rogerc Posted April 18, 2008 Share Posted April 18, 2008 hi Having a problem with displaying all the results from my table.I can return the first 5 but the others come back zero if anyone can see the problem your help is much appreciated . thanks rogerc <?php // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=10; // 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 mysql_connect("localhost"); //specify database mysql_select_db("resultsdb") or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "select * from grades where f_name like \"%$trimmed%\" order by f_name"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</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: "" . $var . ""</p>"; // begin to show results set echo "Results"; $count = 1 + $s ; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["f_name"]; $l_name =$row['l_name']; $address1 =$row['address1']; $address2 =$row['address2']; $address3 =$row['address3']; $english =$row['english']; $irish =$row['irish']; $math =$row['math']; $science =$row['science']; $geography =$row['geography']; $history =$row['history']; echo "$count.) $title ,$l_name,$address1, $address2, $address3, $english, $irish, $math, $science, $geography, $history" ; $count++ ; } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // 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 " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> (edited by kenrbnsn to add the tags) Link to comment https://forums.phpfreaks.com/topic/101705-solved-help-please/ Share on other sites More sharing options...
jonsjava Posted April 18, 2008 Share Posted April 18, 2008 Shouldn't matter, but change mysql_fetch_array to mysql_fetch_assoc As I said, it shouldn't matter, but won't hurt at all to give it a try. Link to comment https://forums.phpfreaks.com/topic/101705-solved-help-please/#findComment-520307 Share on other sites More sharing options...
rogerc Posted April 18, 2008 Author Share Posted April 18, 2008 hi yeah no go thanks for the try rogerc Link to comment https://forums.phpfreaks.com/topic/101705-solved-help-please/#findComment-520314 Share on other sites More sharing options...
jonsjava Posted April 18, 2008 Share Posted April 18, 2008 Usually, if you get ANY responses, it means that it's working. If you are getting 5 results, you should be getting more, if there is anything in your DB that meets the search requirements. The fact that you are receiving 5 results tells me that it's working, but it's not finding more than 5 results. Link to comment https://forums.phpfreaks.com/topic/101705-solved-help-please/#findComment-520324 Share on other sites More sharing options...
rogerc Posted April 18, 2008 Author Share Posted April 18, 2008 hi Jon you right i deleted evering fron the database and re entered it and work fine thanks rogerc Link to comment https://forums.phpfreaks.com/topic/101705-solved-help-please/#findComment-520333 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.