954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

php select from 2 different tables

this is my first code in php. i am trying this off a tutorial i saw--

i am getting error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN products.products_id=products_description.products_id' at line 8

<?php
// Make a MySQL Connection
mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("mydb") or die(mysql_error());

// Get all the data from the "product" table
$result = mysql_query("SELECT * FROM products.products_id AS id,
products_description.products_name AS name,
products.products_quantity AS quantity,
products.products_weight AS weight,
products.products_price AS price,


LEFT JOIN products.products_id=products_description.products_id

") 
or die(mysql_error());  

echo "<table border='1'>";
echo "<tr> <th>Name</th> <th>Age</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
	// Print out the contents of each row into a table
	echo "<tr><td>"; 
	echo $row['id'];
	echo "</td><td>"; 
	echo $row['name'];
	echo "</td></tr>";
	echo $row['quantity'];
	echo "</td></tr>";
	echo $row['weight'];
	echo "</td></tr>";
	echo $row['price'];
	echo "</td></tr>";
} 

echo "</table>";
?>


thanks,

craig

craign924
Newbie Poster
2 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

remove ,

products.products_price AS price,

momo219
Light Poster
44 posts since Dec 2009
Reputation Points: 11
Solved Threads: 3
 

The query sentense shoud be like

$result = mysql_query("SELECT products.products_id AS id,
products_description.products_name AS name,
products.products_quantity AS quantity,
products.products_weight AS weight,
products.products_price AS price  FROM products, products_description 
LEFT JOIN products.products_id=products_description.products_id
 ")

It should be the table name after "FROM", not the column name ;)

shadowcrawler
Newbie Poster
11 posts since Oct 2011
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: