Jump to content

Slight Problem


derekmcd

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

Link to comment
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.

Link to comment
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

Link to comment
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();



?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.