Jump to content

Recommended Posts

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:&nbsp;&nbsp;&nbsp;
<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 page
if(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 will
start 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 2
You 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 2
there will be 5 pages.
*/
$totalpages = $totalpages / $limit;
$totalpages = round($totalpages,0);
$c = 0;//The variable c is 0
echo "<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 = 1
if($_GET['num']==$page){//Gets the number of the page and if its the same that the page
echo "[$page] ";//its only echoes the page, not the url to this page
}else{//else
echo "<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
Link to comment
https://forums.phpfreaks.com/topic/12566-php-mysql-search-problems/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.