Jump to content

How to Display an Array Horizontally in A Set Number of Rows?


Modernvox

Recommended Posts

Hi Guys!

 

Trying to display data in 3 rows horizontally and 25 vertiacally

 

// Print out result
while($row = mysql_fetch_array($result)){
echo "There are ". $row['COUNT(biddersId)'] ." bidders logged.";
echo "<br />";
}



$query = "SELECT * FROM bidders ORDER BY biddersId"; 

$result = mysql_query($query) or die(mysql_error());

echo "<table border='1'>";
echo "<tr> <th>Bidders</th>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>"; 
        echo"<font face= \"calibri\" size=\"3\">";
echo $row['biddersId'];
echo "</br>";
        echo "</td><td>";
        

} 

echo "</table>";


?>

Link to comment
Share on other sites

Did I mention I Only been programming in PHP for a bout a year?

 

Where do I insert this Modulus Operator in my code?

 <?php
   $cols = 0;
   echo "<table><tr>";
   while ($cols < 20) {
      echo ($cols % 3 == 0)? "</tr><tr>" : "";
      echo "<td>$cols</td>";
      $cols++;
   }
   echo "</tr></table>";
?> 

Link to comment
Share on other sites

Where ever within the page you would like the results to display. All depends on the design of the page  :D

 

Understood, but what i meant was how do I tie the new code with my current code?

 

So where does this

 $cols = 0;
   echo "<table><tr>";
   while ($cols < 20) {
      echo ($cols % 3 == 0)? "</tr><tr>" : "";
      echo "<td>$cols</td>";
      $cols++;
   }
   echo "</tr></table>";

 

 

go to make this work...

 

 

 

 

 echo "<table border='1'>";
echo "<tr> <th>Bidders</th>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
   // Print out the contents of each row into a table
   echo "<tr><td>";
        echo"<font face= \"calibri\" size=\"3\">";
   echo $row['biddersId'];
   echo "</br>";
        echo "</td><td>";
       
   
}

echo "</table>";

Link to comment
Share on other sites

try

<?php
// Print out result
while($row = mysql_fetch_array($result)){
echo "There are ". $row['COUNT(biddersId)'] ." bidders logged.";
echo "<br />";
}



$query = "SELECT * FROM bidders ORDER BY biddersId"; 

$result = mysql_query($query) or die(mysql_error());

echo "<table border='1'>";
echo "<tr>",  str_repeat("<td>Bidders</td>",3), "</tr>\n";
// keeps getting the next row until there are no more to get
$i=0;
while($row = mysql_fetch_array( $result )) {
        if ($i == 0) echo "<tr>";
        $i++;
// Print out the contents of each row into a table
echo "<td>"; 
        echo"<font face= \"calibri\" size=\"3\">";
echo $row['biddersId'];
echo "</font>";
        echo "</td>";
        if ($i == 3){
            echo "</tr>\n";
            $i=0;
        }

} 
if ($i>0){
    while ($i++ <3) echo '<td> </td>';
    echo "</tr>\n";
}
echo "</table>";

?>

Link to comment
Share on other sites

try

<?php
// Print out result
while($row = mysql_fetch_array($result)){
echo "There are ". $row['COUNT(biddersId)'] ." bidders logged.";
echo "<br />";
}


Wow... Thanks. 
Works great! It's doing 9 rows down , but it works.

Thanks again!


$query = "SELECT * FROM bidders ORDER BY biddersId"; 

$result = mysql_query($query) or die(mysql_error());

echo "<table border='1'>";
echo "<tr>",  str_repeat("<td>Bidders</td>",3), "</tr>\n";
// keeps getting the next row until there are no more to get
$i=0;
while($row = mysql_fetch_array( $result )) {
        if ($i == 0) echo "<tr>";
        $i++;
// Print out the contents of each row into a table
echo "<td>"; 
        echo"<font face= \"calibri\" size=\"3\">";
echo $row['biddersId'];
echo "</font>";
        echo "</td>";
        if ($i == 3){
            echo "</tr>\n";
            $i=0;
        }

} 
if ($i>0){
    while ($i++ <3) echo '<td> </td>';
    echo "</tr>\n";
}
echo "</table>";

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.