Jump to content

Archived

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

cnagra

Viewing Data in Table Format?

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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
i get the following error with this code

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in c:\project\htdocs\testoutput.html on line 1475

thanks

Share this post


Link to post
Share on other sites
change:

[code]
while (list($id,$category,$model,$price,$stock_amount) = mysql_fetch_row(result))
[/code]

to
[code]
while (list($id,$category,$model,$price,$stock_amount) = mysql_fetch_row($result))
[/code]

Should fix that.

Share this post


Link to post
Share on other sites
hi

yeah that worked, do u know how to make the table boxes wider?...all the data is outputted in narrow boxes..


thanks

Share this post


Link to post
Share on other sites
As you would if you were hand coding the page, just use width attributes:

echo "<TABLE border='1' width='80%'>\n";

Share this post


Link to post
Share on other sites
hi

that worked great, now i need to figure out how to view certain records, edit existing records and delete records...does anyone know of any good tutorial sites, or can help me out?

thanks

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.