Jump to content

Noob table output help


Angeleyezz

Recommended Posts

ok, basically i have a table in my database, it has 2 fields in it, 1 is an ID field which i dont need thats just the unique identifier,  the other is a specific name, the specific name is what i need to query to the website.  now i know i can throw it in a loop and have it cycle through all the data posting a a verticle cell, or a horizontal row, whatever..... what i want to do is break that data up into multiple cells & rows on the output.... like 3 columns and say 20 rows down 

 

example:

 

data  data  data  data

data  data  data  data

data  data  data  data

 

the only thing i know how to do is

data

data

data

data

data

data

data

which is not what i want... i want it listed like above....

 

is there any way possible do achieve this, something i must just be too stupid to figure out.  any help would greatly be appreciated, and i thank anyone in advance.

Link to comment
https://forums.phpfreaks.com/topic/158740-noob-table-output-help/
Share on other sites

You can do something along the lines of -

 

<table><tr>
<?php
$sql = 'SQL HERE';
$result = mysql_query($sql);

$cols_per_row = 4;
$count = 0;
while ($row = mysql_fetch_assoc($result)) {
     echo '<td>some data</td>';
     if (++$count % $cols_per_row === 0) echo '</tr><tr>';
}
?>
</tr></table>

The tables are working right, but now my code isnt lol.

 

Error : PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\hshome\martinia\elitemartini.com\drinks.php on line 106

 

// Liquor List
$get_liquors = "SELECT name from liquors_mixers";
$liquors_res = mysql_query($get_liquors);
echo "<table width=\"100%\" border=\"1\"><tr>";
$cols_per_row =4;
$count = 0;
while ($row = mysql_fetch_array($liquors_res)) {
echo "<td>$row['0']</td>";
if (++$count % $cols_per_row === 0) echo '</tr><tr>';
}
echo "</tr></table>";
?>

 

Any Suggestions?

Ok, fixed that problem, but now a new one arises with it.  if there is less than 4 cells at the end, then it comes up like i never put anything on those cells, like for example

 

<table>
<tr>
<td>1</td><td>2</td><td>3</td>
</tr>
<tr>
<td>1</td>

 

see then theres like white space on the rest and the table doesnt form properly

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.