![]() |
| ||
| Initialization of an Array I use an array for the first time in a while loop without declaring it(as php does not need it) As the while loop is repeating it increases the number of the array. Am I doing this right? Should I have before the loop some code like: Dont know abit confused and lost. Thanks, Regards X |
| ||
| Re: Initialization of an Array As you have already said it yourself, you don't have to explicitly declare a variable as an array to use it like an array. You can simply use $var[] = "value"; This will treat $var as an array. But, its always a good practice to initialize a variable before using it. (But most of them don't do it ;) ) |
| ||
| Re: Initialization of an Array Nav to the rescue again! Umm nav I can declare it but I cant initialize it as I dont want to give it a value till used in the while loop, so. What code would I use? $var[]; ? |
| ||
| Re: Initialization of an Array But, you can't use a normal variable to act like an array. Example, |
| ||
| Re: Initialization of an Array Ya nav that what I have, but I cant seem to print the $var variable should just be print/print_r/echo $var; but none of it works... |
| ||
| Re: Initialization of an Array Why ? print_r($arrayname) should work fine. |
| ||
| Re: Initialization of an Array Its being stupid, in short. It wont let me declare the array before the html, I thought it was possible? Anyways I have found another way to do it, just need a questions answered. [code syntax="php"] while($row = mysql_fetch_array($result)) { //then to release after it is used so you can reuse it is? mysql_free_result($result); [/code] This correct, Thanks. |
| ||
| Re: Initialization of an Array When you execute a query, a resource identifier will be assigned to $result. mysql_free_result will free this value. |
| ||
| Re: Initialization of an Array Allowing me to reuse the query again or in other words fetch it again? Man nav php can be so annoying at times I fix one error and a new error pops up. I throw the arrays in a forloop and now more errors :( . Ill get back to debuging and keep you posted to see if anything works. PS: can you run queries in a for loop? That could be a possible error? or declare it differently? |
| ||
| Re: Initialization of an Array I don't know whats causing the error. You can run queries in a for loop. Once you have freed the result using mysql_free_result, that resource identifier is freed. Actually, if your query isn't too complicated, you don't have to use free_result as php frees the result at the end of execution of the script. Source: http://nl3.php.net/mysql_free_result Can you post your code here ? |
| All times are GMT -4. The time now is 5:25 am. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC