cnagra Posted April 17, 2006 Share Posted April 17, 2006 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:<?phpmysql_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 Quote Link to comment Share on other sites More sharing options...
Barand Posted April 17, 2006 Share Posted April 17, 2006 Just get your code to generate the same HTML as you would write if hand coding the page.[code]<?phpmysql_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] Quote Link to comment Share on other sites More sharing options...
cnagra Posted April 17, 2006 Author Share Posted April 17, 2006 i get the following error with this codeWarning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in c:\project\htdocs\testoutput.html on line 1475thanks Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 17, 2006 Share Posted April 17, 2006 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. Quote Link to comment Share on other sites More sharing options...
cnagra Posted April 17, 2006 Author Share Posted April 17, 2006 hiyeah that worked, do u know how to make the table boxes wider?...all the data is outputted in narrow boxes..thanks Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 17, 2006 Share Posted April 17, 2006 As you would if you were hand coding the page, just use width attributes:echo "<TABLE border='1' width='80%'>\n"; Quote Link to comment Share on other sites More sharing options...
cnagra Posted April 18, 2006 Author Share Posted April 18, 2006 hithat 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted April 18, 2006 Share Posted April 18, 2006 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.