lpxxfaintxx Posted June 21, 2006 Share Posted June 21, 2006 Hello,the following query: [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]"SELECT * FROM tutorials WHERE activation = '1' AND catid = '$catid' AND name LIKE '%$search%' LIMIT $start, $limit";[/quote] is going wrong. It shows tutorials where the $search has nothing in common with the name. The form is:[code]<form action="search.php">Search: <form method="post" action="search.php"> <input type="text" name="search" size=25 maxlength=25> <select name="category"> <option value="Default">Choose a category</option> <?php $query = "SELECT * FROM category"; $result = mysql_query ($query); while ($row = mysql_fetch_array ($result, MYSQL_NUM)) {echo "<option value='{$row[0]}'>{$row[1]}</option>";} ?> <br><br> </select> <input name="image" type="image" src="images/search.jpg" alt="0"/></form>[/code]and the search.php is:[code]<?$num = $_GET['num'];//Get the numeration of the pageif(empty($num)){//if the numeration is empty$num = 1;//the numeration is 1};$limit = 15;//Sets the limit of results to display in each page, change if you want./*The query will start selecting the numeration, for example 2, less 1, that would be 1* the limits of results to show per page, 2 in this case so it would be 1*2 = 2, it willstart from 2;) if the limit would be 5 and the numeration would be 3 if would be (3-1)*5 = 10*/$start = ($num-1)*$limit;$start = round($start,0);//rounds the result/*This query will select the contrene FROM the start and with a limit of 2, in this case,because the variable $limit is 2You can add a WHERE something= '$something' for example, or delete the ORDER by `id`, or change it,etc*/$search=$_POST["search"];$catid = $_POST['category'];$query = "SELECT * FROM tutorials WHERE activation = '1' AND catid = '$catid' AND name LIKE '%$search%' LIMIT $start, $limit";$result = mysql_query($query);while ($rowss = mysql_fetch_array($result)){ $author = $rowss['author']; $description = $rowss['description']; $name = $rowss['name']; $imageurl = $rowss['imageurl']; $url = $rowss['url']; $url2 = 'viewtut.php?id='.$rowss['id'].''; $totalviewed = $rowss['hits']; $cat1 = $rowss['catid']; $tut_rating = $rowss['rating']; $sub = $rowss['subcatid']; $sql3 = "SELECT * FROM `category` WHERE `cat_id` = '$cat1'"; $result3=mysql_query($sql3); $rows3=mysql_fetch_array($result3); $cat3 = $rows3['category']; echo " <div class='tutorial'> <div class='tutorialtitle'> <span class='style1'><a href='".$url2."'>".$name."</a></span><br /> Author: <a href='#'>".$author."</a> | Rating: <span class='style3'>".tut_stars($tut_rating)."<br></span></div> <img src='".$imageurl."' width='44' height='43' alt='' /><br />".$description."<br /> <span class='style2'>22nd March 2006 <span class='style3'><a href='#'>Report Tutorial</a></span> <span class='style3'>Total Views: <strong>".$totalviewed."</strong></span> <span class='style3'>Categorgy: <a href='viewcat.php?act=maincat&id=".$catids."'><strong>".$cat3."</strong></a></span></span></div> "; } $totalpages = mysql_num_rows(mysql_query("SELECT * from `tutorials` WHERE `subcatid` = '$subcat' and `catid` = '$idf'"));//Get the total number of results/*Total resutls/ the limit, in this example is 2, so if there are 10 total result and the limit is 2there will be 5 pages.*/$totalpages = $totalpages / $limit;$totalpages = round($totalpages,0);$c = 0;//The variable c is 0echo "<br>";//make a <br> to separate the results from the [1][2]...while($c<$totalpages){//while c is < than the total pages$page = $c + 1;//sets the variable $page as 0 + 1 = 1if($_GET['num']==$page){//Gets the number of the page and if its the same that the pageecho "[$page] ";//its only echoes the page, not the url to this page}else{//elseecho "<a href=?act=subcat&id=".$cat1."&sub=".$sub."&num=$page>[$page] </a>";//it echoes the url to the page}$c = $c+1;}echo "<br>".$totalpages." Pages in total.";//echoes the total pages?>[/code]Does anyone have any explanation(s) why this is happening?Regards,LPX Quote Link to comment https://forums.phpfreaks.com/topic/12566-php-mysql-search-problems/ Share on other sites More sharing options...
Buyocat Posted June 21, 2006 Share Posted June 21, 2006 What sorts of results is it getting, I may be wrong but I thought %$search% meant anything that contained $search in it. That could mean a lot of things. Quote Link to comment https://forums.phpfreaks.com/topic/12566-php-mysql-search-problems/#findComment-48146 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.