gpt4 book ai didi

javascript - 尝试从选择选项将数据拉入表中

转载 作者:行者123 更新时间:2023-11-29 23:52:35 26 4
gpt4 key购买 nike

对于这个网站,我是个新手,但我认为这将是帮助解决我的问题的最佳机会。现在,我正在尝试从所选选项中提取数据并将其放入页面上的表格中。然而,当我完成代码并将其用于测试时,当我点击选择选项时,屏幕只是空白并且没有发布任何数据。代码附在下面。 PHP代码附在下面。

{<?php

$q = strval($_GET['q']);

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

mysqli_select_db($con,'platform');
$sql = "SELECT DISTINCT cert_type,
status
FROM em_certification_type
WHERE Id = '".$q."'";
$result = mysqli_query($con,$sql);

if($result === FALSE) {
>die(mysql_error());
}

echo "<table border='1'>";

while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['cert_type'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
echo "</tr>";
}

echo "</table>";

?>}

HTML(需要一些清理)

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<?php
/*establishing connection*/
$con = mysql_connect("localhost", "^^^^") or die("Connection Failed");
$db = mysql_select_db("plat")or die("Database not available");


/*setting up query for select box*/

$query1 = "SELECT DISTINCT SpecialtyCode
FROM em_certification_type
WHERE SpecialtyCode != ''";

$result1 = mysql_query($query1);


if (!$result1) {
$message = 'Invalid query on general requirements: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query1;
die($message);
}


/*setting query for general requirements table*/
$query2 = "SELECT DISTINCT cert_type,
expiration_date,
status,
SpecialtyCode
FROM em_certification_type
CROSS JOIN em_certification
WHERE em_certification_type.certification_id = em_certification.certification_type_id
ORDER BY em_certification_type.certification_id";
$result2 = mysql_query($query2);

if (!$result2) {
$message = 'Invalid query on general requirements: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query2;
die($message);
}

/* for the state requirements*/
$query3 = "SELECT cert_type,
expiration_date,
status,
state
FROM em_certification_type
CROSS JOIN em_certification
WHERE em_certification_type.certification_id = em_certification.certification_type_id
AND em_certification.state != ''";
$result3 = mysql_query($query3);



if (!$result3) {
$message = 'Invalid query on state requirements: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query3;
die($message);
}

?>
<h3>Credential</h3>

<form action="Cred.php">
<select name="selectSpecialty" class="selectSpecialty" onchange="showCred(this.value)">
<option value="" selected="selected">Choose Specialty</option>
<?php
/*Setting up a while loop to cycle through for the options*/
while ($row = mysql_fetch_array($result1))
echo("<option value = '" . $row['SpecialtyCode'] . "'>" . $row['SpecialtyCode'] . "</option>");
?>
</select>
</form>
<br>
<div id="txtHint"><b>Information will be listed here for general creds.</b></div>

</body>
<script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript" charset="utf-8"></script>
<script src="buttons.js" type="text/javascript" charset="utf-8"></script>
</html>'

最后,JavaScript

function showCred(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, IE 5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getcred.php?q="+str,true);
xmlhttp.send();
}

非常感谢任何想法或建议。预先非常感谢您。

最佳答案

试试这个

更改这部分

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

mysqli_select_db($con,'platform');

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

在mysqli中,您可以在mysqli_connect本身中定义数据库。不需要mysqli_select_db()

关于javascript - 尝试从选择选项将数据拉入表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25540833/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com