[PHP] Re: global variable declaration
suresh kumar wrote: hai, this is my sample code: i am having user table with SponsorID as one field in mysql database,this is my query; for($j=0;$j5;$j++): $result=mysql_query(select * from user where SponsorID='$id[$j]' ); endfor; in above code when i print mysql_num_rows($result) inside for loop its output is 5.when i print outside the for loop its o/p is 0.I searched weberdev.com website and declared $result as global.but same output 0.i want $result variable to be available outsibe the forloop and all other part of my code.i am looking forward suggestions from ur side. A.suresh - Jiyo cricket on Yahoo! India cricket Yahoo! Messenger Mobile Stay in touch with your buddies all the time. At first i would rather use the LIMIT from MySQL than a for loop. $query = SELECT * FROM foo WHERE bar = 'foobar' LIMIT 5; $result = mysql_query($query); // Now you can use a while loop to print it out while ($row = mysql_fetch_assoc($result)) // mysql_fetch_assoc is the same as mysql_fetch_array with ASSOC { echo $row[somefield]; // to have it availible out of the code use this $outer_array[] = $row; } print_r($outer_array); // now the array has the fields of the Query in it. // as you can see using print_r(); // now you can access it like: $outer_array[0]; $outer_array[1]; ... $outer_array[n]; Your FOR loop replaces the variable $result everytime. That's why it is empty. Greets Barry -- Smileys rule (cX.x)C --o(^_^o) Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Global variable question question
Jason Giangrande [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] When registered globals is set to off this does not effect the $PHP_SELF variable right? In other words I should be able to call $PHP_SELF with out having to do this $_SERVER['PHP_SELF'], right? Thanks, Jason Giangrande I would assume that if you turned register_globals off $PHP_SELF will no longer be available. Course you can always extract($_SERVER); if you want the effect of register_globals inside your script without turning the feature on globally. - Kevin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Global variable
Maybe you could use sessions like: session_start(); session_register('verified'); $verified=0 Erich Kolb [EMAIL PROTECTED] skrev i meddelandet [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I have developed a simple login script. Right now it will check a submitted username and password and verify it against a database. This part works fairly well, however I want to know how to assign a variable that will pass through to the next page(s) to do something like: if verified == 1 then {display the page} else {display error message} My apoligies on the syntax of the above, but hopefully you will get the idea. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Global Variable Change
Thomas Brodkorb wrote: Hi folks, small problem with globals: I would like to set a variable global called Language This seems to be not a really problem, but it is Indexphp: ?php { session_start(); if (!session_is_registered('Language')) { session_register('Language'); $Language = 1031; } ? But all other pages do not have really access to this variable without calling start_session() from within the other pages() You must start session implicitly or explicitly I suggest to start session explicitly Do not use auto start If I call, it works Now the real problem I would like to set $Language by an Hyperlink with image hyperlinks, but it doesnt change anything Within the hyperlink I call setlanguagephp?lang=1033 ?php { session_start(); if ( ($lang 1031) and ($lang 1033) ) { $lang= 1031; } $Language = $lang; if (session_is_registered('Language')) { session_unregister('Language'); } session_register('Language'); } ? But it doesnt change ANYTHING What is not changed? -- Yasuo Ohgaki -- PHP General Mailing List (http://wwwphpnet/) To unsubscribe, visit: http://wwwphpnet/unsubphp
[PHP] Re: global variable.
Nafiseh Saberi [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... hi. I want to use glabal variable. ? global $a; ? but it doesnot work?? ... why do you think you need to use global here? global is used *in a function* to let it see external variables. You are not in a function, so I don't see why you think you need it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Re: Global Variable Variables...
Read References explained section in PHP Manual. You'll see why it does not work as you expected. -- Yasuo Ohgaki [EMAIL PROTECTED] [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I have a class that contains a form, when the form is submitted it posts back to the class. The class is included inside of another file, so all of the form variables need to be declared as global in order to access their values. On the form are several check boxes (number undetermined until the script is run) and the only way I know to access these values is using the variable variables feature of PHP, as follows: $A = chkContact.$I; $B = $$A; This would work just fine if $chkContact## was not a global variable (ie..not wrapped inside of a class). How can I use variable variables on a global variable? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]