Jump to content

Viewing Data in Table Format?


cnagra

Recommended Posts

hi, i got my data to output successfully, but i need each record to output into a table in a website.
can anyone help me.

so far they are seperated by a new line but all the data is outputted together.

php code:

<?php

mysql_pconnect('localhost');
mysql_select_db('dv8_database');

$query="SELECT * FROM stock_control";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$category=mysql_result($result,$i,"category");
$model=mysql_result($result,$i,"model");
$price=mysql_result($result,$i,"price");
$stock_amount=mysql_result($result,$i,"stock_amount");

echo "<br>ID: $id| Category: $category | Model: $model | Price: $price | Stock Amount: $stock_amount |<br><hr><br>";

$i++;
}

?>

thanks
Link to comment
Share on other sites

Just get your code to generate the same HTML as you would write if hand coding the page.

[code]<?php
mysql_pconnect('localhost');
mysql_select_db('dv8_database');

$query="SELECT id,category,model,price,stock_amount FROM stock_control";
$result=mysql_query($query);

echo "<TABLE border='1'>\n";
       echo "<TR>
              <TD>ID</TD>
              <TD>CATEGORY</TD>
              <TD>MODEL</TD>
              <TD>PRICE</TD>
              <TD>STOCK</TD>
       </TR>\n";

while (list($id,$category,$model,$price,$stock_amount) = mysql_fetch_row(result)) {

       echo "<TR>
              <TD>$id</TD>
              <TD>$category</TD>
              <TD>$model</TD>
              <TD>$price</TD>
              <TD>$stock_amount</TD>
       </TR>\n";

}

echo "</TABLE>\n";


?>[/code]
Link to comment
Share on other sites

This series of articles by Kevin Yank gpt me started with php/mysql

[a href=\"http://www.sitepoint.com/article/publishing-mysql-data-web\" target=\"_blank\"]http://www.sitepoint.com/article/publishing-mysql-data-web[/a]

In your case, you need to learn HTML first.

[a href=\"http://www.w3schools.com/html/html_intro.asp\" target=\"_blank\"]http://www.w3schools.com/html/html_intro.asp[/a]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.