如何在sql中使用AND,OR [英] how to use AND,OR in sql

查看:107
本文介绍了如何在sql中使用AND,OR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?php
$search = $_POST['searchvalue'];
    $search= $_POST['searchvalue'];//first time the 'searchvalue' is from form
    $newsearch = $_GET['searchvalue'];//for next time 'searchvalue' is from url
 if((!$newsearch) && strlen($search)<=1)
    {
    echo "Search term too short";
    }
    else{    	    	
        echo "You searched for $search <hr size='1'></br>";
    $construct = "SELECT * FROM books WHERE category = '$name' AND ((title LIKE '%$search% ' or author LIKE '%$search% ')  or (title LIKE '%$newsearch% ' or author LIKE '%$newsearch% ' ))";
    $run = mysql_query($construct);
    $foundnum = mysql_num_rows($run);
    if ($foundnum==0){
    	//echo $_GET['start'];
    echo "Sorry, there are no matching result for $search.</br></br>1.";
    }
    else
    {
    echo "$foundnum results found !<p>";
    }
//I have next button here.
?>



如果搜索结果有10条记录我想打印每页5条记录,对于第一次搜索我我在第一页成功获得5条记录只发生在这个SQL查询中


if search results have 10 records i want to print 5 records per page, for first search i am getting 5 records in first page successfully it is only happening with this sql query

<br />
"$construct=SELECT * FROM books WHERE category = '$name' AND (title LIKE '%$search% ' or author LIKE '%$search% ')";



如果我点击下一个按钮接下来的五个记录不是在下一页打印,它是由于POST,因为FORM在一个php页面而SEARCH.PHP是另一个页面,我需要从url获取下一次搜索的值。所以我使用了GET方法,但问题是$ search正在使用POST,因此我更改了sql查询,如下所示代码中显示


if i click next button the next five records is not printing in next page, its is due to POST, because FORM is in one php page and SEARCH.PHP is another page, I need to get the value from url for next search. so I used GET method, but problem is $search is using POST, hence I changed the sql query, like below as showed in code

$construct = "SELECT * FROM books WHERE category = '$name' AND ((title LIKE '%$search% ' or author LIKE '%$search% ')  or (title LIKE '%$newsearch% ' or author LIKE '%$newsearch% ' ))";<br />



但是这次它甚至不能用于第一次搜索,请任何人帮我如何修改我的查询以获得正确的结果。抱歉我的英语不好。请尝试理解我的问题。


but this time its not working even for first search, please anyone help me how to modify my query to GET the correct results. And sorry for my poor english. please try to understand my problem.

推荐答案

search =
search =


_POST [' searchvalue'];
_POST['searchvalue'];


search =


这篇关于如何在sql中使用AND,OR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆