SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    DB keeps returning the same row

    Hi there

    I have a problem where no matter what value I pass into my php function below, the same row keeps being returned and its not the row I requested. Has anyone seen anything like this before because I am very confused?

    Its such simple MYSQL thats why I don't understand it.

    PHP Code:

    public function getSend($order_id)
        {
          
    $query $this->dbs->query("SELECT order_id FROM SEND` WHERE order_id ='" . (int)$order_id "'");
           return 
    $order_id."<br/>db:".$query->row['order_id'];
        } 
    If I pass in 173 , my output is 173 db: 171 it just keeps returning 171 no matter what i put in there
    "Persistence is the path to perfection"

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,325
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    why would you return order_id if you pass in the order_id value that you want returned?

    i guess i don't understand what you're trying to do
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats my test code to ensure that what I'm passing in is referring to the same row that I'm getting out the actual code is to return some different data but for now I just need to make sure I have the right row returning.
    "Persistence is the path to perfection"

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,325
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    you have a dangling backtick there, so that SELECT statement will die with a syntax error

    did you test it outside of php yet?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have even tried SELECT order_id FROM SEND` WHERE order_id =173;
    The query works fine in phpMyadmin but on my site it returns 171
    "Persistence is the path to perfection"

  6. #6
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey that's it!
    It was the backtick but that's just odd because I didn't put it there, I am using opencart you see, I was just copying their syntax, I wouldn't have used it myself either
    "Persistence is the path to perfection"

  7. #7
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's the line that i copied from their code:

    $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer` WHERE customer_id = '" . (int)$customer_id . "'");

    backtick is there, weird huh?
    "Persistence is the path to perfection"

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,325
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by silversurfer5150 View Post
    backtick is there, weird huh?
    not weird at all -- their line has two backticks, and you've managed to lose one of them
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  9. #9
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your hep btw, What is the backtick for?
    "Persistence is the path to perfection"

  10. #10
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,325
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    the backtick is mysql's mechanism to delimit problematic table/column names -- those which either contain special characters (like a space) or are themselves a reserved word (like ORDER)

    SEND does not appear to be a reserved word (although it might easily be, right?) so you don't really need the backticks
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  11. #11
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I see, thanks very much
    "Persistence is the path to perfection"


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
  •