PDA

View Full Version : MySQL Table


sheppardzwc
12-02-2009, 09:57 PM
Hi guys,

And no, not the actual tables in MySQL. A <table>. :p

I wanted to know, how can we retrieve all the rows in a table and display them in a table in a vB template?

i.e., the normal code is:

<?php

$sql = "SELECT * FROM something";

echo("<table>
<tr>
<th>Something</th>
<th>Something</th>
</tr>");

while($row = mysql_fetch_array($sql)) {
echo("<tr>");
echo("<td>" . $row['first_row'] . "</td>");
echo("<td>" . $row['second_row'] . "</td>");
echo("</tr>");
}

echo("</table>");


So how can this be incorporated into a template?

ragtek
12-02-2009, 10:11 PM
$query = "SELECT * FROM table";

$results = $vbulletin->db->query($query);

while ($result = $vbulletin->db->fetch_array($results)
{
// do something with $result
}


https://vborg.vbsupport.ru/showthread.php?t=119350&highlight=database

sheppardzwc
12-02-2009, 10:17 PM
$query = "SELECT * FROM table";

$results = $vbulletin->db->query($query);

while ($result = $vbulletin->db->fetch_array($results)
{
// do something with $result
}


https://vborg.vbsupport.ru/showthread.php?t=119350&highlight=database
Okay, thank you.

How would I integrate this with a template though? To display the table? I can't include the while code in the template, (or can we?) and I can't store the data in variables because it won't be repeated since there won't be a while(). Any suggestions what I could do there to display it on the template?