|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I would like to output the results of a select statement into a table with two columns. The first record will go in the first column, the second into the second, the third into the first, ....
I'm totally confused as to how to do this. I could easily put them in a one column table but can't figure out the two columns: ONe column I would just use a while loop: $query = mysql_query("select * from news where condition=condition"); while ($myrow = mysql_fetch_array($query)) { #put stuff into single column... } |
|
#2
|
|||
|
|||
|
The script below works for multiple columns.
Go to www.cityzip.com and click on a state to see the example. $connection = mysql_connect("localhost", "root") or die ("Couldn't connect to the server."); $db = mysql_select_db("Your Database", $connection) or die ("Couldn't select database."); $sql = "SELECT * FROM yourtablename WHERE var1 = '$val1' ORDER BY var1 ASC"; $result = mysql_query($sql,$connection) or die ("couldn't execute query."); //Set this to be the number you want across $rows = 5; $i = 1; echo '<table width="650" align="center"><tr>'; while ($row = mysql_fetch_array($result)) { if (is_int($i / $rows)) { echo '<td width="20%" align="center"><font size=-1>'; echo '<A HREF='; echo $row["field name 1"]; echo '>'; //Next echo and field name not necessarily needed echo $row["field name 2"]; echo '</A></td></font></tr><tr>'; } else { echo "<td width='20%' align='center'><font size=-1>"; echo '<A HREF='; echo $row["field 1"]; echo '>'; echo $row["field 2"]; echo "</A></td></font>"; } $i++; } echo '</tr></table>'; echo "</P> |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > Ouputting Select into two columns of a table |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|