user4fun Posted February 24, 2011 Share Posted February 24, 2011 I am trying to wrap my head arround this one.I am trying to create (Maybe a while loop) that will mean these criteriasSelect records from tblList where $Req_Zip = Col_ZipCodeDisplay the list1- It has to keep going untill it pulls 8 records.If it can only list maybe 3, then it needs to arrange the $Req_Zip value to become $Req_Zip+1 (i.e $Req_Zip=29211, then it will become 29212. When it goes through that, if it still cannot list a total of 8 recordsThen it needs to rearrange $Req_Zip to $Req_Zip-1 (i.e 29211 will become 29210)If and when all three events take place and 8 records are found then stopIf it could not find 8 records Print statement "That is all we have"I guess I need to use IFNULL in there mixed in with a for of while loop. Any ideas? and what would it look like! Link to comment Share on other sites More sharing options...
birbal Posted February 24, 2011 Share Posted February 24, 2011 i think there is many ways to do it..as far now this coming into my mind...you can put $count++ to count the itaration of looping in while loop. then you can check each time that its raching the $count==8 or not..if no then again loop through by decreasing the $req_zip value ..check again the $count..if no then again loop increasing $regip.. Link to comment Share on other sites More sharing options...
dsonesuk Posted February 24, 2011 Share Posted February 24, 2011 Can't you just sort , select all zip code greater than or equal to the zip code you require, and limit the records to 8.$sql = "SELECT Col_ZipCode FROM tblList WHERE Col_ZipCode >= $Req_Zip ORDER BY Col_ZipCode ASC LIMIT 8";$result=mysql_query($sql);$count=mysql_num_rows($result); //will give the total number of records foundyou can then use count to set the limt in reverse <$Req_Zip until the 8 files are found, if not, use count from both sql results to show messageif($totalcount<8){echo "That is all we have";} Link to comment Share on other sites More sharing options...
user4fun Posted February 24, 2011 Author Share Posted February 24, 2011 Good idea to give me ways to think about it. The problem is that the $Req_Zip must e displayed first before other values that will some be bigger, and others will be smaller. Link to comment Share on other sites More sharing options...
dsonesuk Posted February 24, 2011 Share Posted February 24, 2011 well it will be if you have something similar to <?php$zipsearch = 111111;$limitvalue = 6;mysql_select_db($database_glf, $glf);$query_zip = "SELECT member_phone FROM golf_members WHERE member_phone >= $zipsearch ORDER BY member_phone ASC LIMIT $limitvalue";$zip = mysql_query($query_zip, $glf) or die(mysql_error());$Rows_zip = mysql_num_rows($zip);$totalRows_zip = $Rows_zip; echo 'Zip code search value: '.$zipsearch.' : Total number Required: '.$limitvalue.'<br />'; echo "<hr />";echo 'Greater and Equal to '.$zipsearch.'<br />';while($row_golf = mysql_fetch_assoc($zip)) {echo $row_golf['member_phone'].'<br />'; } echo 'Total found So Far: '.$totalRows_zip.'<br />'; echo "<hr />"; echo 'Lesser Than '.$zipsearch.'<br />';if( $totalRows_zip < $limitvalue){$Total_limitvalue = $limitvalue-$totalRows_zip;$query_zip = "SELECT member_phone FROM golf_members WHERE member_phone < $zipsearch ORDER BY member_phone DESC LIMIT $Total_limitvalue";$zip = mysql_query($query_zip, $glf) or die(mysql_error());$Rows_zip = mysql_num_rows($zip);$totalRows_zip = $Rows_zip+$totalRows_zip;}while($row_golf = mysql_fetch_assoc($zip)) {echo $row_golf['member_phone'].'<br />'; } echo 'Total found So Far: '.$totalRows_zip.'<br />';if( $totalRows_zip<$limitvalue){echo "not enough records found";}else{echo "All required number of records found";} ?> should end up with something likeZip code search value: 111111 : Total number Require: 6Greater and Equal to 111111111111121212333333666666888888Total found So Far: 5Lesser Than 111111101010Total found So Far: 6All required number of records found Link to comment Share on other sites More sharing options...
user4fun Posted February 25, 2011 Author Share Posted February 25, 2011 This is great, it opens up a whole new set of windowsthank you Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.