PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 30th, 2004, 10:00 PM
Ulitasch Ulitasch is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 7 Ulitasch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Red face PHP/MySQL records horizontally

What do I have to do to see my records horizontally?
A B
C D

I am working with Dreamweaver and can only put them vertically there:
A
B
C
D

Thanks a lot for any further help!!

Reply With Quote
  #2  
Old June 30th, 2004, 10:53 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Use a table perhaps? What kinda of data are you trying to layout? You might want to give us a bit more information.
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #3  
Old October 30th, 2004, 07:25 PM
peasant peasant is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 1 peasant User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The Answer

I found a simple script that accomplished displaying results horizontally (aka Horizontal looping) but it did not add the additional <td> tags at the end of the table if there were an uneven amount of results. Here is my take on this: It seems to work fine.

Code:
<?php
require_once('Connections/info.php');
$sql = "SELECT * FROM inventory";
$result = mysql_query($sql) or die(mysql_error());
$num_rows = mysql_num_rows($result); 
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="500" border="1" cellspacing="0" cellpadding="0">
<tr>
<?php
$numColumns = 3; //Enter how many columns you want your table to be
$extraCells = $numColumns - ($num_rows % $numColumns) ; //determines how many EMPTY extra cells the resulting table may have
$resultingRows = substr($num_rows / $numColumns,0,1) ;//Determines how many COMPLETE html table rows will be diplayed on page
for($i=0; $i < $num_rows; $i++) { //loops through results of query
$row = mysql_fetch_array($result);
 
if (substr($i/$numColumns,0,1) != $resultingRows){ //if its not the last complete row
 
if ($i % $numColumns != $numColumns - 1){ //if its not the last cell of the current row
echo "<td>".$row['serialNumber']."</td>\n";
}else{		//else it is the last cell of the current row, so a </tr> is added
echo "<td>".$row['serialNumber']."</td></tr>\n";
}
}else{	 //else it is the last complete row
echo "<td>".$row['serialNumber']."</td>\n";
}
if ($i==$num_rows - 1){ // if it's the last record, we need to add the amount of EMPTY extra cells needed.
for($j=0; $j < $extraCells; $j++) { 
echo "<td>&nbsp</td>\n";
}
echo"</tr>\n";
}
}
 
?>
</table>
</body>
</html>



-- Mike Puglisi of South Florida

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > PHP/MySQL records horizontally


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 6 hosted by Hostway
Stay green...Green IT