Jump to content

Recommended Posts

okay so here's my code:

[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
[/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--]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...
Link to comment
https://forums.phpfreaks.com/topic/9284-problem-formatting-search-results/
Share on other sites

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 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
[/code]
<bump>

okay again, here's my current code:

[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
[/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.
okay nevermind i figured it out on my own. in case anybody is interested (doubtful), here's the solution:

[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'];
      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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.