Jump to content

Really Simple Question


scriptjet

Recommended Posts

I'm teaching myself php and mysql -- and my coding is a little rough.  But what i'm trying to do is display information from a mysql table in another table on a website.  I can do this just fine simply displaying the table, but i want a little something different.  I am only displaying one column of the table, instead of displaying it all in one column, i want to display the information in 5 columns.  for example.....  the table from mysql has names scott, john, james, mary, simon.  with the code I have i can make it display like this:

                                                                                        scott scott scott scott scott

                                                                                        john john john john john

                                                                                        james james james james james

                                                                                        mary mary mary mary mary

                                                                                        simon simon simon simon simon

i want it to diplay like this:

                                                                                          scott john james mary simon

                                                                                          new names will continue down

 

here is my code:

 

<?php

 

require ("connectigb.php");

 

 

$result = mysql_query ("SELECT pledgeName FROM pledgewall");

 

$fields_num = mysql_num_fields($result);

 

 

echo "<center> <h1>TSA It Gets Better Pledge Wall</h1>";

echo "<table border='1' align='center' style='width:960px;'><tr>";

 

 

while($row = mysql_fetch_row($result))

{

    echo "<tr>";

 

    // $row is array... foreach( .. ) puts every element

    // of $row to $cell variable

    foreach($row as $cell)

if ($cell != "") {

for ($j=0; $j<5; $j++) {

        echo "<td>$cell</td>";

}

}

 

    echo "</tr>\n";

 

}

mysql_free_result($result);

echo "</table></center>";

?>

 

any ideas on what i can do here, i'm sure this is a simply fix.  i just haven't come across it yet.  thanks for the help in advance.

 

Link to comment
https://forums.phpfreaks.com/topic/224086-really-simple-question/
Share on other sites

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.