Display mysql data in a dynamically generated table
Hi, i want to display data fetched from the database in a 3x3 table or a 4x3 table but i'm having trouble looping the rows correctly. Here's 2 sample code
PHP Code:
echo "<table border=\"0\">";
//...some code
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query) {
//loop table rows and columns here
}
echo "</table>";
Thanks in advance.
__________________ Write an Essay, Get all your best web articles.
Here's a sample of how i want data to be displayed
[HTML]
<table border="0">
<tr><td>item1</td><td>item2</td><td>item3</td></tr>
<tr><td>item4</td><td>item5</td><td>item6</td></tr></table>[/HTML]
__________________ Write an Essay, Get all your best web articles.
echo "<table border=\"0\">";
//...some code
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query) {
//loop table rows and columns here
echo "<tr><td>" . $row['my_row_name_here'] . "</td></tr>";
}
echo "</table>";
Basically just add your html for the table data every time you loop.
the loop you stated will loop a pre-determined number of rows or columns. I want a loop statement that will allow each item to be in its own cell. Just like how online catalogues display their products. Here's a sample of how i want data to be displayed
Assuming each row in $query contains just 1 field, then one option is to set a counter going from 1 to the number of items you want on each html table row.
So in your case you want 3 items per <tr>. When the counter reaches 3, close the <tr>, reset the counter to 1, open another <tr> and continue looping through $query
Assuming each row in $query contains just 1 field, then one option is to set a counter going from 1 to the number of items you want on each html table row.
So in your case you want 3 items per <tr>. When the counter reaches 3, close the <tr>, reset the counter to 1, open another <tr> and continue looping through $query
no, each query has more details relating to each item such as photo n price
__________________ Write an Essay, Get all your best web articles.
no, each query has more details relating to each item such as photo n price
Does each row that you are retrieving contain more then one detail? or are there multiple rows each one retrieving a different detail? ex a row for price another row for photo
If it is the latter do what bullant said (as that was a repeat of his question). Otherwise we will need more information about your script. such as how your splitting up the information from a row and where it needs to go.
__________________
Last night I lay in bed looking up at the stars in the sky and I thought to myself, where the heck is the ceiling.
no, each query has more details relating to each item such as photo n price
ok, then it looks like you're only drip feeding information about what your data looks like and since my crystal ball isn't back from its 1000 year service yet, I can't use it to see exactly what you have in your code and data. Hopefully someone else will be able to help.