Topic: MySQL $forum_db Request Help

So, I'm trying to follow the faq on how to work with $forum_db-> results, but I can't seem to get it to return anything but the number of rows in the result (using $forum_db->num_rows($result);), or at least return it in a way I can use.

Here's what I've got so far:

$jchat_query = array(
    'SELECT'    => 'g.g_id, g.g_title',
    'FROM'        => 'groups AS g'
);
$jchat_result = $forum_db->query_build($jchat_query) or error(__FILE__, __LINE__);
$jchat_query_rows = $forum_db->fetch_row($jchat_query);
$jchat_group_id = $jchat_query_rows[0];
echo $jchat_group_id; // returns nothing
print_r($jchat_group_id); // also returns nothing

$rows = $forum_db->num_rows($jchat_result);
printf($rows); // returns 12, which is correct
print_r($jchat_query_rows); // returns nothing
print_r($jchat_query); // returns the proper query array as above
print_r($jchat_result); // returns mysqli_result Object ( )
echo $jchat_query_rows['Administrators']; // nothing
echo $jchat_query_rows['1']; // nada
echo $jchat_query_rows[1]; // zilch 

Can someone enlighten me on what I'm doing wrong?

Re: MySQL $forum_db Request Help

This expression

$jchat_query_rows = $forum_db->fetch_row($jchat_query);

should be

$jchat_query_rows = $forum_db->fetch_row($jchat_result);

Re: MySQL $forum_db Request Help

$jchat_query = array(
    'SELECT'    => 'g.g_id, g.g_title',
    'FROM'        => 'groups as g'
);
$jchat_result = $forum_db->query_build($jchat_query) or error(__FILE__, __LINE__);
$jchat_query_rows = $forum_db->fetch_row($jchat_query);

$rows = $forum_db->num_rows($jchat_result);
echo $rows; // returns the number of rows

while ($data = $forum_db->fetch_assoc($jchat_result))
{
    echo '<p>g_id = '.$data['g_id'].' and g_title = '.$data['g_title'].'</p> ';
}

Re: MySQL $forum_db Request Help

Alright... that was easy.

Thank you! smile

Re: MySQL $forum_db Request Help

Okay, last question...

$jchat_query = array(
    'SELECT'    => 'g.g_id, g.g_title',
    'FROM'        => 'groups AS g'
);
$jchat_result = $forum_db->query_build($jchat_query) or error(__FILE__, __LINE__);
$jchat_query_row = $forum_db->fetch_row($jchat_result);

$jchat_group = array();
while ($cur_row = $forum_db->fetch_assoc($jchat_query_row))
  {
    $jchat_group[$cur_row['g_id']] = $cur_row['g_title'];
  };

I know this is like MySQL to PHP 101, but how do I get the result into the $jchat_group array();? I think I've been up too late working on this and my brain is fried.

For bonus points, where is the best place to put this so the $jchat_group result will be available on every page?

Re: MySQL $forum_db Request Help

$jchat_query = array(
    'SELECT'    => 'g.g_id, g.g_title',
    'FROM'        => 'groups AS g'
);
$jchat_result = $forum_db->query_build($jchat_query) or error(__FILE__, __LINE__);

$jchat_group = array();
while ($cur_row = $forum_db->fetch_assoc($jchat_result))
  {
    $jchat_group[$cur_row['g_id']] = $cur_row['g_title'];
  };
Carpe diem

Re: MySQL $forum_db Request Help

Okay, ignore my previous question... I was making the same mistake as when I first asked.
hmm

Re: MySQL $forum_db Request Help

Thanks, Anatoly. smile Caught it about the exact same time you posted your response.