Topic: Quick help with using an SQL query please

Just a simple, stupid little question that I can't seem to figure out the answer to -

I've got this query that I'm using in profile.php:

$result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE poster_id = '.$id.' AND posted = '.$user['last_post']) or error('Unable to fetch last post ID', __FILE__, __LINE__, $db->error());

My question is simply: how do I reference the information that query returns in PHP as a variable. It's probably obvious to a whole lot of people here, but I'm essentially much learning PHP as I go, and thus this is beyond me (and yes, I've tried to discover this myself on several occasions, with no success).

Thanks in advance for your help.

Looking for a certain modification for your forum? Please take a look here before posting.

Re: Quick help with using an SQL query please

$row = mysql_fetch_assoc($result);
$id = $row['id'];

$id will output the id you got from the database

Re: Quick help with using an SQL query please

Thank you very much, I'll give that a try.

Looking for a certain modification for your forum? Please take a look here before posting.

Re: Quick help with using an SQL query please

Unfortunately, that didn't work for me. Probably my fault, but anyway, I managed to get things working with this code:

$result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE poster_id = '.$id.' AND posted = '.$user['last_post']) or error('Unable to fetch last post ID', __FILE__, __LINE__, $db->error());
while ($row = $db->fetch_assoc($result))
{
    $last_post_id = $row['id'];
}

Thanks for your help and your time, though.

Looking for a certain modification for your forum? Please take a look here before posting.