...

View Full Version : Select



ggp
11-23-2006, 07:28 PM
Hi to all of you.

I am getting this error:
Invalid query: 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 ' doll.image_id='9',' at line 3

line 3:
$conn = mysql_connect("localhost", "root") OR DIE (mysql_error());



<?php


$image_id=$_GET['image_id'];

$sql = ("SELECT doll.gameandtoyname, doll.bigdescription, prices.pricetype, prices.pricevalue
FROM dollsimage as image_id, doll as gameandtoyname, doll as bigdescription
WHERE image_id='$image_id', doll.image_id='$image_id',
");
?>




i try to print:



echo '<TD> <img border="1" height="90" width="100"
src="imagedolls.php?act=view&iid=' . $row['image_id'] . '"> ';

echo '<BR>' .$row['gameandtoyname'] ;
echo '<BR>' .$row['bigdescription'] ;

$row['pricevalue'] = number_format($row['pricevalue'],2, '.', '');
echo '<br>';
echo '$' .$row['pricevalue']. '</TD>';



In my database i have:
tables: fields:
doll image_id, gameandtoyname, bigdescription
prices pricetype, pricevalue
dollsimage image_id


Thanks for any help!!!!

GJay
11-23-2006, 08:24 PM
separate constraints (things after 'WHERE') with 'AND' or 'OR', not with commas.

ggp
11-23-2006, 08:31 PM
Hi. Something got fix but this error now:

Invalid query: 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 '' at line 3

Line 3: $conn = mysql_connect("localhost", "root") OR DIE (mysql_error());



$image_id=$_GET['image_id'];

$sql = ("SELECT doll.gameandtoyname, doll.bigdescription, prices.pricetype, prices.pricevalue
FROM dollsimage as image_id, doll as gameandtoyname, doll as bigdescription
WHERE image_id='$image_id' and doll.image_id='$image_id',
");

GJay
11-23-2006, 08:36 PM
you have an extra comma at the end.
The line number is referring to the query when it gets to mysql, not to line 3 of your code...

ggp
11-23-2006, 08:42 PM
Why is giving this invalid query if my doll table name has a field gameandtoyname?

Invalid query: Unknown column 'doll.gameandtoyname' in 'field list'


Thanks.

GJay
11-23-2006, 10:42 PM
your query doesn't make sense, why are you aliasing 'doll' as 2 different things? This stops you from then being able to refer to fields in the 'doll' table, as it doesn't know which 'instance' of the table to use.

ggp
11-23-2006, 11:22 PM
I did chage something. But ....? this has sense?



<?php
$sql = ("SELECT gameandtoyname, pricevalue, bigdescription, prices.pricetype, prices.pricevalue
FROM dollsimage, doll, prices
WHERE image_id='$image_id' and doll.image_id='$image_id' and doll.pricetype=prices.type

");

<?php



I get this:

Invalid query: Column 'image_id' in where clause is ambiguous



Thanks.

GJay
11-23-2006, 11:37 PM
as before, you need to tell it which image_id you mean (as you've done in the next bit with doll.image_id).

ggp
11-24-2006, 12:22 AM
Is this better?



<?php

$sql = ("SELECT gameandtoyname, pricevalue, bigdescription, prices.pricetype, prices.pricevalue
FROM dollsimage as image_id, doll as image_id , prices
WHERE image_id='$image_id' and doll.image_id='$image_id'
");
?>



Then i get this:
Invalid query: Not unique table/alias: 'image_id'

I just wonder the easies way. But :confused:

GJay
11-24-2006, 12:05 PM
when you use
dollsimage AS image_id
you're telling the SQL parser that the label 'image_id' is now a reference to the 'dollsimage' table. This doesn't make sense, put the tablenames back to how they were.
Without telling me the structure of your tables, I can't work out from your posts which tables have what columns and (more to the point) what you're actually trying to do. Perhaps if you elaborate then I could help you with an actual solution, rather than just fixing the little mistakes one at a time.

guelphdad
11-24-2006, 02:51 PM
what you should do is fix your sql call first. then, and only then, should you worry about coding it in php.

right now your query most likely will not return your expected results.

ask a moderator to move the thread over to the mysql forum. show the layout of your table(s) structure. show some sample rows from your table(s) and your expected output.

at the point your query is figured out and working correctly in mysql alone, then I will be happy to move the thread back here if you are having trouble displaying results with php.

ggp
11-24-2006, 06:59 PM
Hi.
I would like to move the thread over to the mysql forum. Can you help with this?

thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum