dongtang6775 2013-07-18 19:22
浏览 57
已采纳

在phpmyadmin中编辑的mysql数据库不会在php脚本中返回查询

This is a weird problem. I have a field called status in a database table called Parents. Via a php script, I entered a bunch of parents with status of 'active'. Later, I used phpmyadmin to change two of them to a status of 'dormant'. When I run a query asking for rows with status of active, all is well in both phpmyadmin and in my php script. When I run a query asking for rows with status of dormant, phpmyadmin returns the two rows whose status is dormant, but my php script does not return any rows. Here are the relevant pieces of the code:

// get value of radio button for $active
$active = stripslashes(strip_tags($_POST['active']));
if (!$active) {
  $active = 'active';
}

// Similar process for value of $myOrderby, 
// which can have value of 'name' or 'email' and works fine

$query = "SELECT 
    Parents.parentID, 
    Parents.parentName, 
    Parents.parentEmail, 
    Students.nickName,
    Students.Lname
  FROM Parents, Students
  WHERE Parents.parentID=Students.parentID
    AND Parents.status=:active
  ORDER BY $myOrderby ASC" ;
$stmt = $db->prepare($query);
$stmt->bindValue(':active', $active, PDO::PARAM_STR);

try {
   $stmt->execute();
   $affected_rows = $stmt->rowCount();
   if ($affected_rows > 0) {
      // various actions...
   }
} catch (PDOException $ex) {
   $message = $ex->getMessage() ;
   $filename = 'admin-parents' ;
   notifyMe($message, $filename) ;
}

Curiously, however, if I again use phpmyadmin to change the two rows whose status is 'dormant' back to a status of 'active' (not using any punctuation in the input box) those two rows do NOT show up in the php results for all active parents. That is the problem that started me on this entire quest.

CLARIFICATION: myphpadmin query ALWAYS returns correct result for these two rows, both when status is 'active' and when status is 'dormant'. (I change them via myphpadmin.) However, php script NEVER returns these two rows, regardless of their status.

  • 写回答

2条回答 默认 最新

  • dongyong9224 2013-07-26 00:42
    关注

    It turns out: The two rows in Parent table with status of 'dormant' did NOT have any rows in the Student table. The query returns only rows where a Parent also has a Student. Which is not exactly what I intended. Back to the drawing board! But I am SO relieved to understand the source of the problem! Thanks everyone! :-)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备