curiosus Posted May 7, 2006 Share Posted May 7, 2006 I have created a database called '[b]products[/b]'.A guide adviced to use following script:[code]INSERT INTO products VALUES(001,"Milk",4.00);INSERT INTO products VALUES(002,"Chili",5.00);INSERT INTO products VALUES(003,"Orange",10.00);[/code]I typed the products ([i]product code, product and price[/i]) using [b]phpAdmin[/b] which my webhost offers.Then the guide advices me to create producttest.php and add following script into, to print out the info:[code]<html><head><title>product test</title></head><body><?phpmysql_connect("localhost","login","password");mysql_selectdb("shop");$query = "SELECT code,name,price FROM products ORDER BY code";$result = mysql_query($query);?><table cellspacing=0 cellpadding=4 border=1><tr><th>product code</th><th>name </th><th>price</th></tr><?for($count = 0; $count < mysql_numrows($result); $count++) {?><tr><td><?echo mysql_result($result,$count,"code")?></td><td><?echo mysql_result($result,$count,"name")?></td><td><?echo mysql_result($result,$count,"price")?> USD</td></tr><?}?></table><?mysql_close();?></body></html>[/code][code]mysql_connect("localhost","login","password");[/code]I have changed "login" and "password" to my own login and pass. No effect. Then I changed janhost.com as my 'localhost'. No effect.The results should look like this:[a href=\"http://imageshack.us\" target=\"_blank\"][img src=\"http://img288.imageshack.us/img288/8918/products6jc.jpg\" border=\"0\" alt=\"IPB Image\" /][/a]but i'm seeing this:[a href=\"http://imageshack.us\" target=\"_blank\"][img src=\"http://img74.imageshack.us/img74/973/products29os.jpg\" border=\"0\" alt=\"IPB Image\" /][/a]Please help me if you can. i've been dealing with this for 3 days... i've also tried other php codes which should print some info out of MySQL... i can not get them working. Any help will be greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/9236-how-can-i-get-requested-info-from-mysql-using-php/ Share on other sites More sharing options...
wildteen88 Posted May 7, 2006 Share Posted May 7, 2006 Change the below code:[code]<?for($count = 0; $count < mysql_numrows($result); $count++) {?><tr><td><?echo mysql_result($result,$count,"code")?></td><td><?echo mysql_result($result,$count,"name")?></td><td><?echo mysql_result($result,$count,"price")?> USD</td></tr><?}?>[/code]To the following:[code]<?php while($row = mysql_fetch_array($result)){?><tr><td><?php echo $row['code']; ?></td><td><?php echo $row['name']; ?></td><td>$<?php echo $row['price']; ?> USD</td></tr><?php } ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9236-how-can-i-get-requested-info-from-mysql-using-php/#findComment-34043 Share on other sites More sharing options...
curiosus Posted May 7, 2006 Author Share Posted May 7, 2006 Thank you for taking time for helping me! it's working now ^^ Quote Link to comment https://forums.phpfreaks.com/topic/9236-how-can-i-get-requested-info-from-mysql-using-php/#findComment-34071 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.