Jump to content


Photo

Slight Problem


  • Please log in to reply
7 replies to this topic

#1 derekmcd

derekmcd
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationQLD, Australia

Posted 23 January 2003 - 06:29 PM

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

#2 metalblend

metalblend
  • Members
  • PipPipPip
  • Advanced Member
  • 89 posts
  • LocationCalifornia, USA

Posted 23 January 2003 - 08:53 PM

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

Hope that helps.

#3 derekmcd

derekmcd
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationQLD, Australia

Posted 24 January 2003 - 01:23 AM

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[IMG]\'><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.

#4 metalblend

metalblend
  • Members
  • PipPipPip
  • Advanced Member
  • 89 posts
  • LocationCalifornia, USA

Posted 24 January 2003 - 09:53 AM

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]

#5 derekmcd

derekmcd
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationQLD, Australia

Posted 24 January 2003 - 10:48 AM

didn\'t work either

#6 pallevillesen

pallevillesen
  • Members
  • PipPipPip
  • Advanced Member
  • 135 posts
  • LocationDenmark

Posted 24 January 2003 - 11:24 AM

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.
Palle Villesen, www.birc.dk [br]Bioinformatics Research Center

#7 derekmcd

derekmcd
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationQLD, Australia

Posted 24 January 2003 - 11:58 AM

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

#8 metalblend

metalblend
  • Members
  • PipPipPip
  • Advanced Member
  • 89 posts
  • LocationCalifornia, USA

Posted 24 January 2003 - 06:14 PM

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



?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users