Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-17-2012, 06:29 PM   PM User | #1
Aquawave
New to the CF scene

 
Join Date: Jul 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Aquawave is an unknown quantity at this point
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?
Aquawave is offline   Reply With Quote
Old 07-17-2012, 06:34 PM   PM User | #2
DrDOS
Senior Coder

 
Join Date: Sep 2010
Posts: 1,156
Thanks: 10
Thanked 148 Times in 148 Posts
DrDOS is infamous around these parts
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.
DrDOS is offline   Reply With Quote
Old 07-17-2012, 06:37 PM   PM User | #3
Aquawave
New to the CF scene

 
Join Date: Jul 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Aquawave is an unknown quantity at this point
Thanks for your reply man.

Unfortunately, your suggestions didn't work. :\
Aquawave is offline   Reply With Quote
Old 07-17-2012, 06:37 PM   PM User | #4
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
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'])
Keleth is offline   Reply With Quote
Old 07-17-2012, 06:46 PM   PM User | #5
bcarl314
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
bcarl314 will become famous soon enough
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.
bcarl314 is offline   Reply With Quote
Old 07-17-2012, 06:56 PM   PM User | #6
Aquawave
New to the CF scene

 
Join Date: Jul 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Aquawave is an unknown quantity at this point
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..
Aquawave is offline   Reply With Quote
Old 07-17-2012, 07:21 PM   PM User | #7
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
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.
Keleth is offline   Reply With Quote
Old 07-17-2012, 08:14 PM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:58 AM.


Advertisement
Log in to turn off these ads.