PDA

View Full Version : can't get more than 1 row from Database.


vietfancy
22 Nov 2009, 09:38
<?php

// Get Schedule
$mon = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "schedule WHERE day like '%Monday%' ORDER BY time");

$schedule_mon = "<b>$mon[time]</b> - <b>$mon[ampm]</b> - <b>$mon[class]</b> - <b>$mon[level]</b> - <b>$mon[instructor]</b>";

// end Get Schedule

// ###### TEMPLATE IS BEING RENDERED ######
$templater = vB_Template::create('schedule');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
$templater->register('schedule_mon', $schedule_mon);
print_output($templater->render());

?>


I used this code in the template and it only shows 1 row from the database. Did I do anything wrong?
{vb:raw schedule_mon}


Image:
http://www.vbulletin.org/forum/attachment.php?attachmentid=106533&stc=1&d=1258886235

PitchouneN64ngc
22 Nov 2009, 15:47
Query_first() returns only the 1st result from the database.

You must use query_read and fetch_array() for having more lines.

<?php

$schedule_mon = '';

// Get Schedule
$mons = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "schedule WHERE day like '%Monday%' ORDER BY time");

while ($mon = $db->fetch_array($mons))
{
$schedule_mon .= "<b>$mon[time]</b> - <b>$mon[ampm]</b> - <b>$mon[class]</b> - <b>$mon[level]</b> - <b>$mon[instructor]</b>";
}

// end Get Schedule

// ###### TEMPLATE IS BEING RENDERED ######
$templater = vB_Template::create('schedule');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
$templater->register('schedule_mon', $schedule_mon);
print_output($templater->render());

?>

ForumsMods
22 Nov 2009, 16:06
Why don't you use vb:each?

vietfancy
22 Nov 2009, 18:49
Thanks guys.

Adrian. How do i use vb:each?

Thanks

ForumsMods
22 Nov 2009, 20:11
Sorry, vb:each is not what you need.