dqcz57269 2013-12-03 13:33
浏览 21

将php表转换为多个javascript文本框[关闭]

I have used ajax to select data from a db and displayed the data in a table. However i then found out that this is not editable. I wish to edit the returned data on the current page. Is it possible to edit a table, if not how would i go about changing the table data and inserting it into the javascript textboxes. Thanks in advance.

HTML:

<head>
<link href="../UserTemplate.css" rel="stylesheet" type="text/css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>Tours</title>
<script language="javascript" type="text/javascript">
function showUser(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  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("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>


<br>
<div id="txtHint"></div>

</body>
</html>
</script>
</head> 
<body>
<div id="MainDiv">
    <div id="Header">
            <div id="Logo"><img src="../Scotia Sea Life Logo.png" width="150px" height="110px" alt="Company Logo"/></div>
            <div id="NavBar"><ul>
                        <a href="homepage.php">Home</a> <a href="SelectStudentScore.php">Tours</a> <a href="AdditionPageMain.php">About</a> <a href="SubtractionPageMain.php">Donate</a> <a href="Devisionmain.php">Account</a>
               </ul>
      </div>     
            <div id="Title">Tours</div>
  </div>
        <div id="Content">
          <div id="Search">
            <div id="SearchDiv">
            <form id="SelectTourForm" style="margin:5px;">
            <table border="0" align="center" width="100%">
                            <tr>
                                <td width="44%"><label id="lbl_TourNumber" style="color:#FFF; padding-left: ">Tour Number</label></td>
                                <td width="56%"><input type="text" name="txt_TourNumber" id="txt_TourNumber" placeholder="e.g. A123" style="width:100px;"/></td>
                            </tr>
            </table>
            <table border="0" align="center" width="100%">
                            <tr>
                                <td>
                                <select name="lst_MonthDrop" style="background-color:#FF9933; color:#FFF; border:none; border-radius:5px;" onchange="showUser(this.value)">
                                  <option>Please Select</option>
                                                 <?php 
                                                 include 'populatedrodown.php';
                                                 foreach ( $results as $option ) : ?>
                                                      <option value="<?php echo $option->Date; ?>"><?php echo $option->Date; ?></option>
                                                 <?php endforeach; ?>
                                            </select>
                                </select>
                                </td>
                            </tr>
                            <tr> 
                              <td><input type="text" name="txt_Count" id="txt_Count" style="width:100px;"/><input type="submit" name="btn_TourSearch" id="btn_TourSearch" value="Search" style="background:#009300; border-radius:5px; border-color:#009300; color:#FFF; float:right; margin-right:5px;" /></td>
                            </tr>
            </table>

                        <p>&nbsp;</p>
                    </form>
              </form>

            </div>
          </div>

       <div id="DetailsDiv">
            <div id="DetailsContent">
                <form id="DetailsForm" >
                    <table border="0" align="center" width="100%">
                    <tr><td><label style="color:#FFF; font-size:14px;">Tour ID</label> <input type="text" id="Tour_ID" />    </td></tr>
                    <tr><td><label>Duration</label> <input type="text" id="txt_Duration" />   </td></tr>
                    <tr><td><label>Vessel Name</label> <input type="text" id="txt_Vessel_Name"/> </td></tr>
                    <tr><td><label>Location</label> <input type="text" id="txt_Location" />   </td></tr>
                    <tr><td><label>Date</label> <input type="text" id="txt_Date" />       </td></tr>
                    <tr><td><label>Available</label> <input type="text" id="txt_Available" />  </td></tr> 
                    <tr><td><label>Price</label>  <input type="text" id="txt_Price" />     </td></tr>         
                    </table>
                </form>
            </div>
          </div>
        </div>
        <div id="Footer">
        <div id="FooterLinks"></div>
    </div>
</div>
</body>
</html>

PHP:

<?php
$q = $_GET['q'];

$con = mysqli_connect('localhost','root','pwd','db');
if (!$con)
  {
  die('Could not connect: ' . mysqli_error($con));
  }

mysqli_select_db($con,"Tours.php");
$sql="SELECT * FROM Tour WHERE Date = '".$q."'";
$result = mysqli_query($con,$sql);

echo "<table border='1'>
<tr>
<th>Tour_ID</th>
<th>Duration</th>
<th>Vessel_Name</th>
<th>Location</th>
<th>Date</th>
<th>Available</th>
<th>Price</th>
</tr>";

while($row = mysqli_fetch_array($result))
  {

  echo "<tr>";
  echo "<td>" . $row['Tour_ID'] . "</td>";
  echo "<td>" . $row['Duration'] . "</td>";
  echo "<td>" . $row['Vessel_Name'] . "</td>";
  echo "<td>" . $row['Location'] . "</td>";
  echo "<td>" . $row['Date'] . "</td>";
  echo "<td>" . $row['Available'] . "</td>";
  echo "<td>" . $row['Price'] . "</td>";
  echo "</tr>";
  }
echo "</table>";
$dur = $row['Duration'];
mysqli_close($con);
?>
  • 写回答

2条回答 默认 最新

  • duanjiao6730 2013-12-03 13:56
    关注

    As Ravi stated, @Seatter, yes you can echo in textboxes like:

    echo "<td> <input type='text' name='anyname' value='".$row['Tour_ID']."' /> </td>";
    

    Thank you for your quick response.

    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题