Forum Moderators: coopster
I am trying to layout my search results neatly in 2 columns and 4 rows
[result1] [result2]
[result3] [result4]
etc
etc
I am using a normal database call
$results = mysql_query("SELECT * FROM data WHERE type='type' ORDER BY name");
while ($data = mysql_fetch_array($results))
{
?>
its this bit in here that I cant get right, each result has 3 pieces of data ie name, type, cost. Is using the while statement correct, currently using this to display
<?=$data["type"]?>
it gives me 6 sets of the first result, how do I call all the contents of each result set ie
<?=$data['0']["type"]?> this just gives the 1st char of the array itself
I am using a template table and would just like to dictate where what ends up, any help much appreciated.
Thanks
<?php
}
?>
With the db call I am currently using am I on the right track? I somehow doubt it.
Jatar k thanks for the bump, hopefully someone is able to help.
your query and loop should be fine, maybe something like this
echo '<table>';
while ($data = mysql_fetch_array($results)) {
echo '<tr>';
echo '<td>',$data['name'],'</td>';
echo '<td>',$data['type'],'</td>';
echo '<td>',$data['cost'],'</td>';
echo '</tr>';
}
echo '</table>';
is that what you mean?
Your suggestion will just return a table with each bit next to the other.
What I actually want is each result SET of 3 variables to be tiled out across the page like so
2 Result sets one in each <td> area
<td>Name<br>type<br>cost</td> <td>Name<br>type<br>cost</td>
I would prefer to already have the table in place and just populate it, there will always be multiples of 2 results to complete the table.
I always seem to find or want the tough ones to get ;)
Thanks anyway
how about trying this then
Create a Dynamic Table from mysql result [webmasterworld.com] msg 4
for the 3 cells side by side you could use that code and maybe nest a table for each set of 3?