dflow Posted September 14, 2008 Share Posted September 14, 2008 hi im trying to extract the results fetched in this while loop as $var1,$var2 etc until the end of the rows fetched by this query: <?php $query="SELECT * FROM Suppliers WHERE CITY='Berlin'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['website_url']; echo "<br />"; } ?> i would like to continue this as : $var1=$GET_ROW#1; $var2=$GET_ROW#2; $var3=$GET_ROW#3; and so on until the of the query and then use the variables created in a new loop i hope i am clear thx Link to comment https://forums.phpfreaks.com/topic/124193-how-to-parse-an-array-into-variables/ Share on other sites More sharing options...
genericnumber1 Posted September 14, 2008 Share Posted September 14, 2008 why not just use a multidimensional array? Link to comment https://forums.phpfreaks.com/topic/124193-how-to-parse-an-array-into-variables/#findComment-641247 Share on other sites More sharing options...
dflow Posted September 14, 2008 Author Share Posted September 14, 2008 and how would you start it off i need to create a counter per each row and the print the rows into variablrs in the array Link to comment https://forums.phpfreaks.com/topic/124193-how-to-parse-an-array-into-variables/#findComment-641387 Share on other sites More sharing options...
DarkWater Posted September 14, 2008 Share Posted September 14, 2008 What do you mean by "a counter per each row"? Link to comment https://forums.phpfreaks.com/topic/124193-how-to-parse-an-array-into-variables/#findComment-641402 Share on other sites More sharing options...
genericnumber1 Posted September 14, 2008 Share Posted September 14, 2008 I'm not sure what you mean, but to load a result into an array you could do something like.. $query = "blah blah"; $result = mysql_query($query); $array = array(); while($row = mysql_fetch_assoc($result)) { $array[] = $row; } Link to comment https://forums.phpfreaks.com/topic/124193-how-to-parse-an-array-into-variables/#findComment-641408 Share on other sites More sharing options...
dflow Posted September 14, 2008 Author Share Posted September 14, 2008 by counter i mean some sort of identification for each result $array[0] $array[1] etc Link to comment https://forums.phpfreaks.com/topic/124193-how-to-parse-an-array-into-variables/#findComment-641564 Share on other sites More sharing options...
genericnumber1 Posted September 14, 2008 Share Posted September 14, 2008 then use my above code... $array[0] would be the first element, $array[1] the next, etc. when you don't specify the key "[]" it just appends it to the end of the array with the next number. Link to comment https://forums.phpfreaks.com/topic/124193-how-to-parse-an-array-into-variables/#findComment-641565 Share on other sites More sharing options...
dflow Posted September 14, 2008 Author Share Posted September 14, 2008 cool this works the next part i imagine is using the foreach loop i want to get the web_url field value from each row generate in the array how do i define the specific field ? Link to comment https://forums.phpfreaks.com/topic/124193-how-to-parse-an-array-into-variables/#findComment-641581 Share on other sites More sharing options...
PFMaBiSmAd Posted September 14, 2008 Share Posted September 14, 2008 Whatever processing you are doing, you should just do in the first while() loop. Making a copy of values and then looping a second time is unnecessary and it is a waste of memory and a waste of processing time. Link to comment https://forums.phpfreaks.com/topic/124193-how-to-parse-an-array-into-variables/#findComment-641585 Share on other sites More sharing options...
dflow Posted September 14, 2008 Author Share Posted September 14, 2008 thx for the pointer how do i define the value to be a specific field from the table i queried from each array generated?? Link to comment https://forums.phpfreaks.com/topic/124193-how-to-parse-an-array-into-variables/#findComment-641590 Share on other sites More sharing options...
dflow Posted September 15, 2008 Author Share Posted September 15, 2008 ok got it in the while loop $array = array(); while($row = mysql_fetch_assoc($result)) { $array[] = $row; echo $row["City"]; echo $row["XML_PATH"]; echo $row["SupplierID"]; echo "Value:<br />\n"; } Link to comment https://forums.phpfreaks.com/topic/124193-how-to-parse-an-array-into-variables/#findComment-641595 Share on other sites More sharing options...
dflow Posted September 15, 2008 Author Share Posted September 15, 2008 now that i defined my fields how would you guys suggest, i loop through the results: and one of my fields is a XML URI what i want to achieve is to load the XML URI from each row loop through them and eventually parse some realtime data. how would you approach that? Link to comment https://forums.phpfreaks.com/topic/124193-how-to-parse-an-array-into-variables/#findComment-641598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.