Jump to content


Photo

problem formatting search results


  • Please log in to reply
4 replies to this topic

#1 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 08 May 2006 - 03:54 AM

okay so here's my code:

//******************function to list providers
function 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

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--]provider3
provider3
provider3[!--colorc--][/span][!--/colorc--]
provider4 service2 service3 service5 service6
[!--coloro:red--][span style=\"color:red\"][!--/coloro--]provider4
provider4
provider4 [!--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...
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 08 May 2006 - 08:24 AM

Could you post up your search_for_providers() function too, it looks like the error might actually be in there...

#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 08 May 2006 - 11:44 AM

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:

     $temp=0;
   while ($providerlist[$temp]){
       foreach($providerlist[$temp] as $val) {
                echo $val." ";
        }
     echo "<br>";
     $temp++;
     }    

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:

//**************** function to search for providers
function 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

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 08 May 2006 - 10:01 PM

<bump>

okay again, here's my current code:

//******************function to list providers
function 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
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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 08 May 2006 - 10:26 PM

okay nevermind i figured it out on my own. in case anybody is interested (doubtful), here's the solution:

//******************function to list providers
function 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
i'm sure there's a better way to do this, but... oh well.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users