Re: populate form input option dropdown box from existing data
| From: | Martin Scotta | Date: | Thu, 18 Jun 2009 13:23:22 +0000 |
| Subject: | Re: populate form input option dropdown box from existing data | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-294234@lists.php.net to get a copy of this message | ||
It is a sintax error
if (in_array($ex, $selected) <--- missing )
echo "<br />yes";
else echo "<br />no";
On Thu, Jun 18, 2009 at 10:13 AM, PJ <af.gourmet@videotron.ca> wrote:
> Ford, Mike wrote:
> > On 17 June 2009 14:30, PJ advised:
> >
> >
> >
> >> For the moment, I am trying to resolve the problem of
> >> extracting a value
> >> from a string returned by a query. I thought that in_array() would do
> >> it, but the tests I have run on it are 100% negative. The only thing I
> >> have not used in the tests is third parameter bool $strict which only
> >> affects case-sensitivity if the $needle is a string.
> >>
> >
> > $strict has nothing whatsoever at all in any way to do with case
> > sensitivity -- $strict controls whether the values are compared using
> > equality (==) or identity (===) tests. As is stated quite clearly on the
> > manual page, in_array() is always case-sensitive.
> >
> >
> >> This leads me to
> >> believe that in_array() is either inappropriately defined in
> >> the manual
> >> and not effective on associative arrays
> >>
> >
> > Complete rubbish -- the in_array() manual page is excellent and totally
> > accurate, complete with 3 working examples.
> >
> >
> I would really like to understand why my attempts to reproduce the first
> example just did not work.
> Note also that the examples do not show in_array($string, $array)
> My array was Array ([0]=>6[1]=>14....), so when I tried if
> (in_array($string, $array) , echo $string did not return 14 as I had
> expected; neither did if(in_array("14", $array) ... nor if(in_array(14,
> $array). It still does not... actually, the screen goes blank.
> So, what am I doing wrong?
> Here's what is not working... I'm trying to reproduce the example from
> php.net:
>
> $selected = array();
> if ( ( $results = mysql_query($sql, $db) ) ) {
> while ( $row = mysql_fetch_assoc($results) ) {
> $selected[] = $row['id'];
> }
> }
> print_r($selected);
> $ex = 14;
> if (in_array($ex, $selected)
> echo "<br />yes";
> else echo "<br />no";
>
> Regardless if I put 14 into $ex or "14" or '14' or even if I put the 14
> instead of the $ex into the if line, I get a blank screen. It seems tp
> me, from what I see in the manual that this should work... or am I
> supposed to know something that is not clear in the examples... ?
>
>
> --
> Hervé Kempf: "Pour sauver la planète, sortez du capitalisme."
> -------------------------------------------------------------
> Phil Jourdan --- pj@ptahhotep.com
> http://www.ptahhotep.com
> http://www.chiccantine.com/andypantry.php
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Martin Scotta