Log in

View Full Version : Where am I going wrong with this query?


Reeve of shinra
01-25-2006, 06:18 PM
This works but it's only giving the me the first result from the DB and not a full list.


$dingx = $vbulletin->db->query_first("SELECT * FROM ding");


// ##### Lets wrap it up and display the results #####
eval('$dingx = "' . fetch_template('ding_bits') . '";');
eval('print_output("' . fetch_template('ding') . '");');



I assume I need to add a while condition after $dingx?


$dingx = $vbulletin->db->query_read("SELECT * FROM ding");
while ($ding = $vbulletin->db->fetch_array($dingx))
{
echo $ding['userid'], $ding['charname'], $ding['charlvl'];
}

// Finish up.
eval('$dingx = "' . fetch_template('ding_bits') . '";');
eval('print_output("' . fetch_template('ding') . '");');



I tried that and it works but its not placing the results in the template. What would be the correct way of doing this?

Zachery
01-25-2006, 06:42 PM
You overwrote set $dingx twice in your first snipet of code, which isn't helping anything.

Reeve of shinra
01-25-2006, 08:22 PM
No, I tried changing all that around but I can't seem to get it to work right. I wonder if anyone has a working example I can look at to see where I am going wrong.

Paul M
01-25-2006, 08:33 PM
Since we don't know what it's supposed to do - or what's in the ding_bits template - it's hard to say.

Try this (based on a guess of what I think you are trying to do).

unset ($dingx);
$dingr = $vbulletin->db->query_read("SELECT * FROM ding");
while ($ding = $vbulletin->db->fetch_array($dingr))
{
eval('$dingx .= "' . fetch_template('ding_bits') . '";');
}

// Finish up.
eval('print_output("' . fetch_template('ding') . '");');

Guest190829
01-25-2006, 09:25 PM
Since we don't know what it's supposed to do - or what's in the ding_bits template - it's hard to say.

Try this (based on a guess of what I think you are trying to do).

unset ($dingx);
$dingr = $vbulletin->db->query_read("SELECT * FROM ding");
while ($ding = $vbulletin->db->fetch_array($dingr))
{
eval('$dingx .= "' . fetch_template('ding_bits') . '";');
}

// Finish up.
eval('print_output("' . fetch_template('ding') . '");');

This should work. Only use query_first if you only need the first row of the table...

Xenon
01-25-2006, 10:03 PM
query first is exactly the same as
fetch_array(query_read result)

it's just a shortcut ;)

Reeve of shinra
01-25-2006, 10:30 PM
Thank you guys, that seemed to do it. Its nothing major, just something simple to practice some of the basics of coding with. :)