katie77 Posted January 1, 2008 Share Posted January 1, 2008 Hi there, I've got an associative array that I've called and I'm trying to find a simple way of parsing through the rows. $dataset_row = mysql_fetch_array($result, MYSQL_ASSOC); for ($column_counter = 1; $column_counter <= $num_columns; $column_counter += 1) { echo $dataset_row['ext_url']."<br />; } How can I get the row values of $dataset_row? Can I use $dataset_row[1] or something? The trouble is I need to specify the rows between and after - eg loop between rows 3-7. Can anyone help! Quote Link to comment https://forums.phpfreaks.com/topic/83998-solved-moving-down-mysql_fetch-array-rows-in-for-loop/ Share on other sites More sharing options...
revraz Posted January 1, 2008 Share Posted January 1, 2008 May want to try foreach Quote Link to comment https://forums.phpfreaks.com/topic/83998-solved-moving-down-mysql_fetch-array-rows-in-for-loop/#findComment-427448 Share on other sites More sharing options...
hitman6003 Posted January 1, 2008 Share Posted January 1, 2008 I'm assuming you want to loop through the rows of your mysql result set...you're not very clear. while ($row = mysql_fetch_assoc($result)) { echo $row['ext_url']; } The easiest way to loop through only rows 3-7 is to only select those rows from your database. Reformat your query to better select your data, or use a limit on the end of your select statement. There are other methods, but using SQL to select out only the data you want is the best in my opinion. Quote Link to comment https://forums.phpfreaks.com/topic/83998-solved-moving-down-mysql_fetch-array-rows-in-for-loop/#findComment-427449 Share on other sites More sharing options...
katie77 Posted January 1, 2008 Author Share Posted January 1, 2008 hi there, that' looks like it'll work - with regards to the 3-7 select - it's because I'm using the same information 10-15 times in different ways on the same page, so if there is a more efficient way of loading the table and presenting it in different ways, I'd be interested! Quote Link to comment https://forums.phpfreaks.com/topic/83998-solved-moving-down-mysql_fetch-array-rows-in-for-loop/#findComment-427456 Share on other sites More sharing options...
hitman6003 Posted January 1, 2008 Share Posted January 1, 2008 You can use mysql_data_seek to change the starting row. http://www.php.net/mysql_data_seek // I'm assuming that $result has > 10 rows mysql_data_seek($result, 2); // the result set starts @ 0, so 2 == the third row // print results 3 - 7 for ($x = 3; $x <= 7; $x++) { $row = mysql_fetch_assoc($result); print_r($row); } mysql_data_seek($result, 0); // move back to the first result //print the first 3 results. for ($x = 0; $x <= 2; $x++) { $row = mysql_fetch_assoc($result); print_r($row); } Quote Link to comment https://forums.phpfreaks.com/topic/83998-solved-moving-down-mysql_fetch-array-rows-in-for-loop/#findComment-427459 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.