Re: [PHP] arrays() current() next() who to use
From: Vern [EMAIL PROTECTED] How can I now get this output displyed in groups of 10 so that I can display them 10 at a time on a page then click a next button to dispaly they next 10 and so forth? Can't you do all that sorting in your query so you can just retrieve 10 rows at a time using LIMIT? ---John Holmes... UCCASS - PHP Survey System http://www.bigredspark.com/survey.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] arrays() current() next() who to use
Problem with that is it sorts according the results of the recordset range. For instance: It will show the user 1 trhough 10 sorted by miles then 20 - 30 sorted by miles, however, in 1 through 10 could have a range of 0 to 1000 miles and the next set will have 5 to 200 miles. What I need is to sort them all by miles first. The only way I know to do that is to do the way I set it up. So if I create an array, sort that array by the miles then use that array. However the array is different that the recordset and thus does not use LIMIT. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] arrays() current() next() who to use
Vern [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Problem with that is it sorts according the results of the recordset range. For instance: It will show the user 1 trhough 10 sorted by miles then 20 - 30 sorted by miles, however, in 1 through 10 could have a range of 0 to 1000 miles and the next set will have 5 to 200 miles. What I need is to sort them all by miles first. The only way I know to do that is to do the way I set it up. So if I create an array, sort that array by the miles then use that array. However the array is different that the recordset and thus does not use LIMIT. What about this: SELECT * FROM table ORDER BY miles LIMIT 0, 10 Then pass the offset to your query function and exchange it with 0: SELECT * FROM table ORDER BY miles LIMIT $offset, 10 Of course you have to properly validate that $offset is an integer before using it in the query. Regards, Torsten Roehr -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] arrays() current() next() who to use
The miles are being caluculated during the loop that is created using the recordset not in the database. First I create a do..while loop to get the miles do { $k = 0; //SET FIRST ARRAY OF ONLINE USERS AND CALCULATE MILES do { //GEOZIP $zip2 = $row_rsUSERIDID['zip']; $coor1=mycoors($zip1); $coor2=mycoors($zip2); $line1=split(\|,$coor1); $line2=split(\|,$coor2); $totaldist=distance($line1[0],$line1[1],$line2[0],$line2[1],mi); //SET NEW ARRAY WITH MILES $z['username'][$k] = $row_rsUSERIDID['uname']; $z['distance'][$k++] = $totaldist; } while ($row_rsUSERIDID = mysql_fetch_assoc($rsUSERIDID)); //SET NEW ARRAY $z['user'] = $z['username']; //SORT BY DISTANCES natsort ($z['distance']); reset ($z['distance']); //DISPLAY USER INFORMATION SORTED BY MILES foreach($z['distance'] as $k = $v){ $newuser = $z['user'][$k]; echo $newuser . - . $v . br; } } while ($row_rsUSERIDID = mysql_fetch_assoc($rsUSERIDID)); I now what to display this info 10 records at a time. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] arrays() current() next() who to use
* Thus wrote Vern: I'm setting up an array based on recordset that does a loop as follows: do { //SET ARRAYS $z['username'][$k] = $row_rsUSERIDID['uname']; $z['distance'][$k++] = $totaldist; } while ($row_rsUSERIDID = mysql_fetch_assoc($rsUSERIDID)); ... How can I now get this output displyed in groups of 10 so that I can display them 10 at a time on a page then click a next button to dispaly they next 10 and so forth? Well, this is the hard way to do things, and very inefficient but: foreach(array_slice($z['distance'], $start, 10) { //... } Curt -- First, let me assure you that this is not one of those shady pyramid schemes you've been hearing about. No, sir. Our model is the trapezoid! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] arrays() current() next() who to use
Well, this is the hard way to do things, and very inefficient but: foreach(array_slice($z['distance'], $start, 10) { //... } If you think there's a better way of doing it I would like to hear it. However this is resulting in an Parse error on the foreach line: foreach(array_slice($z['distance'], $start, 10)) { $newuser = $z['user'][$k]; echo $newuser . - . $v . br; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] arrays() current() next() who to use
If you think there's a better way of doing it I would like to hear it. However this is resulting in an Parse error on the foreach line: foreach(array_slice($z['distance'], $start, 10)) { $newuser = $z['user'][$k]; echo $newuser . - . $v . br; } foreach needs an as, probably that was meant to say: foreach(array_slice($z['distance'], $start, 10) as $k = $v) { ... - michal migurski- contact info and pgp key: sf/cahttp://mike.teczno.com/contact.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php