This is probably an easy thing to do but I'm an amateur and things just aren't working for me.

这可能是一件容易的事情,但我是一个业余爱好者,事情并不适合我。

I just want to check and see if a row exists where the $lectureName shows. If a row does exist with the $lectureName somewhere in it, I want the function to return "assigned" if not then it should return "available". Here's what I have. I'm fairly sure its a mess. Please help.

我只想查看$ lectureName显示的行是否存在。如果某个行确实存在且其中包含$ lectureName,我希望该函数返回“已分配”,否则它将返回“可用”。这就是我所拥有的。我很确定它一团糟。请帮忙。

function checkLectureStatus($lectureName)
{
 $con = connectvar();
 mysql_select_db("mydatabase", $con);
 $result = mysql_query("SELECT * FROM preditors_assigned WHERE lecture_name='$lectureName'");
  while($row = mysql_fetch_array($result));
  {
     if (!$row[$lectureName] == $lectureName)
     {
         mysql_close($con);
         return "Available";
     }
      else
     {
        mysql_close($con);
        return "Assigned";
    }
}

When I do this everything return available, even when it should return assigned.

当我这样做时,一切都返回可用,即使它应该返回分配。

7 个解决方案

#1


20

This ought to do the trick: just limit the result to 1 row; if a row comes back the $lectureName is Assigned, otherwise it's Available.

这应该是诀窍:将结果限制为1行;如果一行返回,$ lectureName是Assigned,否则它是Available。

function checkLectureStatus($lectureName)
{
    $con = connectvar();
    mysql_select_db("mydatabase", $con);
    $result = mysql_query(
        "SELECT * FROM preditors_assigned WHERE lecture_name='$lectureName' LIMIT 1");

    if(mysql_fetch_array($result) !== false)
        return 'Assigned';
    return 'Available';
}

更多相关文章

  1. require():使用module.exports vs直接分配给“this”
  2. 为什么分配给True / False不能像我期望的那样工作?
  3. numpy无法将值分配给列的一部分
  4. 时间总是过得比你想像中的快,理想总是会被四周的事情所掩盖,希望能
  5. 在C#.net的server explorer 上建立的数据库,在sql server managem
  6. 深入理解Java虚拟机读书笔记---垃圾回收与内存分配
  7. java基础---JVM---调优,垃圾收集器,内存分配策略

随机推荐

  1. 在android tegra2中添加一个camera
  2. Android Installation error: INSTALL_FA
  3. TextView的一些属性
  4. Android P应用显示宽高比maxAspectRatio
  5. Android调试神器stetho使用详解和改造
  6. 【Android Developer Blog】Android Stud
  7. Android高手进阶教程(五)之----Android
  8. android 组件
  9. android音乐播放器开发_开篇
  10. android ui显示技巧和注意事项