...

View Full Version : This is a bug in PHP, right?



Aquawave
07-17-2012, 07:29 PM
In my SQL table, column number4 equals '18' and column set0 equals '1'

<?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?

DrDOS
07-17-2012, 07:34 PM
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.

Aquawave
07-17-2012, 07:37 PM
Thanks for your reply man.

Unfortunately, your suggestions didn't work. :\

Keleth
07-17-2012, 07:37 PM
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'])

bcarl314
07-17-2012, 07:46 PM
Try changing this:



$result = mysql_query($query);


to this


$result = mysql_query($query) or die(mysql_error());


you might also want your query to be:



$query = "SELECT * FROM tablea ORDER BY id DESC limit 1";


if you're trying to get the last record in the tablea table.

Aquawave
07-17-2012, 07:56 PM
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.

Keleth
07-17-2012, 08:21 PM
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.

Fou-Lu
07-17-2012, 09:14 PM
Issue a var_dump and post that.
The data is your problem, not the code. Make sure your error reporting is enabled as well:


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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum