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