MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 22nd, 2000, 04:54 PM
weldonj2 weldonj2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Posts: 36 weldonj2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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...
}

Reply With Quote
  #2  
Old September 23rd, 2000, 04:59 PM
master ken master ken is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: MO, US
Posts: 119 master ken User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via AIM to master ken Send a message via Yahoo to master ken
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>

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Ouputting Select into two columns of a table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT