Forum Moderators: coopster

Message Too Old, No Replies

Displaying results neatly

How to span 2 columns

         

wheelie34

7:45 pm on May 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi all

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

jatar_k

2:58 pm on Jun 7, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



did you get this figured out or get any farther on this wheelie34?

wheelie34

3:36 pm on Jun 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



nope, all I can find on the web shows me how to list it (which I already have) I take it you understand what I want to do? seems straight forward enough but I cant get my head around it, I understand that I will need to split the table cell bits n bobs but its the function I cant do.

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.

jatar_k

3:43 pm on Jun 7, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I also moved it to php from databases ;)

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?

wheelie34

3:55 pm on Jun 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the help

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

jatar_k

4:02 pm on Jun 7, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



gotcha, my misunderstanding

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?

wheelie34

4:09 pm on Jun 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



at a quick glance that may do the trick, with a little work on it, wish I had found that earlier, thanks again for the help and final pointer.

Cheers jatar_k

jatar_k

4:16 pm on Jun 7, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you really can do it with out the nested table but it is a little trickier, starting out with the nested table will save some headaches.