i am a newbie at php. Hi i have a script got it from a website but something is wrong with this script. it is a search engine connected to my database. the problems are: 1)It does not display one by one (pagination does not work) .It shows the results on one row. 2)when i do not type anything in the text box and click on the submit button, it does display the last searched keyword. this is my script <?php // rows to return $limit = 10; // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); mysql_connect("localhost", "root", ""); mysql_select_db("deneme1") or die("Unable to select database"); // Build SQL Query $query = "select * from members where username like \"%$trimmed%\" order by username"; $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["username"]; echo "$count.) $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 " <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>"; ?> PHP: can anyone help me please? thanks in advance.
i do not have the url (because my friend gave me this code and he does not understand too)but i can show you the html code: <html> <head> <title>Search </title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <form name="form" action="search12.php" method="get"> Search : <input type="text" name="q" /> <input type="submit" name="Submit" value="Search" /> </form> </body> PHP: i use wamp server on windows xp. Thanks.
<?php $q = $_GET['q']; mysql_connect("localhost", "root", ""); mysql_select_db("deneme1") or die("Unable to select database"); // Build SQL Query $query = "select * from members where username like \"%$q%\" order by username"; $result = mysql_query($query); $counter = 0; while($row = mysql_fetch_object($result)) { $counter++; echo "$counter) $row->username<BR>"; } if(!$counter) { echo "<p>Sorry, your search for \"$q\" returned zero results.</p>"; } ?> PHP: This won't fix your problem, but I can barely read the code you posted. Try this code, it's a way more efficient way of doing what you were doing. Then add the other features once this basic version works.