Announcement

Collapse
No announcement yet.

How to alter message in php/html file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to alter message in php/html file

    Hi

    My php "Search" script Results page http://pintotours.net/Search/Search1.php

    has 2 fields to display the query.

    They both display the same thing, but I would like to modify the second to say more than just "There were no search results for %aaaaa%! " For instance, here something like "Please, try the English version of the city name"

    However, whatever I do to the script the message is the same for both areas.

    The 2 mentions of "There were no search results" for this code are here, and I would like to add something else AFTER the query:

    Code:
    $sql = "SELECT Image, Chain, Country, City, Top as '', Medium as '', Low as '' FROM Chains WHERE Country LIKE ? OR City LIKE ?"; // Your query string
    
    $prepare = $mysqli->prepare($sql); // Prepare your query string
    
    $prepare->bind_param('ss', $searchq, $searchq); // Bind the placeholders to your search variables
    // s = string | i = integer | d = double | b = blob
    
    $prepare->execute(); // Execute the prepared statement
    
    $prepare->store_result(); // Store the results for later checking
    
    
    
    // Use num_rows to check if the results return a 0 or 1. 0 meaning false and 1 meaning true
    if($prepare->num_rows) {
    
        $prepare->bind_result($image, $chain, $country, $city, $top, $medium, $low); // Append variables to the columns you specified
    }else
    {
    	$results = false;
    $searchMsg = 'There were no search results for ‘'. $searchq .'’!';
    }
    
    ?>
    Code:
    <!DOCTYPE html>
    <html lang="en-GB">
    <head>
    
    
    </head>
    
    <body>
    
    
    
    
    <div id="wrapper">
      <div id="main">
    
    
    
    <div class="search">
    <p>Enter a city or country name</p>
        <form action="Search1.php" method="POST">
            <input type="text" class="textinput" name="keyword" id="keyword" size="20">
            <input type="submit" value="Search" class="button" >
        </form>
    </div>
    
    <br><br><br><br>
    
     <h2>Search results for &lsquo;<?php echo str_replace('%', '', $searchq); ?>&rsquo;</h2> 
     <div class="text">
        <p>The following chains guarantee the lowest rates on the Internet</p>
    <p> Click on any logo on the left to enter the Hotel Chain's own website </p>
    </div>
    
        <table>
          <tr>
            <th></th>
            <th>Chain</th>
            <th>Country</th>
            <th>City</th>
            <th><img src="Star5a.png" alt=""></th>
            <th><img src="Star4a.png" alt=""></th>
            <th><img src="Star3a.png" alt=""></th>
          </tr>
        <?php
    	if($results)
    	{
    		// Throw them all in a while loop
    		while($prepare->fetch()) {
    
    
    ?>
          <tr>
      
            <td><?php echo ($chain != '') ? '<a href="/request/index.php?id=' . $chain . '" target="_blank">' : '<a href="/">';?><img src="<?php echo $image;?>" alt="" /></a></td>
    <td><?php echo $chain; ?></td>
            <td><?php echo $country; ?></td>
            <td><?php echo $city; ?></td>
            <td><img src="<?php echo($top == 'y') ? "Gre.png" : "Red.png"; ?>" alt=""></td>
            <td><img src="<?php echo($medium == 'y') ? "Gre.png" : "Red.png"; ?>" alt=""></td>
            <td><img src="<?php echo($low == 'y') ? "Gre.png": "Red.png";  ?> " alt=""></td>
          </tr>
    
          <?php
    
        	}//end while
    } else {
    ?>
          <tr>
            <td colspan="7"> There were no search results for &lsquo;<?php echo $searchq; ?>&rsquo;! </td>
          </tr>
          <?php
    }//end else
    ?>
        </table>
    Last edited by qim; 01-11-2016, 01:13 PM.

  • #2
    Looks like you've already got it...?


    change "$searchMsg" to be whatever message you want?

    and call it in the lower section.

    Although you'll need to create the $searchMsg as a more global variable.

    try this code

    Code:
    $searchMsg = "";
    $sql = "SELECT Image, Chain, Country, City, Top as '', Medium as '', Low as '' FROM Chains WHERE Country LIKE ? OR City LIKE ?"; // Your query string
    
    $prepare = $mysqli->prepare($sql); // Prepare your query string
    
    $prepare->bind_param('ss', $searchq, $searchq); // Bind the placeholders to your search variables
    // s = string | i = integer | d = double | b = blob
    
    $prepare->execute(); // Execute the prepared statement
    
    $prepare->store_result(); // Store the results for later checking
    
    
    
    // Use num_rows to check if the results return a 0 or 1. 0 meaning false and 1 meaning true
    if($prepare->num_rows) {
    
        $prepare->bind_result($image, $chain, $country, $city, $top, $medium, $low); // Append variables to the columns you specified
    }else
    {
    	$results = false;
            $searchMsg = 'There were no search results for &lsquo;'. $searchq .'&rsquo;!'; //ADJUST MESSAGE HERE
    }
    
    ?>
    Code:
    <!DOCTYPE html>
    <html lang="en-GB">
    <head>
    
    
    </head>
    
    <body>
    
    
    
    
    <div id="wrapper">
      <div id="main">
    
    
    
    <div class="search">
    <p>Enter a city or country name</p>
        <form action="Search1.php" method="POST">
            <input type="text" class="textinput" name="keyword" id="keyword" size="20">
            <input type="submit" value="Search" class="button" >
        </form>
    </div>
    
    <br><br><br><br>
    
     <h2>Search results for &lsquo;<?php echo str_replace('%', '', $searchq); ?>&rsquo;</h2> 
     <div class="text">
        <p>The following chains guarantee the lowest rates on the Internet</p>
    <p> Click on any logo on the left to enter the Hotel Chain's own website </p>
    </div>
    
        <table>
          <tr>
            <th></th>
            <th>Chain</th>
            <th>Country</th>
            <th>City</th>
            <th><img src="Star5a.png" alt=""></th>
            <th><img src="Star4a.png" alt=""></th>
            <th><img src="Star3a.png" alt=""></th>
          </tr>
        <?php
    	if($results)
    	{
    		// Throw them all in a while loop
    		while($prepare->fetch()) {
    
    
    ?>
          <tr>
      
            <td><?php echo ($chain != '') ? '<a href="/request/index.php?id=' . $chain . '" target="_blank">' : '<a href="/">';?><img src="<?php echo $image;?>" alt="" /></a></td>
    <td><?php echo $chain; ?></td>
            <td><?php echo $country; ?></td>
            <td><?php echo $city; ?></td>
            <td><img src="<?php echo($top == 'y') ? "Gre.png" : "Red.png"; ?>" alt=""></td>
            <td><img src="<?php echo($medium == 'y') ? "Gre.png" : "Red.png"; ?>" alt=""></td>
            <td><img src="<?php echo($low == 'y') ? "Gre.png": "Red.png";  ?> " alt=""></td>
          </tr>
    
          <?php
    
        	}//end while
    } else {
    ?>
          <tr>
            <td colspan="7">
    <?php 
    if (strlen($searchMsg) > 0) { echo $searchMsg; }
    else { echo "There were no search results for &lsquo{$searchq}&rsquo;"; ?>! }
    ?> 
    
             </td>
          </tr>
          <?php
    }//end else
    ?>
        </table>
    Who needs a Signature?

    Comment


    • #3
      Hi sbeynon

      I decided to go one step at a time and changed only to start with this

      Code:
       <td colspan="7"> There were no search results for &lsquo;<?php echo $searchq; ?>&rsquo;! </td>
            </tr>
            <?php
      }//end else
      ?>
          </table>
      to this

      Code:
                 <td colspan="7">
      <?php 
      if (strlen($searchMsg) > 0) { echo $searchMsg; }
      else { echo "There were no search results for &lsquo{$searchq}&rsquo;"; ?>! }
      ?> 
      
               </td>
            </tr>
            <?php
      }//end else
      ?>
          </table>
      and got this error on entering a query:

      Code:
      Parse error: syntax error, unexpected end of file in /home/pintotou/public_html/Search/Search1.php on line 283
      According to Notepad++ the file ends with </html> on line 277...
      Last edited by qim; 01-13-2016, 05:08 AM.

      Comment


      • #4
        Hi qim,

        the solution to your issue is this.


        Code:
                   
        <td colspan="7">
        <?php 
        if (strlen($searchMsg) > 0) { echo $searchMsg; } //START ELSE FOR IF ON NEXT LINE
        else { echo "There were no search results for &lsquo{$searchq}&rsquo;"; ?>! } // END ELSE
        ?> 
        
                 </td>
              </tr>
         </table>
        Who needs a Signature?

        Comment


        • #5
          Hi

          There is a test page here


          http://pintotours.net/Search/TEST.php

          I've tried placing the extra text after both instances of
          There were no search results for &lsquo{$searchq}&rsquo;
          but it doesn'tcome up

          Could you tell me where to +put the extra text after the
          &lsquo{$searchq}&rsquo;
          so that it only shows if there is no result?

          For instance I tried putting "Please, make sure you use the English version of the City name"" in front, on the following line, but it does not show at all!

          $results = false;
          $searchMsg = 'There were no search results for &lsquo;'. $searchq .'&rsquo; Please, make sure you use the English version of the City name!';
          }
          Thanks
          Last edited by qim; 01-13-2016, 10:54 AM.

          Comment


          • #6
            When i go onto the test page i just get a PHP error


            Code:
            Parse error: syntax error, unexpected 'this' (T_STRING), expecting '{' in /home/pintotou/public_html/Search/TEST.php on line 83
            This means you have an extra '}' somewhere on the page, did you remove the

            Code:
            <?php
            }//end else
            ?>
            from
            Code:
                     </td>
                  </tr>
                  <?php
            }//end else
            ?>
            Who needs a Signature?

            Comment


            • #7
              Hi

              Since your last post with the code you gave me the parse error has disappeared (and a new one appeared with all my messing about..).

              What I have now is

              <?php
              if($results)
              {
              // Throw them all in a while loop
              while($prepare->fetch()) {


              ?>
              <tr>

              <td><?php echo ($chain != '') ? '<a href="/request/index.php?id=' . $chain . '" target="_blank">' : '<a href="/">';?><img src="<?php echo $image;?>" alt="" /></a></td>
              <td><?php echo $chain; ?></td>
              <td><?php echo $country; ?></td>
              <td><?php echo $city; ?></td>
              <td><img src="<?php echo($top == 'y') ? "Gre.png" : "Red.png"; ?>" alt=""></td>
              <td><img src="<?php echo($medium == 'y') ? "Gre.png" : "Red.png"; ?>" alt=""></td>
              <td><img src="<?php echo($low == 'y') ? "Gre.png": "Red.png"; ?> " alt=""></td>
              </tr>

              <?php

              }//end while
              } else {
              ?>
              <tr>
              <td colspan="7">
              <?php
              if (strlen($searchMsg) > 0) { echo $searchMsg; } //START ELSE FOR IF ON NEXT LINE
              else { echo "There were no search results for &lsquo{$searchq}&rsquo;"; ?>! } // END ELSE
              ?>

              </td>
              </tr>
              </table>

              Try it in the test page I gave you above
              Last edited by qim; 01-13-2016, 01:26 PM.

              Comment


              • #8
                Morning qim!


                this line
                Code:
                if (strlen($searchMsg) > 0) { echo $searchMsg; } //START ELSE FOR IF ON NEXT LINE
                else { echo "There were no search results for &lsquo{$searchq}&rsquo;"; ?>! } // END ELSE
                should be

                Code:
                if (strlen($searchMsg) > 0) { echo $searchMsg; } //START ELSE FOR IF ON NEXT LINE
                else { echo "There were no search results for &lsquo;{$searchq}&rsquo;!"; } ?> // END ELSE
                The '}' being left outside the php part meant that the PHP parser was finding an open ELSE statement that never closes (Big no-no )
                Who needs a Signature?

                Comment


                • #9
                  Hi sbeynon

                  still not working...
                  Parse error: syntax error, unexpected end of file in /home/pintotou/public_html/Search/TEST.php on line 276
                  line 276 is way beyond the end of the file </html>

                  http://pintotours.net/Search/TEST.php

                  Sorry!

                  EDIT

                  There seems to be a duplicate ?> in this code. I took it out but it made no difference, so I put it back in for you to see

                  <td><img src="<?php echo($low == 'y') ? "Gre.png": "Red.png"; ?> " alt=""></td>
                  </tr>


                  <tr>
                  <td colspan="7">
                  <?php
                  if (strlen($searchMsg) > 0) { echo $searchMsg; } //START ELSE FOR IF ON NEXT LINE
                  else { echo "There were no search results for &lsquo;{$searchq}&rsquo;!"; } ?> // END ELSE
                  ?>

                  </td>
                  </tr>
                  </table>
                  Last edited by qim; 01-14-2016, 06:25 AM.

                  Comment


                  • #10
                    yeah, the line numbers can be a bit whacky sometimes....


                    this is the correct code when removing that error.
                    Code:
                    <td><img src="<?php echo($low == 'y') ? "Gre.png": "Red.png"; ?> " alt=""></td>
                    </tr>
                    
                    
                    <tr>
                    <td colspan="7">
                    <?php
                    if (strlen($searchMsg) > 0) { echo $searchMsg; } //START ELSE FOR IF ON NEXT LINE
                    else { echo "There were no search results for &lsquo;{$searchq}&rsquo;!"; } ?> // END ELSE
                    
                    </td>
                    </tr>
                    </table>
                    Who needs a Signature?

                    Comment


                    • #11
                      Sorry....

                      still no good


                      Parse error: syntax error, unexpected end of file in /home/pintotou/public_html/Search/TEST.php on line 274
                      Last edited by qim; 01-14-2016, 08:41 AM.

                      Comment


                      • #12
                        Can you provide me with the whole pages code?
                        Probably best to zip it up and attach it to the post as opposed to copy and paste it in if it's long.
                        Who needs a Signature?

                        Comment


                        • #13
                          ...................
                          Last edited by qim; 01-15-2016, 07:05 AM.

                          Comment

                          Working...
                          X