Jump to content


Photo

Viewing Data in Table Format?


  • Please log in to reply
7 replies to this topic

#1 cnagra

cnagra
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 17 April 2006 - 09:45 PM

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


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 17 April 2006 - 10:55 PM

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

<?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";


?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 cnagra

cnagra
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 17 April 2006 - 11:05 PM

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

#4 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 17 April 2006 - 11:07 PM

change:

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

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

Should fix that.

#5 cnagra

cnagra
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 17 April 2006 - 11:12 PM

hi

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


thanks



#6 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 17 April 2006 - 11:16 PM

As you would if you were hand coding the page, just use width attributes:

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

#7 cnagra

cnagra
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 18 April 2006 - 12:13 AM

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



#8 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 18 April 2006 - 08:18 AM

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]
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users