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 Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted September 14, 2008 Share Posted September 14, 2008 why not just use a multidimensional array? Quote Link to comment 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 Quote Link to comment 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"? Quote Link to comment 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; } Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 ? Quote Link to comment 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. Quote Link to comment 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?? Quote Link to comment 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"; } Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.