Results 1 to 3 of 3

Thread: orphange php help

  1. #1
    Join Date
    Jun 2006
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default orphange php help

    I have the below code, and am very close on getting it to work. It shows the children’s names, and any other information I ask it for, but I can not get the next button to work. Any thoughts? I am sure that I am just missing something, this is a script I found on line, that is suppose to perform a search and provide next and prev buttons. The search is working.
    PHP Code:
    <html>
    <head>
    </head>

    <body>

    <form name="form" action="searchscript.php" method="get">
      <input type="text" name="q" />
      <input type="submit" name="Submit" value="Search" />
    </form>

    <?php

      
    // Get the search variable from URL

      
    $var = @$_GET['q'] ;
      
    $trimmed trim($var); //trim whitespace from the stored variable

    // rows to return
    $limit=1

    // check for an empty string and display a message.
    if ($trimmed == "")
      {
      echo 
    "<p>Please enter a search...</p>";
      exit;
      }

    // check for a search parameter
    if (!isset($var))
      {
      echo 
    "<p>We dont seem to have a search parameter!</p>";
      exit;
      }

    //connect to your database ** EDIT REQUIRED HERE **
    mysql_connect("xxx","yyy","zzz"); //(host, username, password)

    //specify database ** EDIT REQUIRED HERE **
    mysql_select_db("ddd") or die("Unable to select database"); //select which database we're using

    // Build SQL Query  
    $query "SELECT * FROM sponsor WHERE checkSponsorChild LIKE \"%$trimmed%\" ORDER BY id ";  // EDIT HERE and specify your table and field names for the SQL query
     

     
    $numresults=mysql_query($query);
     
    $numrows=mysql_num_rows($numresults);

    // If we have no results, offer a google search as an alternative

    if ($numrows == 0)
      {
      echo 
    "<h4>Results</h4>";
      echo 
    "<p>Sorry, your search: &quot;" $trimmed "&quot; returned zero results</p>";

    // google
     
    echo "<p><a href=\"http://www.google.com/search?q=" 
      
    $trimmed "\" target=\"_blank\" title=\"Look up 
      " 
    $trimmed " on Google\">Click here</a> to try the 
      search on google</p>"
    ;
      }

    // next determine if s has been passed to script, if not use 0
      
    if (empty($s)) {
      
    $s=0;
      }

    // get results
      
    $query .= " limit $s,$limit";
      
    $result mysql_query($query) or die("Couldn't execute query");

    // display what the person searched for
    echo "<p>You searched for: &quot;" $var "&quot;</p>";

    // begin to show results set
    echo "Results";
    $count $s ;
    $childrenInfo['childsName'] ."\r\n";
    // now you can display the results returned
      
    while ($childrenInfomysql_fetch_array($result)) {
      
    $title $childrenInfo['childsName'];

      echo 
    "$count.)&nbsp;$title;
      
    $count++ ;
      }

    $currPage = (($s/$limit) + 1);

    //break before paging
      
    echo "<br />";

      
    // next we need to do the links to other results
      
    if ($s>=1) { // bypass PREV link if s is 0
      
    $prevs=($s-$limit);
      print 
    "&nbsp;<a href=\"$PHP_SELF?s=$prevs&q=$var\"></a>&nbsp&nbsp;";
      }

    // calculate number of pages needing links
      
    $pages=intval($numrows/$limit);

    // $pages now contains int of pages needed unless there is a remainder from division

      
    if ($numrows%$limit) {
      
    // has remainder so add one page
      
    $pages++;
      }

    // check to see if last page
      
    if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

      
    // not last page so give NEXT link
      
    $news=$s+$limit;

      echo 
    "&nbsp;<a href=\"$PHP_SELF?s=$news&q=$var\">Next</a>";
      }

    $a $s + ($limit) ;
      if (
    $a $numrows) { $a $numrows ; }
      
    $b $s ;
      echo 
    "<p>Showing results $b to $a of $numrows</p>";
      
    ?>

    </body>
    </html>

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Sorry for the late response, but here is the fixed code (tested and works as long as the SQL data is present). My changes are below in red.

    Code:
    <html>
    <head>
    </head>
    
    <body>
    
    <form name="form" action="searchscript.php" method="get">
      <input type="text" name="q" />
      <input type="submit" name="Submit" value="Search" />
    </form>
    
    <?php
    
      // Get the search variable from URL
    
      $var = @$_GET['q'] ;
      $trimmed = trim($var); //trim whitespace from the stored variable
    
    // rows to return
    $limit=1; 
    
    // check for an empty string and display a message.
    if ($trimmed == "")
      {
      echo "<p>Please enter a search...</p>";
      exit;
      }
    
    // check for a search parameter
    if (!isset($var))
      {
      echo "<p>We dont seem to have a search parameter!</p>";
      exit;
      }
    
    //connect to your database ** EDIT REQUIRED HERE **
    mysql_connect("xxx","yyy","zzz"); //(host, username, password)
    
    //specify database ** EDIT REQUIRED HERE **
    mysql_select_db("ddd") or die("Unable to select database"); //select which database we're using
    
    // Build SQL Query  
    $query = "SELECT * FROM `sponsor` WHERE `checkSponsorChild` LIKE '&#37;$trimmed%' ORDER BY `id`";  // EDIT HERE and specify your table and field names for the SQL query
     
    
     $numresults=mysql_query($query);
     $numrows=mysql_num_rows($numresults);
    
    // If we have no results, offer a google search as an alternative
    
    if ($numrows == 0)
      {
      echo "<h4>Results</h4>";
      echo "<p>Sorry, your search: &quot;" . $trimmed . "&quot; returned zero results</p>";
    
    // google
     echo "<p><a href=\"http://www.google.com/search?q=" 
      . $trimmed . "\" target=\"_blank\" title=\"Look up 
      " . $trimmed . " on Google\">Click here</a> to try the 
      search on google</p>";
      }
    
    // next determine if s has been passed to script, if not use 0
     
    if (empty($_GET['s'])) {
      $s=0;
      }
    
      else {
      $s = $_GET['s'];
      }
    
    
    // get results
      $query .= " LIMIT $s,$limit";
      $result = mysql_query($query) or die("Couldn't execute query");
    
    // display what the person searched for
    echo "<p>You searched for: &quot;" . $var . "&quot;</p>";
    
    // begin to show results set
    echo "Results";
    $count = 1 + $s ;
    $childrenInfo['childsName'] ."\r\n";
    // now you can display the results returned
      while ($childrenInfo= mysql_fetch_array($result)) {
      $title = $childrenInfo['childsName'];
    
      echo "$count.)&nbsp;$title" ;
      $count++ ;
      }
    
    $currPage = (($s/$limit) + 1);
    
    //break before paging
      echo "<br />";
    
      // next we need to do the links to other results
      if ($s>=1) { // bypass PREV link if s is 0
      $prevs=($s-$limit);
      print "&nbsp;<a href=\"$PHP_SELF?s=$prevs&q=$var\">Previous</a>&nbsp&nbsp;";
      }
    
    // calculate number of pages needing links
      $pages=intval($numrows/$limit);
    
    // $pages now contains int of pages needed unless there is a remainder from division
    
      if ($numrows%$limit) {
      // has remainder so add one page
      $pages++;
      }
    
    // check to see if last page
      if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
    
      // not last page so give NEXT link
      $news=$s+$limit;
    
      echo "&nbsp;<a href=\"$PHP_SELF?s=$news&q=$var\">Next</a>";
      }
    
    $a = $s + ($limit) ;
      if ($a > $numrows) { $a = $numrows ; }
      $b = $s + 1 ;
      echo "<p>Showing results $b to $a of $numrows</p>";
      
    ?>
    
    </body>
    </html>
    Hope this helps. If it doesn't work for you, let me know.

  3. #3
    Join Date
    Jun 2006
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you, it had to do with registerd globals vars.
    thank you for the guidance.
    http://uorf.org/new/sponsor.php

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •