Jump to content

array index changes


moosoft

Recommended Posts

I tried searching for this but I didn't find anything.  I have some php code that when loaded from a web page draws some numbers from a database and outputs.  Should be no problem I thought ;)

 

The code involves a mysql query.  This is an edited sample:

$query = "SELECT `count` FROM `uc` WHERE `id` = 17";
$result = mysql_query($query, $dbh) or die(mysql_error());
$row = mysql_fetch_array($result, $dbh);

 

Now after this I normally access $row as $row[0] and this works great most of the time.  However about 10% of the time it returns an error: "Notice: Undefined offset: 0"

 

My investigation using print_r($row); shows that sometimes it returns Array ( [0] => 619 ) and sometimes it returns Array ( [count] => 619 )

 

Why the inconsistency?  How can I make it always use a numeric index?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.