Bug #18063: Array not "set" when cross referencing.

From: Date: Sat, 29 Jun 2002 16:38:00 +0000
Subject: Bug #18063: Array not "set" when cross referencing.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-12530@lists.php.net to get a copy of this message
From: m3h431337n3wb13@hotmail.com Operating system: Win98SE PHP version: 4.2.1 PHP Bug Type: MySQL related Bug description: Array not "set" when cross referencing. Ok, im trying to make a "User Online:" script, but one that prints out the amount of users on a page... e.g. Users online : 17 /index.php 6 /chat.php 3 /forums.php 8 I am using another script, but I like to rewrite my own. THis is what I have done so far. <?php $link_id = mysql_connect ("localhost", "######", "######"); mysql_select_db ("online", $link_id); $query = mysql_query ("SELECT DISTINCT ip FROM useronline", $link_id); while ($results = mysql_fetch_array ($query)) { $query = mysql_query ("SELECT file FROM useronline WHERE ip = '" . $results["ip"] . "'", $link_id); } ?> I know the first query is set, becuase I can loop through $result["ip"] and get it to print out the 10 IPs held in the database. But, on running this comand... I get the following error message. Notice: Undefined index: ip in C:\Apache\htdocs\online.php on line 8 Line 8: $query = mysql_query ("SELECT file FROM useronline WHERE ip = '" . $results["ip"] . "'", $link_id); Ive tried doing..... $temp_ip = $results["ip"]; $query = mysql_query ("SELECT file FROM useronline WHERE ip = '" . $temp_ip . "'", $link_id); With no avail. What I did find interesting is that. when using this script... <?php $link_id = mysql_connect ("localhost", "######", "######"); mysql_select_db ("online", $link_id); $query = mysql_query ("SELECT DISTINCT ip FROM useronline", $link_id); while ($results = mysql_fetch_array ($query)) { echo ($results["ip"] . "<br>"); //$query = mysql_query ("SELECT file FROM useronline WHERE ip = '" . $results["ip"] . "'", $link_id); } ?> It prints out all the 10 IP's in the DB, but notice the commented out "//$query"... only when its commented out will it echo $results["ip"]! This is a defualt install of the latest PHP binary for windows (APache 2 - in ISAPI mode). Hope this helps solve mine and anyone elses problems. -- Edit bug report at http://bugs.php.net/?id=18063&edit=1 -- Fixed in CVS: http://bugs.php.net/fix.php?id=18063&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=18063&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=18063&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=18063&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=18063&r=support Expected behavior: http://bugs.php.net/fix.php?id=18063&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=18063&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=18063&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=18063&r=globals

« previous php.bugs (#12530) next »