kev wood Posted May 13, 2008 Share Posted May 13, 2008 i want to run a query on a mysql db that i have set up but when it returns the results i want it give a variable the same value as the query. i am storing a random number in a db to use with images when they are displayed so that the image does not show the cached version of the image when the page is loaded again. i have got the query to work with the echo function so i know that the number is being stored. i now need to know how to give a variable the same value as the stored number the code i am using is this $query = "SELECT random1 FROM random_number"; $result=mysql_query($query); while($row=mysql_fetch_array($result)){ $rand="{$row['random1']}"; it is the lst line that i am unsure about i do not know if this is giving the variable a value at all? Link to comment Share on other sites More sharing options...
kev wood Posted May 13, 2008 Author Share Posted May 13, 2008 it does give the variable a value but will this then be available to use around the rest of the page or is it only available to use with the mysql query. i not i not sounding clear but i is trying to explain myself. i want to be able to append this number to the end of image file as it has been stored on the server with this number appended to the file. as it is a randomly generated number the only way i can think of being able to use it again is by storing it in a db when generated and then retrieving it again when the image needs to be viewed again. it may be a stupid question but i have never used the results from a mysql query in this way before. Link to comment Share on other sites More sharing options...
fenway Posted May 13, 2008 Share Posted May 13, 2008 Once you assign another variable's value, it stay around until it goes out of scope. Link to comment Share on other sites More sharing options...
kev wood Posted May 15, 2008 Author Share Posted May 15, 2008 when you say out of scope do you mean when the page has been left of when the function to get the value has been left. Link to comment Share on other sites More sharing options...
mjcoco Posted May 15, 2008 Share Posted May 15, 2008 while($row=mysql_fetch_array($result)) { $rand="{$row['random1']}"; } This is an example of a scope. if you put a variable inside a while loop for example it will only stay there. Link to comment Share on other sites More sharing options...
fenway Posted May 15, 2008 Share Posted May 15, 2008 This is a php syntax issue... topic locked. Link to comment Share on other sites More sharing options...
Recommended Posts