I have a page that will display the names of people from one data base that is joined with another that tracks when two names are linked. Every thing works fine. However; I cannot make the data or specifically the right user name ($id2u) and a string ($permissions) transfer from the input boxes when the user selects one. The onclick event should then show the data fields as per the permission string. The problem is the displayed info is always the last user in the DB that was ran through the loop. Am trying to get the info to carry forward on the onclick event when a check box is clicked so that their info is displayed.

我有一个页面,它将显示一个数据库中的人员名称,这个数据库与另一个数据库连接,跟踪两个名称的链接时间。一切都很好。然而;当用户选择一个时,我无法从输入框传输数据或特定正确的用户名($ id2u)和字符串($ permissions)。然后,onclick事件应根据权限字符串显示数据字段。问题是显示的信息始终是数据库中通过循环运行的最后一个用户。当点击一个复选框时,我试图获取信息以继续onclick事件,以便显示他们的信息。

This is he function to call the display of data.

这是他调用数据显示的功能。

function display1(type) {document.getElementById("pi").style.display = "none"
 document.getElementById(type).style.display = ""}

This is the call to the DB that generated the input boxes for each person.

这是对DB的调用,为每个人生成输入框。

$result1  = mysql_query('SELECT * FROM level1 LEFT JOIN linkreq ON level1.idnumber = linkreq.idme ORDER BY LEAST(lname, fname) DESC');
for ($i = mysql_num_rows($result1) - 1; $i >= 0; $i--){
    if (!mysql_data_seek($result1, $i)){echo "Cannot seek to row $i: " . mysql_error() . "\n";continue;}
    if (!($row = mysql_fetch_assoc($result1))) {continue;}
    if($_SESSION["idnumber"] == $row['id2u']){
    if($row['returnack'] == 0){$id2u = $row['idme']; echo'<font color="#FF6600">*</font>&nbsp;&nbsp;&nbsp;'.$row['title'].' '.$row['fname'].' '.$row['mname'].' '.$row['lname'].' '.$row['suffex'].'<br />';}
    else{
    $permissions  = $row['permissions'];
    parse_str($permissions);
    $permissions; 
    $id2u = $row['idme'].'&nbsp; ';
    echo '<input type="checkbox"  value = " .$id2u. " onClick="display1(\'pi\');">&nbsp;&nbsp;&nbsp;'
    .$row['title'].' '.$row['fname'].' '.$row['mname'].' '.$row['lname'].' '.$row['suffex'].'
    <br />';}}}

This is the data that gets displayed onclick(pi) but displays last user not the selected one. Basically if the $id2u variable data would carry over from the check box this would work. As can manually force it by setting $id2u = xxxxxx; just before the query.

这是在onclick(pi)上显示的数据,但显示最后一个用户而不是所选用户。基本上,如果$ id2u变量数据将从复选框结转,这将起作用。可以通过设置$ id2u = xxxxxx手动强制它;就在查询之前。

$result2  = mysql_query('SELECT * FROM pi WHERE idnumber = "'.$id2u.'"');


for ($i = mysql_num_rows($result2) - 1; $i >= 0; $i--){
    if (!mysql_data_seek($result2, $i)){echo "Cannot seek to row $i: " . mysql_error() . "\n";continue;}
    if (!($row = mysql_fetch_assoc($result2))) {continue;}
    echo '<br>row #'.$row['idnumber'];
    if($id2u == $row['idnumber']){echo'...// PRINTS OUT DATA //...}}

</span>

I know this should be in mySQLi but for now just need to get it to work will convert later.

我知道这应该在mySQLi中,但是现在只需要让它工作就可以转换。

1 个解决方案

#1


0

Why don't you use a while() loop ?

你为什么不使用while()循环?

$query = mysql_query("...");
while($row = mysql_fetch_array($query))
{
   ...
}

This always works fine for me :)

这对我来说总是很好:)

更多相关文章

  1. vmware12下的centos7 linux 安装 mysql5.17数据库
  2. ASP.NET GridView 绑定 MySql数据库
  3. MySQL数据库相关开发入门
  4. MySQL数据库导入或者同步大量数据时数据丢失解决方案
  5. php 连接数据库 Warning: mysqli_connect(): (HY000/2002): No s
  6. mysql进阶(十一)外键在数据库中的作用
  7. 我需要介绍MongoDB / NoSQL数据库
  8. MariaDB 和 MySQL 全面对比:选择数据库需要考虑这几点
  9. 腾讯云数据库团队:GreenPlum简单性能测试与分析--续

随机推荐

  1. MySQL搜索优化(用子查询替换长正则表达式)
  2. 阿里云服务器MySQL远程连接问题
  3. zabbix监控mysql、apache、交换机
  4. MySQL大战SQLite和PostgreSQL(比拼、比较
  5. MySQL中建立索引的集中方式
  6. 关于MySQL的各种总结
  7. mysql 调优 来自5.6版本官方手册
  8. MySQL中的排序(ORDER BY)
  9. 根据cookie数据连接两个表
  10. sqlsever 转mysql 出错 MySQL max_allowe