22 Replies Latest reply: May 8, 2012 4:48 AM by Jonathan Fortis RSS

    displaying and echo in the body

    Jonathan Fortis Community Member

      i have the echo no results being displayed but when its run  it currently displays at the top of the page

       

      if(count($results) > 0){

               echo implode($results);

           }

           else {

               echo "No results were found.";

           }

       

       

      how do i show the No results were found. in the contents

       

       

      thanks in advance

        • 1. Re: displaying and echo in the body
          sudarshan.t CommunityMVP

          Try this. Be sure to post the code where you want the result to be displayed

           

          $noresults = "No results were found!";

          if(count($results) > 0){

                   echo implode($results);

               }

               else {

                   echo "<p>$noresults</p>";

               }

           

           

          • 2. Re: displaying and echo in the body
            sudarshan.t CommunityMVP

            This is because currently, I guess you're echoeing from within the PHP function code that you have all the way in the beginning of your code. This considers that the echo is a part of the function - hence it displays at the top of the page

            • 3. Re: displaying and echo in the body
              Jonathan Fortis Community Member

              ok great....see what you done and it works thanks for your help

              • 4. Re: displaying and echo in the body
                sudarshan.t CommunityMVP

                You're welcome

                • 5. Re: displaying and echo in the body
                  Jonathan Fortis Community Member

                  i still have a problem with the

                   

                          <?php

                          $noresults = "No results were found!";

                  if(count($results) > 0){

                           echo implode($results);

                       }

                       else {

                           echo "<p>$noresults</p>";

                       }

                  ?>

                   

                  it is showing even if there are results. i think i have to put it somewhere else in the code?

                  • 6. Re: displaying and echo in the body
                    sudarshan.t CommunityMVP

                    Are you using an if else condition? If you don't PHP will display this even if there are results found.

                    • 7. Re: displaying and echo in the body
                      Jonathan Fortis Community Member

                      no im not but was unsure where this went

                       

                      this is the header content

                       

                      <?php

                      if (!function_exists("GetSQLValueString")) {

                      function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

                      {

                        if (PHP_VERSION < 6) {

                          $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

                        }

                       

                       

                        $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

                       

                       

                        switch ($theType) {

                          case "text":

                            $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

                            break;   

                          case "long":

                          case "int":

                            $theValue = ($theValue != "") ? intval($theValue) : "NULL";

                            break;

                          case "double":

                            $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

                            break;

                          case "date":

                            $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

                            break;

                          case "defined":

                            $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

                            break;

                        }

                        return $theValue;

                      }

                      }

                       

                       

                      $currentPage = $_SERVER["PHP_SELF"];

                       

                       

                      $maxRows_Recordset1 = 5;

                      $pageNum_Recordset1 = 0;

                      if (isset($_GET['pageNum_Recordset1'])) {

                        $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];

                      }

                      $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

                       

                       

                      $var_SalaryReq_Recordset1 = "xxxxx";

                      if (isset($_GET['SalaryReq'])) {

                        $var_SalaryReq_Recordset1 = $_GET['SalaryReq'];

                      }

                      $var_skills_offered_Recordset1 = "xxxxx";

                      if (isset($_GET['skills_offered'])) {

                        $var_skills_offered_Recordset1 = $_GET['skills_offered'];

                      }

                      $var_location_Recordset1 = "xxxxx";

                      if (isset($_GET['location'])) {

                        $var_location_Recordset1 = $_GET['location'];

                      }

                      $var_PositionReq_Recordset1 = "xxxxx";

                      if (isset($_GET['PositionReq'])) {

                        $var_PositionReq_Recordset1 = $_GET['PositionReq'];

                      }

                      mysql_select_db($database_hostprop, $hostprop);

                      $query_Recordset1 = sprintf("SELECT ID, userid, FirstName, Surname, SalaryReq, PositionReq, location, otherComments, skills_offered FROM think_signup WHERE SalaryReq LIKE %s OR PositionReq LIKE %s OR location LIKE %s OR skills_offered LIKE %s", GetSQLValueString("%" . $var_SalaryReq_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_PositionReq_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_location_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_skills_offered_Recordset1 . "%", "text"));

                      $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);

                      $Recordset1 = mysql_query($query_limit_Recordset1, $hostprop) or die(mysql_error());

                      $row_Recordset1 = mysql_fetch_assoc($Recordset1);

                       

                       

                      if (isset($_GET['totalRows_Recordset1'])) {

                        $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];

                      } else {

                        $all_Recordset1 = mysql_query($query_Recordset1);

                        $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);

                      }

                      $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

                       

                       

                      $queryString_Recordset1 = "";

                      if (!empty($_SERVER['QUERY_STRING'])) {

                        $params = explode("&", $_SERVER['QUERY_STRING']);

                        $newParams = array();

                        foreach ($params as $param) {

                          if (stristr($param, "pageNum_Recordset1") == false &&

                              stristr($param, "totalRows_Recordset1") == false) {

                            array_push($newParams, $param);

                          }

                        }

                        if (count($newParams) != 0) {

                          $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));

                        }

                      }

                      $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);

                      ?>

                       

                       

                      and this site in the body

                       

                      <?php

                              $noresults = "No results were found!";

                      if(count($results) > 0){

                               echo implode($results);

                           }

                           else {

                               echo "<p>$noresults</p>";

                           }

                      ?>

                      • 8. Re: displaying and echo in the body
                        sudarshan.t CommunityMVP

                        Post your full code so I'll know the location of your noresults code.

                        • 9. Re: displaying and echo in the body
                          Jonathan Fortis Community Member

                          <?php

                          if (!function_exists("GetSQLValueString")) {

                          function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

                          {

                            if (PHP_VERSION < 6) {

                              $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

                            }

                           

                           

                            $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

                           

                           

                            switch ($theType) {

                              case "text":

                                $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

                                break;   

                              case "long":

                              case "int":

                                $theValue = ($theValue != "") ? intval($theValue) : "NULL";

                                break;

                              case "double":

                                $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

                                break;

                              case "date":

                                $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

                                break;

                              case "defined":

                                $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

                                break;

                            }

                            return $theValue;

                          }

                          }if (!function_exists("GetSQLValueString")) {

                          function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

                          {

                            if (PHP_VERSION < 6) {

                              $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

                            }

                           

                           

                            $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

                           

                           

                            switch ($theType) {

                              case "text":

                                $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

                                break;   

                              case "long":

                              case "int":

                                $theValue = ($theValue != "") ? intval($theValue) : "NULL";

                                break;

                              case "double":

                                $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

                                break;

                              case "date":

                                $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

                                break;

                              case "defined":

                                $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

                                break;

                            }

                            return $theValue;

                          }

                          }

                          ?>

                          <?php

                          // *** Validate request to login to this site.

                          if (!isset($_SESSION)) {

                            session_start();

                          }

                           

                           

                          $loginFormAction = $_SERVER['PHP_SELF'];

                          if (isset($_GET['accesscheck'])) {

                            $_SESSION['PrevUrl'] = $_GET['accesscheck'];

                          }

                           

                           

                          if (isset($_POST['userid'])) {

                            $loginUsername=$_POST['userid'];

                            $password=$_POST['password'];

                            $MM_fldUserAuthorization = "";

                            $MM_redirectLoginSuccess = "signup/signup-complete.php";

                            $MM_redirectLoginFailed = "failed.php";

                            $MM_redirecttoReferrer = false;

                            mysql_select_db($database_hostprop, $hostprop);

                           

                            $LoginRS__query=sprintf("SELECT userid, password FROM think_signup WHERE userid=%s AND password=%s",

                              GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));

                            

                            $LoginRS = mysql_query($LoginRS__query, $hostprop) or die(mysql_error());

                            $loginFoundUser = mysql_num_rows($LoginRS);

                            if ($loginFoundUser) {

                               $loginStrGroup = "";

                             

                                    if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}

                              //declare two session variables and assign them

                              $_SESSION['MM_Username'] = $loginUsername;

                              $_SESSION['MM_UserGroup'] = $loginStrGroup;               

                           

                           

                              if (isset($_SESSION['PrevUrl']) && false) {

                                $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];

                              }

                              header("Location: " . $MM_redirectLoginSuccess );

                            }

                            else {

                              header("Location: ". $MM_redirectLoginFailed );

                            }

                          }

                          ?>

                          <?php

                          if (!function_exists("GetSQLValueString")) {

                          function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

                          {

                            if (PHP_VERSION < 6) {

                              $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

                            }

                           

                           

                            $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

                           

                           

                            switch ($theType) {

                              case "text":

                                $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

                                break;   

                              case "long":

                              case "int":

                                $theValue = ($theValue != "") ? intval($theValue) : "NULL";

                                break;

                              case "double":

                                $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

                                break;

                              case "date":

                                $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

                                break;

                              case "defined":

                                $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

                                break;

                            }

                            return $theValue;

                          }

                          }

                           

                           

                          $currentPage = $_SERVER["PHP_SELF"];

                           

                           

                          $maxRows_Recordset1 = 5;

                          $pageNum_Recordset1 = 0;

                          if (isset($_GET['pageNum_Recordset1'])) {

                            $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];

                          }

                          $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

                           

                           

                          $var_SalaryReq_Recordset1 = "xxxxx";

                          if (isset($_GET['SalaryReq'])) {

                            $var_SalaryReq_Recordset1 = $_GET['SalaryReq'];

                          }

                          $var_skills_offered_Recordset1 = "xxxxx";

                          if (isset($_GET['skills_offered'])) {

                            $var_skills_offered_Recordset1 = $_GET['skills_offered'];

                          }

                          $var_location_Recordset1 = "xxxxx";

                          if (isset($_GET['location'])) {

                            $var_location_Recordset1 = $_GET['location'];

                          }

                          $var_PositionReq_Recordset1 = "xxxxx";

                          if (isset($_GET['PositionReq'])) {

                            $var_PositionReq_Recordset1 = $_GET['PositionReq'];

                          }

                          mysql_select_db($database_hostprop, $hostprop);

                          $query_Recordset1 = sprintf("SELECT ID, userid, FirstName, Surname, SalaryReq, PositionReq, location, otherComments, skills_offered FROM think_signup WHERE SalaryReq LIKE %s OR PositionReq LIKE %s OR location LIKE %s OR skills_offered LIKE %s", GetSQLValueString("%" . $var_SalaryReq_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_PositionReq_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_location_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_skills_offered_Recordset1 . "%", "text"));

                          $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);

                          $Recordset1 = mysql_query($query_limit_Recordset1, $hostprop) or die(mysql_error());

                          $row_Recordset1 = mysql_fetch_assoc($Recordset1);

                           

                           

                          if (isset($_GET['totalRows_Recordset1'])) {

                            $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];

                          } else {

                            $all_Recordset1 = mysql_query($query_Recordset1);

                            $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);

                          }

                          $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

                           

                           

                          $queryString_Recordset1 = "";

                          if (!empty($_SERVER['QUERY_STRING'])) {

                            $params = explode("&", $_SERVER['QUERY_STRING']);

                            $newParams = array();

                            foreach ($params as $param) {

                              if (stristr($param, "pageNum_Recordset1") == false &&

                                  stristr($param, "totalRows_Recordset1") == false) {

                                array_push($newParams, $param);

                              }

                            }

                            if (count($newParams) != 0) {

                              $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));

                            }

                          }

                          $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);

                          ?>

                           

                           

                          BODY HERE

                           

                          <div id="CandidateSearchResCont">

                                  <?php

                                  $noresults = "No results were found!";

                          if(count($results) > 0){

                                   echo implode($results);

                               }

                               else {

                                   echo "<p>$noresults</p>";

                               }

                          ?>

                                    <?php do { ?>

                                      <table width="655" border="0" cellspacing="5" cellpadding="0">

                                        <tr>

                                          <td colspan="2" class="Titlegreen"><table width="100%" border="0" cellspacing="0" cellpadding="0">

                                            <tr>

                                              <td align="left"><a href="candidate-information.php?ID=<?php echo $row_Recordset1['ID']; ?>" class="joblinks"><?php echo $row_Recordset1['PositionReq']; ?></a></td>

                                              <td> </td>

                                              <td align="right"><?php echo $row_Recordset1['skills_offered']; ?></td>

                                              </tr>

                                        </table></td>

                                        </tr>

                                        <tr>

                                          <td colspan="2" class="textblack"><?php echo $row_Recordset1['otherComments']; ?></td>

                                        </tr>

                                        <tr>

                                          <td width="250"><a href="candidate-information.php?ID=<?php echo $row_Recordset1['ID']; ?>" class="smallTXTlinksBlack">more info</a></td>

                                          <td width="405"><div align="right"><span class="pos_salary"></span><span class="pos_location"> <?php echo $row_Recordset1['SalaryReq']; ?>/<?php echo $row_Recordset1['location']; ?></span></div></td>

                                        </tr>

                                      </table>

                                      <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>

                                    <p> 

                                    <table border="0">

                                      <tr>

                                        <td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>

                                            <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>" class="smallTXTlinksBlack">First</a>

                                            <?php } // Show if not first page ?></td>

                                        <td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>

                                            <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>" class="smallTXTlinksBlack">Previous</a>

                                            <?php } // Show if not first page ?></td>

                                        <td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>

                                            <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>" class="smallTXTlinksBlack">Next</a>

                                            <?php } // Show if not last page ?></td>

                                        <td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>

                                            <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>" class="smallTXTlinksBlack">Last</a>

                                            <?php } // Show if not last page ?></td>

                                      </tr>

                                    </table>

                                    </p>

                                  </div>

                          • 10. Re: displaying and echo in the body
                            sudarshan.t CommunityMVP

                            I see you haven't defined the variable $results anywhere else in your code. The following PHP function tells the system to count your variable results and if the count is more than 0 in our case, it implodes the results into your table. If the count is not more than 0, then it echos the variable noresults which says 'No results were found'.

                            <?php

                                    $noresults = "No results were found!";

                            if(count($results) > 0){

                                     echo implode($results);

                                 }

                                 else {

                                     echo "<p>$noresults</p>";

                                 }

                            ?>

                             

                            In your case, since you haven't defined the results variable, the PHP script just echos the noresults variable as it doesn't find the results variable anywhere in your code.

                            • 11. Re: displaying and echo in the body
                              Jonathan Fortis Community Member

                              so i presume i need to add

                               

                              if(count($results) > 0){

                                       echo implode($results);

                                   }

                                   else {

                                       echo "No results were found.";

                                   }

                               

                              in the php code at the top of the page? but wheree

                              • 12. Re: displaying and echo in the body
                                sudarshan.t CommunityMVP

                                You have to define $results as a variable before you add this code anywhere on your page. You should tell the system what value it should assume as $results.

                                • 13. Re: displaying and echo in the body
                                  Jonathan Fortis Community Member

                                  would i have to add something like

                                   

                                  $results = "No results were found!"

                                  • 14. Re: displaying and echo in the body
                                    Jonathan Fortis Community Member

                                    no i tried that and it come back with error

                                     

                                     

                                    i am unsure what i need to put in there as this was not correct

                                     

                                    i know i havee to insert $results =

                                     

                                    but dont know what needs to come after this

                                    • 15. Re: displaying and echo in the body
                                      Jonathan Fortis Community Member

                                      i have looked at many variations and they all seem simple but i dont know where to put the code

                                       

                                      i obviously need to add the varialble to the sql in the top of the page and the echo in the body

                                       

                                      <?php

                                              $noresults = "No results were found!";

                                      if(count($results) > 0){

                                               echo implode($results);

                                           }

                                           else {

                                               echo "<p>$noresults</p>";

                                           }

                                      ?>

                                       

                                      but what goes where i am unsure of...i have tried variations but non work

                                       

                                      any help would be very gratful

                                       

                                      thanks

                                      • 16. Re: displaying and echo in the body
                                        Jonathan Fortis Community Member

                                        i have just tried this in the php at the head of the document

                                         

                                        mysql_select_db($database_hostprop, $hostprop);

                                        $query_Recordset1 = sprintf("SELECT ID, userid, FirstName, Surname, SalaryReq, PositionReq, location, otherComments, skills_offered FROM think_signup WHERE SalaryReq LIKE %s OR PositionReq LIKE %s OR location LIKE %s OR skills_offered LIKE %s", GetSQLValueString("%" . $var_SalaryReq_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_PositionReq_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_location_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_skills_offered_Recordset1 . "%", "text"));

                                        $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);

                                        $Recordset1 = mysql_query($query_limit_Recordset1, $hostprop) or die(mysql_error());

                                        $row_Recordset1 = mysql_fetch_assoc($Recordset1);

                                         

                                         

                                        if(count($results) > 0){

                                                 echo implode($results);

                                             }

                                             else {

                                                 echo "<p>$noresults</p>";

                                             }

                                        if (isset($_GET['totalRows_Recordset1'])) {

                                          $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];

                                        } else {

                                          $all_Recordset1 = mysql_query($query_Recordset1);

                                          $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);

                                        }

                                        $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

                                         

                                         

                                        $queryString_Recordset1 = "";

                                        if (!empty($_SERVER['QUERY_STRING'])) {

                                          $params = explode("&", $_SERVER['QUERY_STRING']);

                                          $newParams = array();

                                          foreach ($params as $param) {

                                            if (stristr($param, "pageNum_Recordset1") == false &&

                                                stristr($param, "totalRows_Recordset1") == false) {

                                              array_push($newParams, $param);

                                            }

                                          }

                                          if (count($newParams) != 0) {

                                            $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));

                                          }

                                        }

                                        $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);

                                         

                                         

                                        ?>

                                         

                                        and this in the body

                                        <?php $noresults = "No results were found!";?>

                                         

                                        but this didnt work

                                        • 17. Re: displaying and echo in the body
                                          sudarshan.t CommunityMVP

                                          Sorry for the M.I.A. Personal emergency.

                                           

                                          results should be a variable before you can use that variable to manipulate data strings.

                                           

                                          For example,

                                           

                                          <?php
                                          $a
                                          [0] = 1;
                                          $a[1] = 3;
                                          $a[2] = 5;
                                          $result = count($a);
                                          // $result == 3
                                          ?>

                                           

                                          In this $result is defined as a total count of all $a values. This is static PHP. However, in your case, you should define $result to be the value of the actual results of your search query. For example, if you want to validate if your total rows returned from your sql query to be the markup for your PHP function, your code will be as follows:

                                           

                                          $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);

                                          $result = $totalRows_Recordset1

                                          In this, we define the totalRows in Recordset1 as the total number of all rows in Recordset1. We then use that value as the $result. If you run a count function here, you could say if count is >, return a message saying there are rows present in the table. Else, echo that there are no rows.

                                           

                                          Trust this helps.

                                          • 18. Re: displaying and echo in the body
                                            Jonathan Fortis Community Member

                                            i thiank you so much for you r help, i understand the concept of

                                             

                                            <?php
                                            $a
                                            [0] = 1;
                                            $a[1] = 3;
                                            $a[2] = 5;
                                            $result = count($a);
                                            // $result == 3
                                            ?>

                                             

                                            and

                                            $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);

                                            $result = $totalRows_Recordset1

                                             

                                            but i have added this code to my code and it doesnt work, I think i am placing it in the wrong area of the code

                                             

                                            i tried adding an else statement..thinking it will read this then move onto the next this but i am getting errors in the code

                                             

                                            mysql_select_db($database_hostprop, $hostprop);

                                            $query_Recordset1 = sprintf("SELECT ID, userid, FirstName, Surname, SalaryReq, PositionReq, location, otherComments, skills_offered FROM think_signup WHERE SalaryReq LIKE %s OR PositionReq LIKE %s OR location LIKE %s OR skills_offered LIKE %s", GetSQLValueString("%" . $var_SalaryReq_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_PositionReq_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_location_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_skills_offered_Recordset1 . "%", "text"));

                                            $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);

                                            $Recordset1 = mysql_query($query_limit_Recordset1, $hostprop) or die(mysql_error());

                                            $row_Recordset1 = mysql_fetch_assoc($Recordset1);

                                             

                                             

                                            if

                                            $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);

                                            $result = $totalRows_Recordset1;

                                            else

                                             

                                             

                                            if (isset($_GET['totalRows_Recordset1'])) {

                                              $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];

                                            } else {

                                              $all_Recordset1 = mysql_query($query_Recordset1);

                                              $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);

                                            }

                                            $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

                                             

                                             

                                            $queryString_Recordset1 = "";

                                            if (!empty($_SERVER['QUERY_STRING'])) {

                                              $params = explode("&", $_SERVER['QUERY_STRING']);

                                              $newParams = array();

                                              foreach ($params as $param) {

                                                if (stristr($param, "pageNum_Recordset1") == false &&

                                                    stristr($param, "totalRows_Recordset1") == false) {

                                                  array_push($newParams, $param);

                                                }

                                              }

                                              if (count($newParams) != 0) {

                                                $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));

                                              }

                                            }

                                            $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);

                                             

                                             

                                             

                                             

                                            ?>

                                             

                                            in the bosy i have

                                             

                                            <?php

                                                    $noresults = "No results were found!";

                                            if(count($results) > 0){

                                                     echo implode($results);

                                                 }

                                                 else {

                                                     echo "<p>$noresults</p>";

                                                 }

                                            ?>

                                             

                                            so i removed the else and just added what you sent

                                             

                                            mysql_select_db($database_hostprop, $hostprop);

                                            $query_Recordset1 = sprintf("SELECT ID, userid, FirstName, Surname, SalaryReq, PositionReq, location, otherComments, skills_offered FROM think_signup WHERE SalaryReq LIKE %s OR PositionReq LIKE %s OR location LIKE %s OR skills_offered LIKE %s", GetSQLValueString("%" . $var_SalaryReq_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_PositionReq_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_location_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_skills_offered_Recordset1 . "%", "text"));

                                            $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);

                                            $Recordset1 = mysql_query($query_limit_Recordset1, $hostprop) or die(mysql_error());

                                            $row_Recordset1 = mysql_fetch_assoc($Recordset1);

                                             

                                             

                                            $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);

                                            $result = $totalRows_Recordset1;

                                             

                                             

                                            if (isset($_GET['totalRows_Recordset1'])) {

                                              $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];

                                            } else {

                                              $all_Recordset1 = mysql_query($query_Recordset1);

                                              $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);

                                            }

                                            $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

                                             

                                             

                                            $queryString_Recordset1 = "";

                                            if (!empty($_SERVER['QUERY_STRING'])) {

                                              $params = explode("&", $_SERVER['QUERY_STRING']);

                                              $newParams = array();

                                              foreach ($params as $param) {

                                                if (stristr($param, "pageNum_Recordset1") == false &&

                                                    stristr($param, "totalRows_Recordset1") == false) {

                                                  array_push($newParams, $param);

                                                }

                                              }

                                              if (count($newParams) != 0) {

                                                $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));

                                              }

                                            }

                                            $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);

                                             

                                             

                                            ?>

                                             

                                            and even if there are results it is still showing there arent any results?

                                             

                                            thanks again for you time


                                            • 19. Re: displaying and echo in the body
                                              Jonathan Fortis Community Member

                                              Also no problem on the replies i hope your Personal emergency wasnt too serious!

                                               

                                              thanks

                                              • 20. Re: displaying and echo in the body
                                                sudarshan.t CommunityMVP

                                                You have the answer to this in your question itself!

                                                 

                                                Look at how you've configured newParams

                                                 

                                                $queryString_Recordset1 = "";

                                                if (!empty($_SERVER['QUERY_STRING'])) {

                                                  $params = explode("&", $_SERVER['QUERY_STRING']);

                                                  $newParams = array();

                                                  foreach ($params as $param) {

                                                    if (stristr($param, "pageNum_Recordset1") == false &&

                                                        stristr($param, "totalRows_Recordset1") == false) {

                                                      array_push($newParams, $param);

                                                    }

                                                  }

                                                  if (count($newParams) != 0) {

                                                    $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));

                                                  }

                                                }

                                                You're first querying your DB and you've defined $newparams as an array. Then, you're running a validation on it to find out its count.

                                                 

                                                Your $results variable should be configured in a very similar manner.

                                                • 21. Re: displaying and echo in the body
                                                  Jonathan Fortis Community Member

                                                  ok, but this code was genertated by dreamweaver.

                                                  • 22. Re: displaying and echo in the body
                                                    Jonathan Fortis Community Member

                                                    got it sorted thanks you

                                                     

                                                    in the header

                                                     

                                                    mysql_select_db($database_hostprop, $hostprop);

                                                    $query_Recordset1 = sprintf("SELECT ID, userid, FirstName, Surname, SalaryReq, PositionReq, location, otherComments, skills_offered FROM think_signup WHERE SalaryReq LIKE %s OR PositionReq LIKE %s OR location LIKE %s OR skills_offered LIKE %s", GetSQLValueString("%" . $var_SalaryReq_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_PositionReq_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_location_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_skills_offered_Recordset1 . "%", "text"));

                                                    $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);

                                                    $Recordset1 = mysql_query($query_limit_Recordset1, $hostprop) or die(mysql_error());

                                                    $row_Recordset1 = mysql_fetch_assoc($Recordset1);

                                                     

                                                     

                                                    $results = mysql_num_rows($Recordset1);

                                                    $noresults = 'No results found';

                                                     

                                                     

                                                    if (isset($_GET['totalRows_Recordset1'])) {

                                                      $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];

                                                    } else {

                                                      $all_Recordset1 = mysql_query($query_Recordset1);

                                                      $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);

                                                    }

                                                    $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

                                                     

                                                     

                                                    in the body

                                                    <?php

                                                    if($results == 0) {

                                                    echo "<p>$noresults</p>";

                                                    }

                                                    ?>

                                                     

                                                     

                                                    thanks so much for your help