homepage Welcome to WebmasterWorld Guest from 54.161.236.229
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Trying to make 3 column rows with mySQL info
3 column rows with mySQL info
nameless6135




msg:3518779
 6:08 pm on Dec 2, 2007 (gmt 0)

I have a database built and a page pulling the data and displaying it on but I get the following result:


[2]
[3]
[4]
[5]
[6]

However, I want it to look more like the one I manually typed in:

[1][2][3]
[4][5][6]

Is there a way to get the results in a 3 column layout and then go down a row from there? Any help would be greatly appreciated!

[1][edited by: eelixduppy at 6:32 pm (utc) on Dec. 2, 2007]

[edited by: nameless6135 at 6:36 pm (utc) on Dec. 2, 2007]

 

nameless6135




msg:3518783
 6:14 pm on Dec 2, 2007 (gmt 0)
Here is the code I am using, sorry about now posting it in the first message.

while($rows=mysql_fetch_array($result)){
?>
<font face="Arial, Helvetica, sans-serif" size="1"><table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="80%"><p><? echo $rows['company'];?><br><? echo $rows['raddress'];?><br><? echo $rows['phone'];?><br><? echo "<a href=".$rows['waddress'].">".Website."</a>";?> <? echo "<a href=".$rows['email'].">".Email."</a>";?> Map</p><br></td>
</tr>
</table>
</font>

brancook




msg:3519486
 6:51 pm on Dec 3, 2007 (gmt 0)

Here is the way one of my tables looks. It's a 5 column layout.

<table id="view">
<tr>
<th>RMA</th>
<th>Filename</th>
<th>Date</th>
<th>Note</th>
<th>Delete</th>
</tr>
<?php
if (mysql_num_rows($filelist) > 0) {
while ($f = mysql_fetch_array($filelist)) {
?>
<tr>
<td>
<?php echo $f['status_name'];?>
</td>
<td>
<a href="<?php echo $_SERVER['PHP_SELF'];?>?action=dnld&id=<?php echo $f['id'];?>"><?php echo $f['filename'];?></a>
</td>
<td>
<?php echo $f['date'];?>
</td>
<td>
<?php echo $f['description'];?>
</td>
<td>
<a href="<?php echo ($_SERVER['PHP_SELF']);?>?delete_id=<?php echo $f['id'];?>">Delete</a>
</td>
</tr>

<?php
}
} else {
?>
<tr><td>No Files!</td></tr>
<?php
}
?>
</table>

mooger35




msg:3519603
 8:37 pm on Dec 3, 2007 (gmt 0)

I've posted this in another thread before but I think this is what you are looking for.

$cols = 3; // put the number of columns you want here
$col_width = round(1/$cols * 100,0)."%"; // get column width as %
$extra_cells = "";
$num_rows = mysql_num_rows($result); // get number of records from query
$extra_needed = $cols-($num_rows % $cols); //find out how many blank cells there will be
if($extra_needed!= $cols ){
for($i = 0; $i<$extra_needed;$i++){
$extra_cells .= "<td width=\"$col_width\">&nbsp;</td>\r\n"; // loop the blank cells in
}
}
if($result){
echo '<table width="80%" border="0" cellspacing="0" cellpadding="0">'."\r\n";
$tdcount = 1; //start cell count at one
while($rows=mysql_fetch_assoc($result)){
if($tdcount % $cols == 1) echo "<tr>\r\n"; // check to see if new row needs to be started

echo "<td width=\"$col_width\"><p>".$rows['company']."<br>".$rows['raddress']."<br>".$rows['phone']."<br><a href=\"".$rows['waddress']."\">Website</a> <a href=\"".$rows['email']."\">Email</a> Map</p><br></td>\r\n";

if($tdcount == $num_rows) echo $extra_cells; //echo extra cells into row
if($tdcount % $cols == 0) echo "</tr>\r\n"; // check to see if row needs to be ended

$tdcount++; // add one to cell count
}
echo "</table> \r\n";
}


nameless6135




msg:3519791
 11:50 pm on Dec 3, 2007 (gmt 0)

mooger35: That is exactly what I was looking for. Thank you for the help.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved