Jump to content

Archived

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

derekmcd

Slight Problem

Recommended Posts

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

Share this post


Link to post
Share on other sites

$q=mysql_query("SELECT * FROM table WHERE Model_No=\'KFC\' ORDER BY Model_No DESC");

 

Hope that helps.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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();



?>

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.