SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    had an slq syntax error now it is an undefined index 'rating' on line 465

    I have a query error

    Error in query: SELECT rating , COUNT(*) AS rating_counts FROM rating WHERE item_name = GROUP BY rating. 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 'GROUP BY rating' at line 2
    the query goes like this

    $query ="SELECT rating , COUNT(*) AS rating_counts FROM rating
    WHERE item_name = $shoename GROUP BY rating";
    Last edited by co.ador; Jul 26, 2009 at 14:34.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    it looks like you forgot to ensure that $shoename has an actual value
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    now it say

    PHP Code:
    Error in querySELECT rating COUNT(*) AS rating_counts FROM rating WHERE item_name Pernil GROUP BY ratingUnknown column 'Air Jordan' in 'where clause' 
    But $shoename is not part of the table rating is just a variable picked up from the url and I put it in there so it can match item_name value, But now it say unknown column.

    Air jordan is the value of $shoename

    Does it mean that after the = the variable in there has to be an column in the rating table?

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by co.ador View Post
    Does it mean that after the = the variable in there has to be an column in the rating table?
    no, what the error message is telling is that it looks like you want to reference a column called Air Jordan

    what you want is to make $shoename a string, by enclosing it in single quotes

    i know you could've figured this out and will understand it as soon as you realize what's going on
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you I realized that the commas were missing

    now i recieving this php error


    PHP Code:
    NoticeUndefined indexin C:\wamp\www\shoes\stores\itemdetails2.php on line 465
    1 Star Active 

    PHP Code:
    $query ="SELECT rating , COUNT(*) AS rating_counts FROM rating
     WHERE item_name = '
    $platename' GROUP BY rating";

    $result mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 

    // see if any rows were returned 
    if (mysql_num_rows($result) > 0) { 
    $ratings array_fill(1,5,0);
    $rowsCount count($result); // assume $rows is the result array

    for($i=0;$i<$rowsCount;$i++) {
        
    $ratings[$result[$i]['rating']]++; // line 465 
    i don't get why it is referring to undefined index because rating is a column field in the database rating I guess it is talking about 'rating'

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    they are called 'single quotes' not ,commas,

    as for your index, hey, sorry man, i don't do php

    i'm gonna ask that this thread, just like your other one, be moved to the php forum
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    singles quotes and double quotes still on the learning and production curb at the same time thank all of you for take a little bit of your time.


Bookmarks

Posting Permissions

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