Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12

Thread: Select

  1. #1
    ggp
    ggp is offline
    New Coder
    Join Date
    Nov 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Select

    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 Code:
    <?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:

    PHP Code:
    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!!!!

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    separate constraints (things after 'WHERE') with 'AND' or 'OR', not with commas.

  • #3
    ggp
    ggp is offline
    New Coder
    Join Date
    Nov 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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());

    PHP Code:
    $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', 
               "
    ); 

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    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...

  • #5
    ggp
    ggp is offline
    New Coder
    Join Date
    Nov 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    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.

  • #7
    ggp
    ggp is offline
    New Coder
    Join Date
    Nov 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I did chage something. But ....? this has sense?

    PHP Code:
    <?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.

  • #8
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    as before, you need to tell it which image_id you mean (as you've done in the next bit with doll.image_id).

  • #9
    ggp
    ggp is offline
    New Coder
    Join Date
    Nov 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is this better?

    PHP Code:
    <?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

  • #10
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    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.

  • #11
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    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.

  • #12
    ggp
    ggp is offline
    New Coder
    Join Date
    Nov 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    move thread to mysql.

    Hi.
    I would like to move the thread over to the mysql forum. Can you help with this?

    thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •