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条)

报告相同问题?

悬赏问题

  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题