Forum Moderators: coopster

Message Too Old, No Replies

php results side by side

in html table

         

benihana

10:14 pm on Jan 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi
im working on my first php/mysql site and would like to be able to output SELECT results side by side in an html table like this:

result1 result2
result3 result4
result5 etc.

ive tried a few things like:

$query="SELECT * from tablename";
$result=(mysql_query($query));
while ($myrow=mysql_fetch_array($result)){
$tablebreak=1;

if ($tablebreak==1){
echo('<table width="600" colspan=2 border=1><tr><td>'.$myrow[1].'</td>');
$tablebreak++;
}

else {
echo('<td>'.$myrow[1].'</td></tr></table><br>');
}

but it just outputs single cell tables with <br>'s between them and no </table> tags.

any ideas anybody?
help would be hugely appreciated.
thanks

jatar_k

10:40 pm on Jan 25, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what about something like

$query="SELECT * from tablename";
$result=(mysql_query($query));

$tablebreak=1;
echo '<table width="600" border=1>';

while ($myrow=mysql_fetch_array($result)){
if ($tablebreak == 1) {
echo '<tr><td>'.$myrow[1].'</td>';
$tablebreak = 2;
} else {
echo '<td>'.$myrow[1].'</td></tr>';
$tablebreak = 1;
}
}
//check to make sure the last row and final cell were output
if ($tablebreak == 2) echo '<td> </td></tr>';
echo '</table>':

benihana

11:03 pm on Jan 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Jatar_K
once again, thanks very much for your help!
thats fixed it (and will hopefully get the boss off my back :))
thanks.