Having a problem. I want to be able to make a 3 column table and pull information from a database to that table. There will be one variable in each cell. Creating the loop to call from the database and make the table is not a problem, but, after putting information in 3 columns, I want to be able to make a new row, then put 3 more columns with information, then make a new row... and so on, until all the information is pulled from the database... here is what I have to pull the information and keep making columns until all the information is pulled from the database:
/* declare some relevant variables */
$hostname = "localhost";
$username = "granite";
$password = "terminal";
$userstable = "majorretail";
$dbName = "granitedevelopment_com";
/* make connection to database */
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");
@mysql_select_db( "$dbName") or die( "Unable to select database");
/* Select all records */
$query = "SELECT * FROM $userstable";
$result = MYSQL_QUERY($query);
/* How many records are there? */
$number = MYSQL_NUMROWS($result);
/* Print these results to the screen in a nice format */
$i = 0;
$s = 0;
IF ($number == 0) :
PRINT "<P>Error in database communication";
ELSEIF ($number > 0) :
WHILE ($i < $number):
$name = mysql_result($result,$i,"name");
$id = mysql_result($result,$i,"id");
echo '<tr align="left" valign="top">';
print "\n";
echo '<td><font size="2" face="Arial, Helvetica, sans-serif">';
print "$name";
echo '</font></td>';
print "\n";
echo '</tr>';
print "\n";
$i++;
ENDWHILE;
ENDIF;
I need a loop of some sort I imagine for the <tr> code so it only prints that after every 3rd record, or something. I don't know.. Please help.. 🙂