PHP coding help

designer

Registered
Hi everyone,

I have a question for PHP. I am not a expert in PHP but I know how to output data from database :)

Is there anyway to write php code that recognize how many columns in table?

Let say, I want to make table that has 3 columns in a row.

if there are 3 columns then create another row continuously.

I don't know if it's clear enough.

Thanks
 
It would probably be a database function rather than a PHP function. But I'm no expert either.
 
I can't tell if you are talking about row/columns of data in the database, or rows/columns in our output HTML table.

Please restate.... maybe with an example in words.
 
Sorry for late reply.

I was talking about outputing HTML table.

I am not a PHP expert. I am learning now :)

if ( col == 3)
{
echo '</tr><tr>';
}

Acturally, I don't know where to begin.

i =< 3

then create another row, </tr></tr>.

Create another row after 3 col. have been created.

Thanks.
 
Even with your examples I'm still not sure exactly what you want. I'll give it a shot and hope I help you somehow.

I'm assuming that you are getting data from a db in the form of, first name, last name, id number.
select fname, lname, id from db;
variables: $fname, $lname, $id

since you are pulling from an array you can do all the column/row stuff in the while loop.
while() {
echo "<tr>
<td>$fname</td><td>$lname</td><td>$id</td>
</tr>";
}


Now, if you are talking about getting a list of names and just listing 3 names per row.
This is off the top of my head, so it will be clunky and is not tested
#set counting variable
$count = 0;
#again, you are reading from an array (mysql_fetchrow is reading from an array)
while() {
if($count == 3) {
echo "</tr><tr>";
$count = 0;
}
echo "<td>$name</td>";
$count++;

}
 
Back
Top