Formatting Mysql Queries in Table
Alright. I have several queries
<?php
// Make a MySQL Connection
mysql_connect("mm.hostname.net", "user", "pass") or die(mysql_error());
mysql_select_db("db_name") or die(mysql_error());
$query = "SELECT card_id,item_bar FROM cards";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
echo "Id :{$row['card_id']} <br>" .
"Title :($row['title']}" .
"Description :($row['description']}";
}
include '开发者_高级运维closedb.php';
?>
My question is how do I get the queries to align in a table like form like below?
Id | Title | Description
============================
1 | card | cute and fluffy
1 | card | cute and fluffy
1 | card | cute and fluffy
1 | card | cute and fluffy
1 | card | cute and fluffy
I am pretty new to queries using php (and really still trying to get the hang of them anyway)
You can use tables:
<?php
// Make a MySQL Connection
mysql_connect("hostname", "user", "pass") or die(mysql_error());
mysql_select_db("db_name") or die(mysql_error());
$query = "SELECT card_id,item_bar FROM cards";
$result = mysql_query($query);
echo '<table>';
echo '<th><td>Id</td><td>Title</td><td>Description</td></th>';
while($row = mysql_fetch_assoc($result))
{
echo "<tr><td>$row['card_id']</td>" .
"<td>$row['title']</td>" .
"<td>$row['description']</td></tr>";
}
echo '</table>';
?>
精彩评论