.josh Posted May 8, 2006 Share Posted May 8, 2006 okay so here's my code:[code]//******************function to list providersfunction list_providers($services_to_search, $filter) { $providerlist = search_for_providers($services_to_search, $filter); //print the list of providers and their services $temp = 0; $count = 0; while ($providerlist[$temp]) { $blah = $providerlist[$temp]['provider_name']; echo $blah." "; while ($blah == $providerlist[$count]['provider_name']) { echo $providerlist[$count]['service_name']." "; $count++; }//end while $temp++; echo "<br>"; }}//******************end function show_provider_form[/code]here's a link to the script in action:[a href=\"http://www.chroniclesofwar.com/providersearch.php\" target=\"_blank\"]http://www.chroniclesofwar.com/providersearch.php[/a]submit a random search and you will see something like this:[!--coloro:blue--][span style=\"color:blue\"][!--/coloro--]provider3 service1 service3 service5 service6[!--coloro:red--][span style=\"color:red\"][!--/coloro--]provider3provider3provider3[!--colorc--][/span][!--/colorc--]provider4 service2 service3 service5 service6[!--coloro:red--][span style=\"color:red\"][!--/coloro--]provider4provider4provider4 [!--colorc--][/span][!--/colorc--][!--colorc--][/span][!--/colorc--]okay so yeh, i want that stuff in the red to go away. help? i know just as soon as i post this i'll probably figure it out,lol. i know it's not that hard... Quote Link to comment https://forums.phpfreaks.com/topic/9284-problem-formatting-search-results/ Share on other sites More sharing options...
zq29 Posted May 8, 2006 Share Posted May 8, 2006 Could you post up your search_for_providers() function too, it looks like the error might actually be in there... Quote Link to comment https://forums.phpfreaks.com/topic/9284-problem-formatting-search-results/#findComment-34241 Share on other sites More sharing options...
.josh Posted May 8, 2006 Author Share Posted May 8, 2006 well, no, i don't think the error is there. it returns the array $providerlist. i can dump the array out to the screen just fine with this:[code] $temp=0; while ($providerlist[$temp]){ foreach($providerlist[$temp] as $val) { echo $val." "; } echo "<br>"; $temp++; } [/code]and it has all the information in it just fine. my problem is with formatting it the way i want to. but if you think it will help, here is the search_for_providers function:[code]//**************** function to search for providersfunction search_for_providers($services_to_search, $filter) { $connection = connect(); if ($services_to_search) { $sql ="SELECT p.provider_name, m.service_id, services.service_name FROM providers AS p "; $sql.="INNER JOIN maintable AS m ON p.provider_id = m.provider_id "; $sql.="INNER JOIN services ON services.service_id = m.service_id "; $sql.="WHERE p.provider_id IN ("; $sql.="SELECT p2.provider_id FROM providers AS p2 "; $sql.="INNER JOIN maintable AS m2 ON ( m2.provider_id = p2.provider_id ) "; $sql.="WHERE m2.service_id IN ("; //**insert service id's from checkboxes $numberservices = 0; foreach ($services_to_search as $id) { $sql.="'$id',"; $numberservices++; } $sql = substr_replace($sql,"",-1); $sql.=") "; $sql.="GROUP BY p2.provider_name HAVING COUNT( * ) >= "; $sql.= ($filter=='only') ? $numberservices : 1; $sql.=") ORDER BY p.provider_name"; }//end if services_to_search $query = mysql_query($sql, $connection) or die(mysql_error()); while($result=mysql_fetch_array($query)) { $providers[] = array('provider_name' => $result['provider_name'], 'service_id' => $result['service_id'], 'service_name' => $result['service_name']); }//end while mysql_close($connection); return $providers;} //***********end function search_for_providers[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9284-problem-formatting-search-results/#findComment-34261 Share on other sites More sharing options...
.josh Posted May 8, 2006 Author Share Posted May 8, 2006 <bump>okay again, here's my current code:[code]//******************function to list providersfunction list_providers($services_to_search, $filter) { $providerlist = search_for_providers($services_to_search, $filter); //print the list of providers and their services $temp = 0; $count = 0; while ($providerlist[$temp]) { $blah = $providerlist[$temp]['provider_name']; echo $blah." "; while ($blah == $providerlist[$count]['provider_name']) { echo $providerlist[$count]['service_name']." "; $count++; }//end while $temp++; echo "<br>"; }}//******************end function show_provider_form[/code]i think all i really need to do is run a check ater $temp++ to see if $providerlist[$temp]['provider_name'] has changed or not, and only echo $blah when it has changed and on the first iteration. but i'm not sure how to implement that. Quote Link to comment https://forums.phpfreaks.com/topic/9284-problem-formatting-search-results/#findComment-34443 Share on other sites More sharing options...
.josh Posted May 8, 2006 Author Share Posted May 8, 2006 okay nevermind i figured it out on my own. in case anybody is interested (doubtful), here's the solution:[code]//******************function to list providersfunction list_providers($services_to_search, $filter) { $providerlist = search_for_providers($services_to_search, $filter); //print the list of providers and their services $temp = 0; $count = 0; while ($providerlist[$temp]) { $blah = $providerlist[$temp]['provider_name']; if ($temp >= 0) { if ($blah != $providerlist[($temp-1)]['provider_name']) { echo $blah." "; while ($blah == $providerlist[$count]['provider_name']) { echo $providerlist[$count]['service_name']." "; $count++; }//end while echo "<br>"; }//end if $blah != ... }//end if $temp >= ... $temp++; }//end while $providerlist}//******************end function show_provider_form[/code]i'm sure there's a better way to do this, but... oh well. Quote Link to comment https://forums.phpfreaks.com/topic/9284-problem-formatting-search-results/#findComment-34452 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.