|
Posted by Rami Elomaa on 06/01/07 16:29
Schraalhans Keukenmeester kirjoitti:
> At Fri, 01 Jun 2007 07:59:11 -0700, Akhenaten let h(is|er) monkeys type:
>
>> I must be missing something rather obvious. I have the following
>> snippet of code that echo's my result twice when it should be echoing
>> just once (only one element in the array). What am I overlooking?
>>
>>
>> ********************************
>> $OpenQ = mysql_query("SELECT column FROM table WHERE q_uid =
>> $_SESSION[userid] AND status = 1",$db); // SQL query on DB returns 1
>> result
>
> Rami has answered your question. I just wondered whether:
> a) userid is a defined constant. If not, it should be in quotes.
I used to think this too, but after reading the manual once again
carefully, I discovered that this is not the case. Singlequotes in array
keys aren't required when inside double quotes. It will not look for the
constant, _unless_ you also use curly braces around it.
$foo = "$array[key]"; // This is right, assumes key is a string
$foo = "{$array[key]}"; // this assumes key is a constant, then falls
back to string, so it'll trigger some stupid notice..
$foo = "{$array['key']}"; // This again is right
$foo = "$array['key']"; // quotes without curly braces is wrong, parse
error.
The thing is, if you're calling a multidimensional array, you gotta use
the curly braces, and that forces you to use the single quotes:
$foo = "{$array[0]['key']}";
It's all here in the better book:
http://fi.php.net/manual/en/language.types.string.php
--
Rami.Elomaa@gmail.com
"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
Navigation:
[Reply to this message]
|