SOLVED:displaying certain amount of records

I have written a registration form for my website to register for a convention.
In the members section it displays a list of members who will be attending the convention.
The members are held on a database using a php query to display the members names.

problem is I have no idea to display a certain number of records on each row. It will continue to print on the same line unless i use the

tag but then it will only display only one record per line. I want it to display 5 names and then create a new line so it does not overload on one line.

my code to display the members is…

<?php
// Retrieve all the data from the "test data" table
$result = mysql_query("SELECT * FROM MEMBERS where PaidStatus = 'paid'" ) 
or die(mysql_error()); 
// Print out the contents of the entry 
echo "<table border='2'>"; 
while($row = mysql_fetch_array( $result))
{
$count = $row["count"];
{
   echo "<td width=100 align=center>";
   echo $row['BadgeName'];
   echo "</td>";
}
}
echo "</table>";
?>

heres the finished sample

http://www.jamesmanagement.co.uk/projec … embers.php members list
http://www.jamesmanagement.co.uk/projec … gister.php registration page

any help?

Hi,

If I’m understanding correctly, then you want the table to be 5 cells wide when displaying names.

You can just keep track of how many you have inserted per row, then when it reaches five, close the tr tag

$cellcount = 0;
while($row = mysql_fetch_array( $result))
{
  $count = $row["count"];
  {
   if($cellcount==0){
     echo "<tr>";
   }
   echo "<td width=100 align=center>";
   echo $row['BadgeName'];
   echo "</td>";
  if(++$cellcount==5){
    echo "</tr>";
    $cellcount=0;
  }
}

Make sure that after you come out of the while loop, you check that the last row has the right amount of cells, or add more empty ones, otherwise I think the table will be messed up.

Hope that helps

ps. I scribbled this code pretty quick, so if it does not work then make some adjustments, but the main idea is right

i tried that code and did not work, i modified it but i am still unable to get it to work, I am still new to PHP. I can understand you are using an IF loop statement.

What is going wrong? Do you get any errors? Is it not displaying correctly? Are you getting unexpected behaviour?

heres what i tried…

[code]<?php
// Retrieve all the data from the “test data” table
$result = mysql_query(“SELECT * FROM MEMBERS where PaidStatus = ‘paid’” )
or die(mysql_error());
// Print out the contents of the entry
$cellcount = 0;
$cellcount ++;

if ($cellcount < 6){
echo “

”;
while($row = mysql_fetch_array( $result )) {
echo “”;
}
}
echo “
”;
echo $row[‘BadgeName’];
echo “
”;
?>[/code]

Waylon999 gave you an, as far as I can tell, perfectly working example of what you want. Why you changed the if statements to being outside the while loop is beyond me, but change that back. Why is the $cellcount ++; outside the while loop, where it serves no purpose?

ok i changed the code to exactly what waylon999 did and this is what i got…

http://www.jamesmanagement.co.uk/projec … mbers1.php

i applied it to one set of results in the confimed section and unsure what to do now…

solved it, thx for your help

Sponsor our Newsletter | Privacy Policy | Terms of Service