derekmcd Posted January 23, 2003 Share Posted January 23, 2003 hi, I want to be able to get data from my MySQL database and put it on my website using PHP. Problem is I can\'t work out the MySQL query. SELECT t.Model_No,t.Product_Name,t.FOB_Price,t.IMG FROM products t WHERE t.Model_No=\'KFC\' ORDER BY Model_No; I want all the data in the table that has KFC in the Model_No. Thanks in advance Quote Link to comment Share on other sites More sharing options...
metalblend Posted January 23, 2003 Share Posted January 23, 2003 $q=mysql_query("SELECT * FROM table WHERE Model_No=\'KFC\' ORDER BY Model_No DESC"); Hope that helps. Quote Link to comment Share on other sites More sharing options...
derekmcd Posted January 24, 2003 Author Share Posted January 24, 2003 This is what I have in the PHP file. I tried that SQL code that was posted in the 2nd post but I did not work either. [php:1:bfe4799ca9]<?php // MySQL Connection Information $db_server = \"\"; // The name of your server $db_username = \"\"; // The MySQL username $db_password = \"\"; // The MySQL password $db_name = \"\"; // The name of the database where your forums are installed // Variables $tbl = \"products\"; // Name of the table where your topics are $url = \"Site URL\"; // The full URL to your forums $limit = \"5\"; // The amount of topics at max you want to be exported $model = \"KFC\" //Product Model Number #################################################### mysql_connect(\"$db_server\",\"$db_username\",\"$db_password\"); mysql_select_db(\"$db_name\"); $sql_topic = mysql_query(\"SELECT t.Model_No,t.Product_Name,t.FOB_Price,t.IMG FROM $tbl t WHERE t.Model_No=\'$model\' ORDER BY Model_No DESC\") or print mysql_error(); while($t=mysql_fetch_array($sql_topic)) { print \"<img scr=\'$url/$t\'><br><a href=\'$t[Model_No]\'>$t[Proguct_Name]</a><br>$t[FOB_Price]\"; } mysql_close(); ?>[/php:1:bfe4799ca9] For surcurity Reasons. I have removed the databse password and stuff and also the site url. Can someone tell me where I have gone wrong. Quote Link to comment Share on other sites More sharing options...
metalblend Posted January 24, 2003 Share Posted January 24, 2003 Try this: [php:1:c1dd6b2877]... $sql_topic = mysql_query(\"SELECT t.Model_No,t.Product_Name,t.FOB_Price,t.IMG FROM $tbl t WHERE t.Model_No=\'$model\' ORDER BY Model_No DESC LIMIT $limit\") or mysql_error(); ...[/php:1:c1dd6b2877] Quote Link to comment Share on other sites More sharing options...
derekmcd Posted January 24, 2003 Author Share Posted January 24, 2003 didn\'t work either Quote Link to comment Share on other sites More sharing options...
pallevillesen Posted January 24, 2003 Share Posted January 24, 2003 Please post a describe Products; .. or tell us what the error is. I can\'t see any errors in your sql statement, but it may be the database schema or something not so obvious... P. Quote Link to comment Share on other sites More sharing options...
derekmcd Posted January 24, 2003 Author Share Posted January 24, 2003 Please post a describe Products; .. or tell us what the error is. I can\'t see any errors in your sql statement, but it may be the database schema or something not so obvious... P. products is the table name I\'m not getting an error I\'m getting a blank page. With absolutely nothing Quote Link to comment Share on other sites More sharing options...
metalblend Posted January 24, 2003 Share Posted January 24, 2003 Ok here\'s some error checking.. I also noticed you had lots of typos. <?php // MySQL Connection Information $db_server = ""; // The name of your server $db_username = ""; // The MySQL username $db_password = ""; // The MySQL password $db_name = ""; // The name of the database where your forums are installed // Variables $tbl = "products"; // Name of the table where your topics are $url = "Site URL"; // The full URL to your forums $limit = "5"; // The amount of topics at max you want to be exported $model = "KFC" //Product Model Number #################################################### mysql_connect("$db_server","$db_username","$db_password"); mysql_select_db("$db_name"); $sql_topic = mysql_query("SELECT Model_No,Product_Name,FOB_Price,IMG FROM $tbl WHERE Model_No=\'$model\' ORDER BY Model_No DESC LIMIT $limit") or mysql_error(); if(!isset($sql_topic)) { print "Error : query failed.<br>rn"; } else { $cnt=mysql_num_rows($sql_topic); if($cnt<1) { print "Error : mysql returned 0 results.<br>rn"; } else { while($row=mysql_fetch_array($sql_topic)) { print "<img src=\'".$url."/".$row[\'IMG\']."\' border=\'0\'><br><a href=\'".$row[\'Model_No\']."\' target=\'_self\'>".$row[\'Product_Name\']."</a><br>".$row[\'FOB_Price\']."<br><br>rn"; } } } mysql_close(); ?> 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.