Echo'ing MySQL Data
Posted: Wed Jun 18, 2008 2:41 pm
First of all, I have no trouble connecting to my database and I've done this many times.
My problem comes when I want to echo/print/show data from the database in a certain way.
I have been echoing/showing mysql data with either this code or the following code…
Would produce:
Would produce a table:
Any ideas? (Please mention if I haven't explained myself well enough - it's a bit hard for me to explain although I know it's fairly simple)
My problem comes when I want to echo/print/show data from the database in a certain way.
I have been echoing/showing mysql data with either this code or the following code…
Code: Select all
while ($row = mysql_fetch_assoc($result)) {
echo $row['row1']; //Pretend row1 is A
echo $row['row2']; //Pretend row2 is B
echo $row['row3']; //Pretend row3 is C
}
Or the other code I found on php.net:ABC
Code: Select all
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
I want to be able to echo certain rows, not always every part of the row like in the first method but have that, like the second method, apply to every column of data and have the ability have a prefix and suffix, such as <span> and </span>| A | B | C |
Any ideas? (Please mention if I haven't explained myself well enough - it's a bit hard for me to explain although I know it's fairly simple)