Jump to content

[SOLVED] SELECT statement


thomashw

Recommended Posts

Can someone tell me what's wrong with this? I am getting an error saying there is something wrong with the SQL syntax.

 

$result = mysql_query("SELECT * 
FROM product, product_attributes, product_options 
WHERE product.product_id={$id} 
AND product_attributes.options_id=product_options.product_options_id, 
product_options.product_options_id=product_options_values_to_product_options.product_options_id, 
product_options_values_to_product_options.product_options_values_id=product_options_values.product_options_values_name") or die(mysql_error());

Link to comment
Share on other sites

You should be using AND, not a comma to separate the different conditions of the WHERE clause:

 

<?php
$result = mysql_query("SELECT * FROM product, product_attributes, product_options WHERE product.product_id={$id} 
AND product_attributes.options_id=product_options.product_options_id AND  
product_options.product_options_id=product_options_values_to_product_options.product_options_id AND 
product_options_values_to_product_options.product_options_values_id=product_options_values.product_options_values_name") or die(mysql_error());
?>

Link to comment
Share on other sites

I might as well post the whole code. If you see any problems with it please let me know!

 

<?
$result = mysql_query("SELECT * 
FROM product, product_attributes, product_options 
WHERE product.product_id={$id} 
AND product_attributes.options_id=product_options.product_options_id, 
product_options.product_options_id=product_options_values_to_product_options.product_options_id, 
product_options_values_to_product_options.product_options_values_id=product_options_values.product_options_values_name") or die(mysql_error());
$count = 0;
while($name = mysql_fetch_assoc($result)) {
if(mysql_num_rows($name) > 0) {
if($count==0) {
echo "<tr>\n<td>\n<label>\n<span>";
echo $name["product_options_name"];
echo "</label></span></td>";
++$count;
}}}
echo "<tr>\n<td>";
echo "<td align=\"left\" class=\"productdrop\">";
echo "<select name=\"cat1\">";
$count = 0;
while($form = mysql_fetch_assoc($result)) {
if(mysql_num_rows($result) > 0) {
if($count==0) {
echo "<option value=\"Quantity&#58; 16\">$form[product_options_values_name]</option>";
}}}
?>

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.