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
https://forums.phpfreaks.com/topic/7644-viewing-data-in-table-format/
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]
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.