本文介绍了如何使用或语句运行多个查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友我是php和mysql的新手,我想执行一个查询,它必须搜索4列common表(常见的是表名)。我们将在前端只有一个文本框,其名称=refno



Hi friends i m new to php and mysql and i want to execute a query where it has to search in 4 columns of "common" table(common is a table name). where we will be having only one textbox at the front end and its name="refno"

<?php

error_reporting(0);

$con = mysql_connect("localhost","root","");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }



mysql_select_db("newcrm", $con);



$refid = "";



$tblname = "";



if(isset($_POST["submit1"]))

{

    $refid = $_POST['refno'];/*

    $pieces = explode("-", $tblname);*/

}

?>




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>abc</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <link href="css/style.css" rel="stylesheet" type="text/css">

<script type="text/javascript">
// Popup window code
function newPopup(url) {
    popupWindow = window.open(
        url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>

<script type="text/javascript">
// Popup window code
function newPopup(url) {
    popupWindow = window.open(
        url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <script>
  $(function() {
    $( "#from" ).datepicker({
      defaultDate: "+1w",
      changeMonth: true,
      numberOfMonths: 1,
      onClose: function( selectedDate ) {
        $( "#to" ).datepicker( "option", "minDate", selectedDate );
      }
    });
    $( "#to" ).datepicker({
      defaultDate: "+1w",
      changeMonth: true,
      numberOfMonths: 1,
      onClose: function( selectedDate ) {
        $( "#from" ).datepicker( "option", "maxDate", selectedDate );
      }
    });
  });
  </script>

<style>
.ddtbl{
    width:100%;
    border-collapse:collapse;
}
.ddtbl td{
    border:1px solid red;
}
.ddtbl th{
    border:1px solid red;
}



</style>
</head>
<body>
<div class="main">
<div class="page">
  <!--<div class="header_nav">welcome <strong><?php echo $_SESSION['SESS_FIRST_NAME']." ".$_SESSION['SESS_LAST_NAME']; ?></strong> | <a href="logout.php">Sign Out </a>| Help </div>
-->
<div class="header">
<div class="banner">
  <h1><a href ="userform.php"> <img src="images/abc.png" width="100"alt="abc" align="absmiddle"/>abc</a></h1>
</div>

</div>
<div class="content">
<div class="content-in">

<div class="gap"></div>
<div class="right-panel" style="border:1px solid red;">

<div style="position:relative;overflow:hidden;width:100%;border:1px solid blue;min-height:200px;">
<form action="fetchdata.php" method="post">

<table style="width:100%;">
    <tr>
        <td>
            <div class="reg_form_row">
            <div class="reg_form_row_left">Enter RefNo. or Agent Name or abc No. or Caller Id</div>
            <div class="reg_form_row_right"><input name="refno" style="width: 150px;" maxlength="100" value="<?php echo $refid; ?>" /></div>
            </div>
        </td>
    </tr>
</table>
<input name="submit1" type="submit" value="Get Info" />

</form>

</div>
</div>


<?php

if(isset($_POST["submit1"]))

{

    if($refid!="")

    {

        $strquery = "select * from common where refno='$refid'" ;

        //$strquery = "select * from common where agentname='$refid'" ;

        //$strquery = "select * from common where zcno='$refid'" ;

        //$strquery = "select * from common where callerid='$refid'" ;



        $result = mysql_query($strquery);



        ?>
        <table class="ddtbl">
        <tr>
            <th>Results for Refno entry</th>
        </tr>
        </table>
        <table class="ddtbl">
        <tr>
            <th>refno</th>
            <th>date</th>
            <th>agentname</th>
            <th>zcno</th>
            <th>callerid</th>
        </tr>
        <?php

        while($data = mysql_fetch_array($result))

        {

            $refno = $data["refno"];

            $date = $data["date"];

            $agentname = $data["agentname"];

            $zcno = $data["zcno"];

            $callerid = $data["callerid"];



            ?>


        <tr>
            <td><?php echo $refno; ?></td>
            <td><?php echo $date; ?></td>
            <td><?php echo $agentname; ?></td>
            <td><?php echo $zcno; ?></td>
            <td><?php echo $callerid; ?></td>
        </tr>

            <?php

        }

        echo("</table><br /><br />");
    }
        $result1 = mysql_query($strquery1);
        ?>

        <?php

    }

?>

</body>
</html>

推荐答案




这篇关于如何使用或语句运行多个查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 09:15