son Posted October 28, 2009 Share Posted October 28, 2009 I have a query and would like to go twice through returned data (show data in different format). Is this not possible with same query? The first while shows nicely all info, the second one does not. The code is: $query = "SELECT finish_id, finish, img FROM finishes WHERE range_id = $prange"; $result = mysqli_query ($dbc, query); if (mysqli_num_rows($finish_result) > 0) { echo "<select name=\"fn\" id=\"fn\">"; echo "<option value=\"0\">Select finish</option>"; while ($row = mysqli_fetch_array ($finish_result, MYSQLI_ASSOC)) { $finish_id = $row['finish_id']; $finish = $row['finish']; echo "<option value=\"" . $finish_id . "\""; echo ">" . $finish . "</option>"; } echo "</select> "; while ($row = mysqli_fetch_array ($finish_result, MYSQLI_ASSOC)) { $finish_id = $row['finish_id']; $finish = $row['finish']; $img = $row['img']; $finishImgPath = "assets/finishes/preview/"; $size = getimagesize("assets/finishes/preview/{$img}"); echo "<img src=\"" . $mainPath . $finishImgPath . $img . "\" " . $size[3] . " alt=\"" . $finish . "\" title=\"" . $finish . "\" /></a>"; } } Do I have to run the query twice?Son Link to comment Share on other sites More sharing options...
justsomeguy Posted October 28, 2009 Share Posted October 28, 2009 Loop through and dump the results into an array, then you can loop through the array as much as you want. Link to comment Share on other sites More sharing options...
son Posted October 30, 2009 Author Share Posted October 30, 2009 Loop through and dump the results into an array, then you can loop through the array as much as you want.How can I dump the results in an array?Son Link to comment Share on other sites More sharing options...
justsomeguy Posted October 30, 2009 Share Posted October 30, 2009 $data = array();while ($row = mysql_fetch_assoc($result)) $data[] = $row;print_r($data); Be careful about memory requirements, if you have tens of thousands of records you'll probably hit the memory limit before you're able to store everything. For nicer memory usage, you can use this to reset the result pointer to the beginning so you can loop through it again:http://www.php.net/manual/en/function.mysql-data-seek.php Link to comment Share on other sites More sharing options...
son Posted November 4, 2009 Author Share Posted November 4, 2009 $data = array();while ($row = mysql_fetch_assoc($result)) $data[] = $row;print_r($data); Be careful about memory requirements, if you have tens of thousands of records you'll probably hit the memory limit before you're able to store everything. For nicer memory usage, you can use this to reset the result pointer to the beginning so you can loop through it again:http://www.php.net/manual/en/function.mysql-data-seek.php Will have a go...Many thanks,Son Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.