Php 单击单选按钮检索mySQL数据

Php 单击单选按钮检索mySQL数据,php,mysql,ajax,Php,Mysql,Ajax,通过一些非常感谢的帮助,从这个网站的用户我已经能够把一个脚本,一个单选按钮点击将填充一个表与用户详细信息 我认为我可以进一步适应它,但是,很可能是因为我缺乏经验,不幸的是我遇到了另一个问题,因此我添加了一个新帖子 从mySQL数据库中提取数据,我使用下面的代码创建一个日期列表,其中包含一个关联的单选按钮 <html> <head> <script type="text/javascript"> function showUser(str) { if (str=

通过一些非常感谢的帮助,从这个网站的用户我已经能够把一个脚本,一个单选按钮点击将填充一个表与用户详细信息

我认为我可以进一步适应它,但是,很可能是因为我缺乏经验,不幸的是我遇到了另一个问题,因此我添加了一个新帖子

从mySQL数据库中提取数据,我使用下面的代码创建一个日期列表,其中包含一个关联的单选按钮

<html>
<head>
<script 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","getuser2.php?="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php 
mysql_connect("hostname", "username", "password")or 
die(mysql_error()); 
mysql_select_db("database"); 


$result = mysql_query("SELECT userdetails.userid, finds.dateoftrip, detectinglocations.locationname, finds.userid, finds.locationid, detectinglocations.locationid,   finds.findname, finds.finddescription FROM userdetails, finds, detectinglocations WHERE finds.userid=userdetails.userid AND finds.locationid=detectinglocations.locationid AND finds.userid = 1 GROUP By dateoftrip ORDER BY dateoftrip DESC"); 

if (mysql_num_rows($result) == 0)  
// table is empty  
  echo 'There are currently no finds recorded for this location.';  
  else 
 {  
  echo"<table>\n"; 
  while (list($userid, $dateoftrip) = 
    mysql_fetch_row($result)) 
  { 

    echo"<tr>\n" 
    . 
     "<td><input type='radio' name='show' dateoftrip value='{$userid}' onClick='showUser(this.value)'/></td>\n" 
    ."<td><small>{$dateoftrip}</small><td>\n" 
    ."</tr>\n"; 
  } 
  echo'</table>'; 
} 

?> 
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>
</body>
</html>
PHP

    <?php 
//$q=$_GET["q"]; 

$con = mysql_connect('hostname', 'username', 'password'); 
if (!$con) 
{ 
die('Could not connect: ' . mysql_error()); 
} 

mysql_select_db('database', $con); 

$sql="SELECT * FROM finds"; 

$result = mysql_query($sql); 

// This is helpful for debugging
if (!$result) {
    die('Invalid query: ' . mysql_error());
}

echo "<table border='1'> 
<tr> 
<th>Find Name</th> 
</tr>"; 

while($row = mysql_fetch_array($result)) 
{ 
echo "<tr>"; 
echo "<td>" . $row['findname'] . "</td>"; 

echo "</tr>"; 
} 
echo "</table>"; 

mysql_close($con); 
?> 

不是


mysql\u-fetch\u数组
接受一个mysql结果对象(从
mysql\u查询
函数调用中获得),而不是
$row=mysql\u-fetch\u数组($sql)


$sql
是一个字符串,您应该改为使用
$result
,它是一个
mysql\u result
对象。

在何处查找.userid=userdetails.userid和。。。并且在您的第一个代码脚本mysql\u查询中找到了finds.userid=1?@sransara谢谢,我现在已经从查询中删除了
finds.userid=userdetails.userid
。RegardsHi,你能详细解释一下吗?嗨,非常感谢你帮我看这个。我已经做了您建议的更改,但不幸的是,我仍然收到相同的错误。友善的regards@IRHM您是否检查了“查询结果”是否生成了正确的结果?也许可以尝试Hi@sransara中的第一个示例,如果我正确理解了这一点,那么结果如下:
无效查询:您的SQL语法有错误;查看与MySQL服务器版本对应的手册,了解在第1行“WHERE 1=1”附近使用的正确语法
Kind regardsHi@IRHM实际上我早期的意思是为速度太慢而道歉。我运行了调试。这一行的“id”找到了id=“$q.”是问题所在。我现在已更改此项以及与“fetch array”相关的项。该表现在显示字段数据。但是,它不会显示所选正确单选按钮的相关记录。这是指向我的页面的链接:。我对这个有点陌生,所以我用新的代码修改了我原来的帖子。我只是想知道你是否可以看一看,并告诉我哪里出了问题。真诚的感谢。
<html>
<head>
<script 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","getuser2.php?="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php 
mysql_connect("hostname", "username", "password")or 
die(mysql_error()); 
mysql_select_db("database"); 


$result = mysql_query("SELECT userdetails.userid, finds.dateoftrip, detectinglocations.locationname, finds.findid, finds.userid, finds.locationid, detectinglocations.locationid, finds.findname, finds.finddescription FROM userdetails, finds, detectinglocations WHERE finds.locationid=detectinglocations.locationid AND finds.userid = 1 GROUP By dateoftrip ORDER BY dateoftrip DESC"); 

if (mysql_num_rows($result) == 0)  
// table is empty  
  echo 'There are currently no finds recorded for this location.';  
  else 
 {  
  echo"<table>\n"; 
  while (list($findid, $dateoftrip) = 
    mysql_fetch_row($result)) 
  { 

    echo"<tr>\n" 
    . 
     "<td><input type='radio' name='show' dateoftrip value='{$findid}' onClick='showUser(this.value)'/></td>\n" 
    ."<td><small>{$dateoftrip}</small><td>\n" 
    ."</tr>\n"; 
  } 
  echo'</table>'; 
} 

?> 
<br />
<div id="txtHint"></div>
</body>
</html>
    <?php 
//$q=$_GET["q"]; 

$con = mysql_connect('hostname', 'username', 'password'); 
if (!$con) 
{ 
die('Could not connect: ' . mysql_error()); 
} 

mysql_select_db('database', $con); 

$sql="SELECT * FROM finds"; 

$result = mysql_query($sql); 

// This is helpful for debugging
if (!$result) {
    die('Invalid query: ' . mysql_error());
}

echo "<table border='1'> 
<tr> 
<th>Find Name</th> 
</tr>"; 

while($row = mysql_fetch_array($result)) 
{ 
echo "<tr>"; 
echo "<td>" . $row['findname'] . "</td>"; 

echo "</tr>"; 
} 
echo "</table>"; 

mysql_close($con); 
?> 
while ($row = mysql_fetch_array($result))
while ($row = mysql_fetch_array($sql))