Figurine
08-15-2008, 11:14 AM
Hi everyone!
I am hoping someone can help me with a simple php table?
I am a total beginner with php and am a little lost in this...
I have a db table with the fields 'date' (primary key), 'heading' and 'text' and I need these to be displayed so that the date and the heading are in 2 columns in the same row and the 'text' in the same column as 'heading' but in a row beneath it. This is a news table so content will be added all the time and should be displayed by date.
I am using this now:
<?
$link=mysql_connect("", "", "")
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('Mydatabase') or die('Could not select database');
$query = 'SELECT * FROM news';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Printing results in HTML
echo "<table>\n";
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";
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);
?>
But it shows everything in the same row. I realize I need to call the variables separately and put then into the tables but I am confused as to how I would do that.
sorry if this is a crazy simple question, but help would be appreciated :)
best!
Figurine
I am hoping someone can help me with a simple php table?
I am a total beginner with php and am a little lost in this...
I have a db table with the fields 'date' (primary key), 'heading' and 'text' and I need these to be displayed so that the date and the heading are in 2 columns in the same row and the 'text' in the same column as 'heading' but in a row beneath it. This is a news table so content will be added all the time and should be displayed by date.
I am using this now:
<?
$link=mysql_connect("", "", "")
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('Mydatabase') or die('Could not select database');
$query = 'SELECT * FROM news';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Printing results in HTML
echo "<table>\n";
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";
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);
?>
But it shows everything in the same row. I realize I need to call the variables separately and put then into the tables but I am confused as to how I would do that.
sorry if this is a crazy simple question, but help would be appreciated :)
best!
Figurine