0

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)

4
  • You want proper HTML table, or something along the lines you showed? Commented May 17, 2011 at 12:45
  • Side note, just to make sure, your query is actually going for 'select card_id, title, description.....' yes? You have them as being in the result set but not in the actual query. Commented May 17, 2011 at 12:55
  • @enoyhs , I need it set up like a proper HTML table with the headers at the top, and corresponding data under it. Commented May 17, 2011 at 13:02
  • Then Parkyprg's answer will help you do that Commented May 17, 2011 at 13:05

1 Answer 1

3

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>';
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.