【问题标题】:INNER JOIN: Notice: showing Undefined IndexINNER JOIN:注意:显示未定义索引
【发布时间】:2017-07-10 16:53:29
【问题描述】:

我有两张桌子temp_bidpost_project。我想要投标项目的记录。为此,我使用 INNER JOIN 进行了查询,但出现未定义索引错误。它适用于 MySQL 编辑器。

这是我的代码。

<?php
include 'conn.php';
session_start();
if ($_SESSION['EmailID'] == "") {
    header("location:index.html");
}

$getTempBid = "SELECT * from temp_bid TB INNER JOIN post_project P ON P._id = TB.prj_id " + 
" WHERE TB.bidBy = '" .$_SESSION['EmailID']."'";

$tempBidResult = mysqli_query($conn,$getTempBid);

while($fetchTempBid = mysqli_fetch_row($tempBidResult)) {
    $tempBidId = $fetchTempBid['tempBidId'];
    $tempBidPrjId = $fetchTempBid['prj_id'];
    $tempBidPostBy = $fetchTempBid['postBy'];
    $tempBidBy = $fetchTempBid['bidBy'];
    $tempBidOn = new DateTime($fetchTempBid['bidOn']);
    $tempBidAmount = $fetchTempBid['amount'];
    $tempBidDays = $fetchTempBid['days'];
    $tempBidProposalDetails = $fetchTempBid['proposalDetails'];
    $tempBidStatus = $fetchTempBid['bidStatus'];
    $prjId = $fetchTempBid['_id'];
    $prjTitle = $fetchTempBid['projectTitle'];
    $prjDescriptions = $fetchTempBid['projectDescriptions'];
    $prjSkills = $fetchTempBid['projectRequiredSkill'];
    $prjSkills1 = explode(",", $prjSkills);
    $prjBudget = $fetchTempBid['projectBudget'];
    $prjPostDate = new DateTime($fetchTempBid['projectCreatedOn']);
    $prjStatus = $fetchTempBid['projectStatus'];
}
$records = mysqli_num_rows($tempBidResult);
?>

输出:

Notice: Undefined index: tempBidId in C:\wamp\www\Gopinath Infosystem\testpage.php on line 23
Notice: Undefined index: prj_id in C:\wamp\www\xxx\testpage.php on line 24
Notice: Undefined index: postBy in C:\wamp\www\xxx\testpage.php on line 25
Notice: Undefined index: bidBy in C:\wamp\www\xxx\testpage.php on line 26
Notice: Undefined index: bidOn in C:\wamp\www\xxx\testpage.php on line 27
Notice: Undefined index: amount in C:\wamp\www\xxx\testpage.php on line 28
Notice: Undefined index: days in C:\wamp\www\xxx\testpage.php on line 29

【问题讨论】:

  • 这只是意味着查询不返回任何记录。尝试使用完全相同的$_SESSION['EmailID'] 值直接在 mysql 中运行查询并检查是否有任何记录?
  • @AlivetoDie,我在 MySQL 中直接运行了相同的查询,使用完全相同的值 $_SESSION['EmailID'] 并且记录即将到来。
  • 你在下面有正确答案

标签: php mysql inner-join


【解决方案1】:

mysqli_fetch_row 返回一个带有数字键的数组。来自documentation

从结果集中获取一行数据并将其作为枚举数组返回,其中每一列存储在从 0(零)开始的数组偏移量中。对该函数的每次后续调用都将返回结果集中的下一行,如果没有更多行,则返回 NULL。

使用mysqli_fetch_assoc 代替返回一个以列名作为键的数组。

【讨论】:

    猜你喜欢
    • 2015-12-01
    • 2013-11-27
    • 2015-06-02
    • 2021-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-25
    相关资源
    最近更新 更多