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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    This is a bug in PHP, right?

    In my SQL table, column number4 equals '18' and column set0 equals '1'
    PHP Code:
    <?php
        $query 
    "SELECT * FROM tablea WHERE id = (SELECT MAX(id) FROM tablea)";
        
    $result mysql_query($query);
        
    $row mysql_fetch_array($result);
        echo 
    $row['number4'];
        echo 
    $row['set0'];
    ?>
    $row['number4'] echo's fine, but $row['set0'] does not echo at all. Is this a bug in PHP?

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    I haven't even started on mysql yet, but I suspect it isn't a bug. You just have to call each one separately, maybe by looping over the calls. Try swapping the two in the code and see which one gets echoed.

  • #3
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your reply man.

    Unfortunately, your suggestions didn't work. :\

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    No, it can't be a bug in PHP, your setup is correct, your data is probably wrong somewhere. Presumably, if you throw your query info phpMyAdmin or some other command line, it works fine?

    If you do print_r($row);, show us what you get? or var_dump($row['set0'])

  • #5
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    Try changing this:

    PHP Code:
    $result mysql_query($query); 
    to this
    PHP Code:
    $result mysql_query($query) or die(mysql_error()); 
    you might also want your query to be:

    PHP Code:
    $query "SELECT * FROM tablea ORDER BY id DESC limit 1"
    if you're trying to get the last record in the tablea table.

  • #6
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Keleth View Post
    Presumably, if you throw your query info phpMyAdmin or some other command line, it works fine?

    If you do print_r($row);, show us what you get? or var_dump($row['set0'])
    Yes it works fine, but I need the value of $row['set0'].

    I did a print_r() and everything came out fine, except, $row['set0'] was empty, yet its not because I can see it in my table via my SQL's console.
    Last edited by Aquawave; 07-17-2012 at 07:00 PM.

  • #7
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    var_dump didn't give any useful info? I can't think of ANY reason why some of your columns would show up correctly but not others.

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Issue a var_dump and post that.
    The data is your problem, not the code. Make sure your error reporting is enabled as well:
    PHP Code:
    ini_set('display_errors'1);
    error_reporting(E_ALL); 
    It would also be helpful to issue a SHOW CREATE TABLE tablea and show that as well.


  •  

    Posting Permissions

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