Helpful Information
 
 
Category: vB4 Programming Discussions
can't get more than 1 row from Database.

<?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

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());

?>

Why don't you use vb:each?

Thanks guys.

Adrian. How do i use vb:each?

Thanks

Sorry, vb:each is not what you need.










privacy (GDPR)