MyBB Community Forums

Full Version: How do I display the output of WHILE to template?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I must be really tired because I cannot figure this out. I am output find into a custom page in the Admin CP but outputting to a template is apparently much harder.

Template variable: {$whileout}

Code:
$myq = $db->simple_select("mydata", "*", "uid = '$uid'", array('order_by' => 'mid', 'order_dir' => 'desc'));
$whileout = while($row = $db->fetch_array($myq)) { . '
				<p align="center"><table width="100%" border="1">
				<tr><th>' . $lang->time . '</th>
				<th>' . $lang->mym . '</th>
				<th>' . $lang->mys . '</th>
				</tr>
				<tr>
				<td>' . my_date($mybb->settings['dateformat'].' '.$mybb->settings['timeformat'],$row['time']) . '</td>
				<td>' . $db->escape_string($row['mym']) . '</td>
				<td>' . $db->escape_string($row['mys']) . '</td>
				</tr>
				</table></p>' . ;
$myq = $db->simple_select("mydata", "*", "uid = '$uid'", array('order_by' => 'mid', 'order_dir' => 'desc'));
while($row = $db->fetch_array($myq)) { $whileout .= '
                <p align="center"><table width="100%" border="1">
                <tr><th>' . $lang->time . '</th>
                <th>' . $lang->mym . '</th>
                <th>' . $lang->mys . '</th>
                </tr>
                <tr>
                <td>' . my_date($mybb->settings['dateformat'].' '.$mybb->settings['timeformat'],$row['time']) . '</td>
                <td>' . $db->escape_string($row['mym']) . '</td>
                <td>' . $db->escape_string($row['mys']) . '</td>
                </tr>
                </table></p>'; 
}

That should do the trick Big Grin
Thanks! For some reason the code you posted kept timing out but it got me on the right direction. This was the solution:

	$myq = $db->simple_select("mydata", "*", "uid = '$uid'", array('order_by' => 'mid', 'order_dir' => 'desc'));
	$whilestart = '<p align="center"><table width="100%" border="1">
				<tr><th>' . $lang->time . '</th>
				<th>' . $lang->mym . '</th>
				<th>' . $lang->mys . '</th></tr>';
	while($row = $db->fetch_array($myq)) { $whileout .= '
				<tr><td>' . my_date($mybb->settings['dateformat'].' '.$mybb->settings['timeformat'],$row['time']) . '</td>
				<td>' . $db->escape_string($row['mym']) . '</td>
				<td>' . $db->escape_string($row['mys']) . '</td></tr>';
	}
	$whileend ='</table></p>';
Odd. What do you mean by "timing out"? Running out of memory or what?
Instead of using separate vars for start and end, and then concating them to the loop var, just use the same var for all 3. It works.
(2011-04-28, 03:59 PM)euantor Wrote: [ -> ]Odd. What do you mean by "timing out"? Running out of memory or what?

The server I am testing this on times out after executing a script for longer than 30 seconds.
(2011-04-28, 04:01 PM)Dylan M. Wrote: [ -> ]Instead of using separate vars for start and end, and then concating them to the loop var, just use the same var for all 3. It works.

I had setup separate vars for the start and end for organizational reason but ultimately did away with table aspect so now there is only 1 var anyways. Smile
Hm, that script really shouldn't take 30 seconds - unless you have a ton of data and/or a whole lot more going on in the rest of the plugin.
It made no sense. The while loop would time out after 30 seconds while a $db->num_rows for the same exact query displayed "2" (the number of rows) in less than a second.
it should just be

$myq = $db->simple_select("mydata", "*", "uid = '$uid'", array('order_by' => 'mid', 'order_dir' => 'desc'));

if($db->num_rows($myq))
{
	$while = '<p align="center"><table width="100%" border="1">
          <tr><th>' . $lang->time . '</th>
          <th>' . $lang->mym . '</th>
          <th>' . $lang->mys . '</th></tr>';
          
	while($row = $db->fetch_array($myq))
	{
	$while .=   '<tr>
                <td>' . my_date($mybb->settings['dateformat'],$row['time']).' '.my_date($mybb->settings['timeformat'],$row['time']) . '</td>
                <td>' . $row['mym'] . '</td>
                <td>' . $row['mys'] . '</td>
                </tr>';
	}
    $while .= '</table></p>'; 
}

plus you were misusing the my_date() function