PDA

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


vietfancy
11-22-2009, 08:38 AM
<?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:
https://vborg.vbsupport.ru/attachment.php?attachmentid=106533&stc=1&d=1258886235

PitchouneN64ngc
11-22-2009, 02:47 PM
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
11-22-2009, 03:06 PM
Why don't you use vb:each?

vietfancy
11-22-2009, 05:49 PM
Thanks guys.

Adrian. How do i use vb:each?

Thanks

ForumsMods
11-22-2009, 07:11 PM
Sorry, vb:each is not what you need.