Topic: PHP related question

$temp = $db->query('SELECT uid, tid FROM posts_read WHERE uid='.$pun_user['id'].' AND tid='.$cur_topic['tid']) or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
$atid = $db->fetch_row($temp);

print($atid);
exit();

output:
"Array"

print($db->fetch_row($db->query('SELECT uid, tid FROM posts_read WHERE uid='.$pun_user['id'].' AND tid='.$cur_topic['tid']) or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error())));
exit;

output:
""

Why, why, why ~.~ I understand that in the end, $temp exists, but I don't want to have to type it, and worry about the other $temps in the same scope, etc... I thought php was supposed to be getting closer to c/c++...

echo "deadram"; echo; fortune;

Re: PHP related question

Since $db->query returns something of type resource, perhaps it needs to be stored (because without a reference to it, the garbage collector kills it?)

Re: PHP related question

Meh, it work in perl, or c/c++... heck I think even in java...
I was hoping I was just forget to cast it or add extra brackets or something...

echo "deadram"; echo; fortune;

4 (edited by Smartys 2006-09-16 18:27)

Re: PHP related question

Mmm, actually, try this:

print($db->fetch_row($db->query('SELECT uid, tid FROM posts_read WHERE uid='.$pun_user['id'].' AND tid='.$cur_topic['tid'])));
exit;

Re: PHP related question

print_r($atid);

Re: PHP related question

That's if he wants to see the elements of the array, his issue is that he can't even get the array to show up wink

Re: PHP related question

Smartys wrote:

Mmm, actually, try this:

print($db->fetch_row($db->query('SELECT uid, tid FROM posts_read WHERE uid='.$pun_user['id'].' AND tid='.$cur_topic['tid'])));
exit;

Nope, no go... hmm

You'd think the guys who started php would make this the first thing on thier list of thing to do... ~.~ I must be doing something wrong with the $db->fetch_row declairation?

This works...

print($db->query('SELECT uid, tid FROM posts_read WHERE uid='.$pun_user['id'].' AND tid='.$cur_topic['tid']));

output:
"Object id #3"

But then again print isn't a member of a class... maybe that has something to do with it?

echo "deadram"; echo; fortune;

Re: PHP related question

Try this:

$data = $db->fetch_row($db->query('SELECT uid, tid FROM posts_read WHERE uid='.$pun_user['id'].' AND tid='.$cur_topic['tid']));
print $data;
exit;

9 (edited by deadram 2006-09-16 20:01)

Re: PHP related question

Humm found it.... and why I was getting some many problems, thanks for the help smartys big_smile

I keeped getting "" because there was no value for that select when I ran the test... ~.~ Gawd I need some sleep... or coffee tongue

Originally it was the "or error(msg)" that cause the problem, so if it was a one liner I'd have to remove that or... Which could be where the garbage collector comes in... cause really what happend when the or error is expanded is ~something~ like this:

try {
  $temp = $db->query('xxx');
  // .. in $db->query();
    if ($other_temp == 0) throw OrError
}
catch (OrError $e)
{
  error(msg)
}

// We've left the scope of the try block, [b]even if there was no error thrown[/b] and now we hand off NULL to $db->fetch_row()

Unfortunatly something like this won't catch the error hmm
print($db->fetch_row($db->query('SELECT uid, tid FROMasd posts_read WHERE uid='.$pun_user['id'].' AND tid='.$cur_topic['tid']))) or error ('blah', __FILE__, __LINE__, '');

price to pay, i guess....

echo "deadram"; echo; fortune;