Enjoy an ad free experience by logging in. Not a member yet?
Register .
07-17-2012, 06:29 PM
PM User |
#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?
07-17-2012, 06:34 PM
PM User |
#2
Senior Coder
Join Date: Sep 2010
Posts: 1,156
Thanks: 10
Thanked 148 Times in 148 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.
07-17-2012, 06:37 PM
PM User |
#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. :\
07-17-2012, 06:37 PM
PM User |
#4
Senior Coder
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 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'])
07-17-2012, 06:46 PM
PM User |
#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.
07-17-2012, 06:56 PM
PM User |
#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
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 ..
07-17-2012, 07:21 PM
PM User |
#7
Senior Coder
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 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.
07-17-2012, 08:14 PM
PM User |
#8
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 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.
Jump To Top of Thread
Thread Tools
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
HTML code is Off
All times are GMT +1. The time now is 05:58 AM .
Advertisement
Log in to turn off these ads.