Re: populate form input option dropdown box from existing data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Stuart wrote:
> 2009/6/18 PJ <af.gourmet@xxxxxxxxxxxx>:
>   
>> Martin Scotta wrote:
>>     
>>> 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@xxxxxxxxxxxx
>>> <mailto:af.gourmet@xxxxxxxxxxxx>> 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 <http://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@xxxxxxxxxxxxx <mailto:pj@xxxxxxxxxxxxx>
>>>       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
>>>       
>> Actually, we have to call it a typo because i fixed that and the results
>> are exactly the same = blank screen. :-(
>>     
>
> If you're getting a blank screen instead of an error message I highly
> recommend turning display_errors on and setting error_reporting to
> E_ALL in you dev php.ini - that way you'll actually see error messages
> rather than having to hunt through the code by hand.
>   
Duh, Stuart, I'm wet behind the ears, but that was one of my first
revelations - to use
error_reporting(E_ALL);
ini_set('display_errors', 1); ;-)

But that's what's weird...  if I comment those last 4 lines out, the
proggie works (or shall I say, limps; I still have other problems)
But the in_array just refuses to cooperate.

-- 
Hervé Kempf: "Pour sauver la planète, sortez du capitalisme."
-------------------------------------------------------------
Phil Jourdan --- pj@xxxxxxxxxxxxx
   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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux