Crafting Unique and Customizeable Websites is my Passion

Crafting Unique and Customizeable Websites is my Passion

hero frame
Display Results – HTML Output | Pharmacie Addresses and Best Prices

We now got the search results in XML format and we want to display them on our site, which means we must translate them to HTML. we will do this in three steps. First we cleanup the response in order to avoid translation errors. second we translate to JSON and then to an PHP array. We are now able to loop trough the array and display the results from the Drug Discount Network in HTML.

  if($err_response !== $response):
  // Make a clean array out of the soap response
  $cleanResponse = str_ireplace(['SOAP-ENV:', 'ns1:'], "", $response);
  $xmlPharma = simplexml_load_string($cleanResponse);
  $arr = json_decode( json_encode($xmlPharma), true);
  $pharmacies = $arr['Body']['pharmacies_searchResponse']['return']['item'];

  //Loop trough array and display in HTML
  $i = 0;
  $pharma_len = count($pharmacies) - 1;
  ?>
    <div id="search__results" class="container">
      <div class="row">
        <div class="col-md-4">
            <div id="mapid" style="min-height:100%;"></div>
        </div>
        <div class="col-md-8">
          <div class="row">
      <?php
        while($i <= 5 && $i <= $pharma_len):

        $pharmacy = $pharmacies[$i];

        ?>
            <div class="col-sm-6">
              <div style="border: 1px solid #acacac;
                          border-radius:<?php echo $custom_search_results_border_radius;?>px;
                          min-height:234px;
                          position:relative;"  
                   class="mb-2 mb-sm-2 mb-md-3 mb-lg-4"
              >

              <?php
              if($i === 0  && !empty($pharmacy['price'])):
              ?>
                <div id="best-price"
                     style="position:absolute;
                            right:-25px;
                            top:-35px;"
                     class>
                  <img src="<?php echo $custom_search_results_best_price_image_url;?>" 
                       class="img-fluid mobile-icon" 
                       alt="<?php echo $custom_search_results_best_price_image_alt;?>">
                </div>
              <?php
              endif;
              ?>
                <div class="p-1 p-sm-1 p-md-2 p-lg-2" 
                     style="background:<?php echo $custom_search_results_pane_background;?>;                                                        
                            border-radius:<?php echo $custom_search_results_border_radius;?>px <?php echo $custom_search_results_border_radius;?>px 0px 0px;
                            min-height:72px;" 
                >
                  <h5  style="font-weight:900;
                              color:<?php echo $custom_search_results_pane_text_price_color;?>;">
                    <?php echo $pharmacy["pharmacy_name"]?>
                  </h5>
                </div>
                  <address class="text-center pharma__address">
                    <span style="color:<?php echo $custom_search_results_address_tel_text_color;?>;
                                 font-weight:900;
                                 "
                    >
                      <?php echo $pharmacy["pharmacy_address"]?>
                    </span>
                  </address>
                  <p class="text-center" 
                     style="font-size:40px;
                           font-weight:900;
                           color:<?php echo $custom_search_results_pane_text_price_color;?>;
                  ">
                    <?php echo (empty($pharmacy["price"])) ? "<span style='font-size:25px;'>Price unavailable</span>" : "$ " . $pharmacy["price"]?>
                  </p>
                  <p class="text-center px-3" style="font-size:12px;">
                    <a 
                      href="tel:<?php echo $pharmacy["pharmacy_phone_number"]?>"
                      class="pharma__phone text-center"
                      style="color:<?php echo $custom_search_results_address_tel_text_color;?>;
                             font-weight:900;
                             font-size:15px;
                            "
                    >
                      Tel. <?php echo $pharmacy["pharmacy_phone_number"]?>
                    </a>
                  </p>
              </div>              
            </div>
      <?php        
        $i++;
        endwhile;
      ?>

      <?php
      
      /* === Hero Buttons === */
      $custom_hero_buttons                    = get_field('custom_hero_buttons');
      $hero_card_button_text                  = $custom_hero_buttons["hero_card_button_text"];
      $hero_card_button_text_color            = $custom_hero_buttons["hero_card_button_text_color"];
      $hero_card_button_color                 = $custom_hero_buttons["hero_card_button_color"];
      $hero_card_button_link                  = $custom_hero_buttons["hero_card_button_link"];
      $hero_card_button_border_color          = $custom_hero_buttons["hero_card_button_border_color"];
      $hero_buttons_rounded_corner            = $custom_hero_buttons["hero_buttons_rounded_corner"];

      /* === Hero Buttons === */
      $custom_hero_buttons                    = get_field('custom_hero_buttons');
      ?>

          </div>      
        </div>
      </div>
    </div>
      <div class="container d-none d-sm-none d-md-block d-lg-block">
      <?php if($pharma_len > 5):?>
        <div class="row my-2 my-sm-3 my-md-3 my-lg-5">
        <a href="<?php echo $hero_card_button_link;?>" 
                            class="primary-btn mx-auto get__card mx-2" 
                            style="background:<?php echo $hero_card_button_color;?>; 
                                  border-radius:<?php echo $hero_buttons_rounded_corner?>px;
                                  font-size:30px;
                                  border:4px solid <?php echo $hero_card_button_border_color?>;
                                  color: <?php echo $hero_card_button_text_color?>;"
                        >
                            <?php echo $hero_card_button_text;?>
                        </a>
        </div>
      <?php endif;?>
    
        <div class="row pt-2 pt-sm-2 pt-md-3 pt-lg-4">
    <?php
    if($pharma_len > 5):

    while($i > 5 && $i <= $pharma_len):
    $pharmacy = $pharmacies[$i];
    ?>
        <div class="col-md-4">
        <div style="border: 1px solid #acacac;
                          border-radius:<?php echo $custom_search_results_border_radius;?>px;
                          min-height:234px;" 
                   class="mb-2 mb-sm-2 mb-md-3 mb-lg-4"
              >
                <div class="p-1 p-sm-1 p-md-2 p-lg-2" 
                     style="background:<?php echo $custom_search_results_pane_background;?>;                           
                            border-radius:<?php echo $custom_search_results_border_radius;?>px <?php echo $custom_search_results_border_radius;?>px 0px 0px;
                            min-height:72px;"
                >
                  <h5  style="font-weight:900;
                              color:<?php echo $custom_search_results_pane_text_price_color;?>;">
                    <?php echo $pharmacy["pharmacy_name"]?>
                  </h5>
                </div>
                  <address class="text-center pharma__address">
                    <span style="color:<?php echo $custom_search_results_address_tel_text_color;?>;
                                 font-weight:900;"
                    >
                      <?php echo $pharmacy["pharmacy_address"]?>
                    </span>
                  </address>
                  <p class="text-center" 
                     style="font-size:40px;
                           font-weight:900;
                           color:<?php echo $custom_search_results_pane_text_price_color;?>;
                  ">
                    <?php echo (empty($pharmacy["price"])) ? "<span style='font-size:25px;'>Price unavailable</span>" : "$ " . $pharmacy["price"]?>
                  </p>
                  <p class="text-center px-3" style="font-size:12px;">
                    <a 
                      href="tel:<?php echo $pharmacy["pharmacy_phone_number"]?>"
                      class="pharma__phone text-center"
                      style="color:<?php echo $custom_search_results_address_tel_text_color;?>;
                             font-weight:900;
                             font-size:15px;"
                    >
                      Tel. <?php echo $pharmacy["pharmacy_phone_number"]?>
                    </a>
                  </p>
              </div>          
        </div>
    <?php
    $i++;

    endwhile;

  endif;
    ?>
Drug Discount Network Search Results
Figure 3.1: Drug Discount Network – Search Results

be the first to share shared this post

Leave a Reply

Your email address will not be published. Required fields are marked *

top frame
freebie picture
STAY TUNED &
SUBSCRIBE

Sign up to my mailing list and receive occasional updates, new bogposts, freebies, giveaways and more



    Terms of privacy and data protection



    Get in Touch

    Feel free to send me a message. I'll gladly respond to all your requests.