PHP:如何在文本框中保存超链接的名称

时间:2014-02-20 05:45:39

标签: php mysql

请帮我这个代码,我想在php&中使用即时搜索mysql

如果用户在文本框中写入名称,则显示全部数据库值(如果相同)

超链接显示的值与:

相同

此页面:result.php

$text = $_REQUEST['textx'];
  $text = preg_replace('#[^a-z0-9]#i', '', $text);
  $query = "SELECT * FROM employee WHERE name_emp LIKE '%$text%' AND  job_title='driver'";
  $action = mysql_query($query);
  $result = mysql_num_rows($action);
  if ($result == 0) {
    $output = "User does not exist...";
  }else{
    while ($row = mysql_fetch_array($action)) {
      $output .= '<div class="output"><a href="#" >'.$row['name_emp'].'</div><br />';

    }
  }
  echo $output;

如果用户点击其中一个值,则该值出现在文本框中, 文本框退出另一页index.php。

我怎么能这样做?

的index.php

<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
    font: 100%/1.4 Verdana, Times New Roman, Helvetica, sans-serif;
    background-color: #ffffff;
    margin: 0;
    padding: 0;
    color: #000;
}
/* ~~ Element/tag selectors ~~ */
ul, ol, dl { /* Due to variations between browsers, it's best practices to zero padding and margin on lists. For consistency, you can either specify the amounts you want here, or on the list items (LI, DT, DD) they contain. Remember that what you do here will cascade to the .nav list unless you write a more specific selector. */
    padding: 0;
    margin: 0;
}
h1, h2, h3, h4, h5, h6, p {
    margin-top: 0;   /* removing the top margin gets around an issue where margins can escape from their containing block. The remaining bottom margin will hold it away from any elements that follow. */
    padding-right: 15px;
    padding-left: 15px; 
    border: none;
}
/* ~~ Styling for your site's links must remain in this order - including the group of selectors that create the hover effect. ~~ */
a:link {
    color: #42413C;
    text-decoration: underline; /* unless you style your links to look extremely unique, it's best to provide underlines for quick visual identification */
}
a:visited {
    color: #6E6C64;
    text-decoration: underline;
}
a:hover, a:active, a:focus { /* this group of selectors will give a keyboard navigator the same hover experience as the person using a mouse. */
    text-decoration: none;
}
/* ~~ This fixed width container surrounds all other blocks ~~ */
.container {
    width: 960px;
    background-color: #FFFFFF;
    margin: 0 auto; /* the auto value on the sides, coupled with the width, centers the layout */
}
/* ~~ The header is not given a width. It will extend the full width of your layout. ~~ */
header {
    background-color: #bbe0f4;
}


*/
.sidebar1 {
    float: left;
    width: 180px;
    background-color: #EADCAE;
    padding-bottom: 10px;
}
.content {
    padding: 10px 0;
    width: 600px;
    float: left;
aside {
    float: left;
    width: 180px;
    background-color: #EADCAE;
    padding: 10px 0;
}

/* ~~ This grouped selector gives the lists in the .content area space ~~ */
.content ul, .content ol {
    padding: 0 15px 15px 40px; 
}

/* ~~ The navigation list styles (can be removed if you choose to use a premade flyout menu like Spry) ~~ */
nav ul{
    list-style: none; /* this removes the list marker */
    border-top: 1px solid #666; /* this creates the top border for the links - all others are placed using a bottom border on the LI */
    margin-bottom: 15px; /* this creates the space between the navigation on the content below */
}
nav li {
    border-bottom: 1px solid #666; /* this creates the button separation */
}
nav a, nav a:visited { /* grouping these selectors makes sure that your links retain their button look even after being visited */
    padding: 5px 5px 5px 15px;
    display: block; /* this gives the link block properties causing it to fill the whole LI containing it. This causes the entire area to react to a mouse click. */
    width: 160px;  /*this width makes the entire button clickable for IE6. If you don't need to support IE6, it can be removed. Calculate the proper width by subtracting the padding on this link from the width of your sidebar container. */
    text-decoration: none;
    background-color: #C6D580;
}
nav a:hover, nav a:active, nav a:focus { /* this changes the background and text color for both mouse and keyboard navigators */
    background-color: #ADB96E;
    color: #FFF;
}

/* ~~ The footer ~~ */
footer {
    padding: 10px 0;
    background-color: #bbe0f4;
    position: relative;/* this gives IE6 hasLayout to properly clear */
    clear: both; /* this clear property forces the .container to understand where the columns end and contain them */
}
/* ~~ Miscellaneous float/clear classes ~~ */
.fltrt {  /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
    float: right;
    margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page. The floated element must precede the element it should be next to on the page. */
    float: left;
    margin-right: 8px;
}
.clearfloat { /* this class can be placed on a <br /> or empty block element as the final element following the last floated block (within the .container) if the footer is removed or taken out of the .container */
    clear:both;
    height:0;
    font-size: 1px;
    line-height: 0px;
}

/*HTML 5 support - Sets new HTML 5 tags to display:block so browsers know how to render the tags properly. */
header, section, footer, aside, article, figure {
    display: block;
}
-->
</style><!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script language="JavaScript" type="text/javascript"> 
function dtval(d,e) {
var pK = e ? e.which : window.event.keyCode;
if (pK == 8) {d.value = substr(0,d.value.length-1); return;}
var dt = d.value;
var da = dt.split('/');
for (var a = 0; a < da.length; a++) {if (da[a] != +da[a]) da[a] = da[a].substr(0,da[a].length-1);}
if (da[0] > 31) {da[1] = da[0].substr(da[0].length-1,1);da[0] = '0'+da[0].substr(0,da[0].length-1);}
if (da[1] > 12) {da[2] = da[1].substr(da[1].length-1,1);da[1] = '0'+da[1].substr(0,da[1].length-1);}
if (da[2] > 9999) da[1] = da[2].substr(0,da[2].length-1);
dt = da.join('/');
if (dt.length == 2 || dt.length == 5) dt += '/';
d.value = dt;
}
</script>
<script>



</script>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script> 
<script type="text/javascript" src="search.js"></script> 

<script>
  function showHint(str) {
    if (str.length==0) {
      document.getElementById("inner").innerHTML="You haven't search.";
      return;
    }
    if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    } else {
      // code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        document.getElementById("inner").innerHTML=xmlhttp.responseText;
      }
    }
    xmlhttp.open("REQUEST","results.php?text="+str,true);
    xmlhttp.send();
  }
  function setSelected(menuitem) {

    //JBP - get search result to place in search field on hover
    var title = $("#results ul li a").eq(menuitem).attr('title');
    $("#s").val(title);
    //

    $("#results ul li a").removeClass("search_hover");
    $("#results ul li a").eq(menuitem).addClass("search_hover");
    currentUrl = $("#results ul li a").eq(menuitem).attr("href");
}
</script>
<script>
  function showHint1(str) {
    if (str.length==0) {
      document.getElementById("inner1").innerHTML="You haven't search.";
      return;
    }
    if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    } else {
      // code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        document.getElementById("inner1").innerHTML=xmlhttp.responseText;
      }
    }
    xmlhttp.open("REQUEST","results1.php?textx="+str,true);
    xmlhttp.send();
  }
  function setSelected(menuitem) {

    //JBP - get search result to place in search field on hover
    var title = $("#results ul li a").eq(menuitem).attr('title');
    $("#s").val(title);
    //

    $("#results ul li a").removeClass("search_hover");
    $("#results ul li a").eq(menuitem).addClass("search_hover");
    currentUrl = $("#results ul li a").eq(menuitem).attr("href");
}
</script>
<script>
  function showHint2(str) {
    if (str.length==0) {
      document.getElementById("inner2").innerHTML="You haven't search.";
      return;
    }
    if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    } else {
      // code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        document.getElementById("inner2").innerHTML=xmlhttp.responseText;
      }
    }
    xmlhttp.open("REQUEST","results2.php?textxx="+str,true);
    xmlhttp.send();
  }
  function setSelected(menuitem) {

    //JBP - get search result to place in search field on hover
    var title = $("#results ul li a").eq(menuitem).attr('title');
    $("#s").val(title);
    //

    $("#results ul li a").removeClass("search_hover");
    $("#results ul li a").eq(menuitem).addClass("search_hover");
    currentUrl = $("#results ul li a").eq(menuitem).attr("href");
}
</script>
<script>
  function showHint3(str) {
    if (str.length==0) {
      document.getElementById("inner3").innerHTML="You haven't search.";
      return;
    }
    if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    } else {
      // code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        document.getElementById("inner3").innerHTML=xmlhttp.responseText;
      }
    }
    xmlhttp.open("REQUEST","results3.php?textxxx="+str,true);
    xmlhttp.send();
  }
  function setSelected(menuitem) {

    //JBP - get search result to place in search field on hover
    var title = $("#results ul li a").eq(menuitem).attr('title');
    $("#s").val(title);
    //

    $("#results ul li a").removeClass("search_hover");
    $("#results ul li a").eq(menuitem).addClass("search_hover");
    currentUrl = $("#results ul li a").eq(menuitem).attr("href");
}
</script>
<script>
  function showHint4(str) {
    if (str.length==0) {
      document.getElementById("inner4").innerHTML="You haven't search.";
      return;
    }
    if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    } else {
      // code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        document.getElementById("inner4").innerHTML=xmlhttp.responseText;
      }
    }
    xmlhttp.open("REQUEST","results4.php?textxxxx="+str,true);
    xmlhttp.send();
  }
  function setSelected(menuitem) {

    //JBP - get search result to place in search field on hover
    var title = $("#results ul li a").eq(menuitem).attr('title');
    $("#s").val(title);
    //

    $("#results ul li a").removeClass("search_hover");
    $("#results ul li a").eq(menuitem).addClass("search_hover");
    currentUrl = $("#results ul li a").eq(menuitem).attr("href");
}
</script>
</head>

<body>
 <?php
  $posted = false;
  if( $_POST ) {
    $posted = true;

$host="localhost"; // Host name 
$user_name="root"; // Mysql username 
$pass_word=""; // Mysql password 
$db_name="alkhaldi"; // Database name 
$tbl_name="trip"; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$user_name", "$pass_word")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
 //List 2 
 $li=$_POST['textx'];
 $li1=$_POST['text'];
 $li2=$_POST['textxx'];
 $li3=$_POST['textxxx'];
 $li4=$_POST['textxxxx'];
 $num=$_POST['num'];
 $date11=$_POST['date1'];
 $date22=$_POST['date2'];
 $date_up=str_replace("/","-",$date11);
  $date_do=str_replace("/","-",$date22);
 $date1 =date('Y-m-d', strtotime($date_up));
 $date2 = date("Y-m-d", strtotime($date_do));
 $type=$_POST['type'];
 $r=$_POST['rec'];
 $d=$_POST['del'];
 $value="";
$allo ="";
 $diff= $r- $d;
$date_3= str_replace("/","-",$date11);
$day= date('d', strtotime($date_3)) ;
$date20=31-$day;
$date_2 = date('$date20 days', strtotime($date_3));
$date_1 = date('Y-m-d', mktime(0, 0, 0, date('m',strtotime($date_3)), date('d',strtotime($date_3)) + $date20, date('Y',strtotime($date_3))));
 $rs1 = "SELECT* FROM path WHERE path_num='$li4'";
 $rs = mysql_query($rs1);
 $name=$_REQUEST['name_emp'];

if($row=mysql_fetch_array($rs)){

$value=$row['value'];
$allo =$row['allo_trip'];

    }
     if ($li =="" or $li1=="" or $li2=="" or $li3=="" or $li4=="" or $num=="" or $type=="" or $date1=="" or $date2=="" or $r=="" or $d=="" or $diff=="" or $value=="" or $allo=="" )
 {

     echo "<script type='text/javascript'>alert('Please enter all information ')</script>";
 }

         else

     {
        $sql="SELECT* FROM $tbl_name  WHERE num_dwn = '$num'";
        $result=mysql_query($sql);
        $anymatches=mysql_num_rows($result);
        if ($anymatches != 0)
    {
           echo "<script type='text/javascript'>alert('Sorry , This information is exit , can not added agine ')</script>";
  exit;



    }
 else
 {
   $query = "INSERT INTO trip (name_emp,cus_num,car_num,truck_num,path_num,num_dwn,type,date_r,date_s,amount_r,amount_s,diff,value,allowance) VALUES ('$li','$li1','$li2','$li3','$li4','$num','$type','$date1','$date2','$r','$d','$diff','$value','$allo' )";
   mysql_query($query) or die(mysql_error());

 }}

  $rs2 = "SELECT* FROM bill_trip WHERE date_1='$date_1' AND name='$li'";
   $rs5 = mysql_query($rs2);
$anymatches=mysql_num_rows($rs5);
 if ($anymatches == 0)
 {
   $query1 = "INSERT INTO bill_trip (name,Ttrip,Ttrip_allow,Ttotal_disel,date_1) VALUES ('$li','1','$allo','$value','$date_1' )";
   mysql_query($query1) or die(mysql_error()); 
 }
 else
 {
    if($row1=mysql_fetch_array($rs5)){

$total_trip=$row1['Ttrip'];
$trip_allow =$row1['Ttrip_allow'];
$disel=$row1['Ttotal_disel'];
$total_trip1=$total_trip +1;
$trip_allow1 =$trip_allow +$allo;
$disel1=$disel+$value;
    }
     $sql="UPDATE bill_trip SET Ttrip ='$total_trip1',Ttrip_allow='$trip_allow1',Ttotal_disel='$disel1'";
     mysql_query($sql) or die(mysql_error()); 
 }}
 ?>
<div class="container">
  <header>
    <p>&nbsp;</p>
    </p>
    <p> Website for employee - Add new Trip</p>
    <p>&nbsp;</p>
  </header>

  <div class="content">
    <section>
      <h5>Please enter the all information  </h5>
    </section>
<form id="search" name="search" method="post" action="" autocomplete="off"> 

    <table width="588" height="178">

 <tr>

 <td width="176" height="68" valign="top">

  <h5> Bill of Lading number *</h5>

 </td>

 <td width="295" valign="top">


     <input  type="text" name="num" maxlength="50" size="30">



 </td>

</tr>
<tr>

 <td width="176" height="68" valign="top">

  <h5> Customer Number *</h5>

 </td>

 <td width="295" valign="top">
<input id="text" type="text" name="text" onkeyup="showHint(this.value)"   value="<?php  if (isset($_REQUEST['cus_num'])  ){ echo $_REQUEST['cus_num'];}  ?>" />
<div id="inner" class="inner"></div>
 </td>

</tr> 
<tr>

 <td width="176" height="68" valign="top">

  <h5> Employee Name *</h5>

 </td>

 <td width="295" valign="top">

 <input id="textx" type="textx" name="textx" onkeyup="showHint1(this.value)" value="<?php  if (isset($_REQUEST['name_emp']) ){ echo $_REQUEST['name_emp'];}  ?>"  />

<div id="inner1" class="inner1"></div>


 </td>

</tr> 
<tr>

 <td width="176" height="68" valign="top">

  <h5> Car Number *</h5>

 </td>

 <td width="295" valign="top">
  <input id="textxx" type="textxx" name="textxx" onkeyup="showHint2(this.value)" autocomplete="off" />
<div id="inner2" class="inner2"></div>

 </td>
</tr> 
<tr>

 <td width="176" height="68" valign="top">

  <h5> Track Number *</h5>

 </td>

 <td width="295" valign="top">
   <input id="textxxx" type="textxxx" name="textxxx" onkeyup="showHint3(this.value)" autocomplete="off" />
<div id="inner3" class="inner3"></div>

</td>

</tr> 
<tr>

 <td width="176" height="68" valign="top">

  <h5> Date of Receipt *</h5>

 </td>

 <td width="295" valign="top">


     <input  type="text" name="date1" maxlength="50" size="30"  onkeyup="dtval(this,event);"/>



 </td>

</tr> 
<tr>

 <td width="176" height="68" valign="top">

  <h5> Date of Delivery *</h5>

 </td>

 <td width="295" valign="top">


     <input  type="text" name="date2" maxlength="50" size="30"  onkeyup="dtval(this,event);"/>

 </td>

</tr> 
<tr>

 <td width="176" height="68" valign="top">

  <h5> Cargo Type *</h5>

 </td>

 <td width="295" valign="top">


     <input  type="text" name="type" maxlength="50" size="30">



 </td>

</tr> 
<tr>

 <td width="176" height="68" valign="top">

  <h5> Quantity Received   *</h5>

 </td>

 <td width="295" valign="top">


     <input  type="text" name="rec" maxlength="50" size="30"/>



 </td>
</tr> 
<tr>

 <td width="176" height="68" valign="top">

  <h5> Quantity Delivered   *</h5>

 </td>

 <td width="295" valign="top">


     <input  type="text" name="del" maxlength="50" size="30"/>



 </td>

</tr> 


<tr>

 <td width="176" height="68" valign="top">

  <h5> Path Number   *</h5>

 </td>
 <td width="295" valign="top">
    <input id="textxxxx" type="textxxxx" name="textxxxx" onkeyup="showHint4(this.value)" autocomplete="off" />
<div id="inner4" class="inner4"></div>


 </td>

</tr>

  <td height="33" colspan="2" style="text-align:center">
    <p align="center">
      <input type="submit" value="Add new ">
      <input type="reset" value="Reset" />
      </p></td>



</tr>

<tr>

  <td colspan="2" style="text-align:center">

      </td>

</tr>

</table>

   </form><br />
    <div align="center">
    <h5>  <a href="main_admin.php">back to home</a></h5>
    </div>

<!-- end .content --></div>
  <footer>
    <p></p>

  </footer>
  <!-- end .container --></div>
</body>
</html>

谢谢..

1 个答案:

答案 0 :(得分:0)

试试这个......

<?php
$text = $_REQUEST['textx'];
  $text = preg_replace('#[^a-z0-9]#i', '', $text);
  $query = "SELECT * FROM employee WHERE name_emp LIKE '%$text%' AND  job_title='driver'";
  $action = mysql_query($query);
  $result = mysql_num_rows($action);
  if ($result == 0) {
    $output = "User does not exist...";
  }else{
    while ($row = mysql_fetch_array($action)) {
      $output .= '<div class="output"><a href="index.php?name_emp='.$row['name_emp'].'">'.$row['name_emp'].'</div><br />';
    }
  }
  echo $output;
?>

以下内容适用于index.php

 <?php
        //Index.php page,
        if(isset($_REQUEST['name_emp']) && $_REQUEST['name_emp'] != "")
        {
            echo "Name_EMP: "   .$_REQUEST['name_emp'];
        }

?>