Re: [PHP] foreach ($media as $key => $val) problem SOLVED
Thanks Kristen and TG!! Worked like a charm Kristen G. Thorson wrote: Jack Jackson wrote: Hi, all, This might look like a mysql problem but I assure you it's my botching the PHP which is the problem! I'm building a part of a page with info from three tables: art, media and media_art. Media_art is the intersection table. For every entry in art there can be one or more entries in media. art.art_id 1 has two entries in media_art: Media_id art_id 32 52 I do this SQL, which in phpmyadmin returns the two names of media as expected SELECT media.media_name FROM art, media_art, media WHERE art.art_id = 1 AND art.art_id = media_art.art_id AND media.media_id = media_art.media_id Yet here's where I mess up. To see if I've got them in an array, I do: $media = mysql_fetch_assoc($media_result); while ($media = mysql_fetch_assoc($media_result)) { If this particular example has only two rows to return, then the above two lines look like the culprit. $media = ... is fetching the first row, but you're not doing anything with it, then while( $media = ...) will fetch the second and print it out. Take out the first line above. asort($media); foreach($media as $key => $val) { echo "key: $key value: $val "; } } //end while $media = mysql_fetch_assoc($media_result) and this returns only the name of the HIGHer number of the two (that is, 5). What have I done wrong to echo out each name of the media associated with this record? I'm trying, eventually, to echo it out in the age so that it appears as [art_id 1] comprises Ink, watercolor. Thanks in advance, Jack -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Can no one help with this opendir problem?
Hi, I wrote a few days ago and have heard nothing - can ANYONE help with this: I've got a script that is installed on a Solaris machine that is having difficulties, and I'm wondering if anyone can help. The script is trying to access and read files within a directory, pull some at random and put them in a webpage. The path is correct, the directory is set to 755 and I can view the files when I browse in. The script is up and running perfectly on two other servers - one on Red Hat Linux and one on Win2k. The script is this: "; } } // $l != 0 } // $banner != FALSE ?> The problem on the solaris machine is that opendir is getting in to the directory but from that point the server won't let the script read the files. It kicks back the error: Warning: 1 is not a valid Directory resource in /data0/foo.org/members/foo/foo/html/destinations/templates/foo.footer.php on line 20 (Identifying directories are foo'd out) Since it kicks back the "1" and not a false, it seems it's getting access but then not being permitted. Here's something else - the problem is intermittent: sometimes the script can grab the images and others not. Can anyone help? Many thanks in advance. NIck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] opendir problem on solaris
Hi, I've got a script that is installed on a Solaris machine that is having difficulties, and I'm wondering if anyone can help. The script is trying to access and read files within a directory, pull some at random and put them in a webpage. The path is correct, the directory is set to 755 and I can view the files when I browse in. The script is up and running perfectly on two other servers - one on Red Hat Linux and one on Win2k. The script is this: "; } } // $l != 0 } // $banner != FALSE ?> The problem on the solaris machine is that opendir is getting in to the directory but from that point the server won't let the script read the files. It kicks back the error: Warning: 1 is not a valid Directory resource in /data0/foo.org/members/foo/foo/html/destinations/templates/foo.footer.php on line 20 (Identifying directories are foo'd out) Since it kicks back the "1" and not a false, it seems it's getting access but then not being permitted. Here's something else - the problem is intermittent: sometimes the script can grab the images and others not. Can anyone help? Many thanks in advance. NIck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php