MySQLi SELECT查询相关记录

时间:2014-10-16 06:13:52

标签: mysql select

好的,我已经编辑了我的邮件,并在回复中提供了第二个查询的代码。我还包括了对结果的期望的屏幕截图;这是:

  1. 罪犯的照片和生物数据
  2. 第一个SELECT查询语句中与罪犯关联的任何其他违规者的照片。
  3. 这可能是你的建议吗?

    <?php
     //The first working MySQLi SELECT statement is here .....
    
        }
    
        /* Close the statement */
        $stmt->close();
    }
    else {
        /* Error */
        printf("Prepared Statement Error: %s\n", $mysqli->error);
    }
    
        if ($stmt = $mysqli->prepare("SELECT PersonID,ImagePath FROM t_persons 
                    NATURAL JOIN t_incidents
                    NATURAL JOIN t_incident_persons 
            WHERE t_persons.PersonID = '$PersonID' AND t_incident_persons.IncidentID = t_incident.IncidentID")) {   
    
        /* Execute the prepared Statement */
        $stmt->execute();
    
        /* Bind results to variables */
        $stmt->bind_result($PersonID,$ImagePath);
    
        /* fetch values */
        while ($rows = $stmt->fetch()) {
         // display records in a table
         <?php echo '<img src="./Persons_Images/'.$ImagePath.'" width="300" height="400" border="1" />';  ?>
         }
         }
    /* close our connection */
    $mysqli->close();
    ?>  
    

    预期结果应为:

    enter image description here

1 个答案:

答案 0 :(得分:0)

  

为表格执行自然连接

select ('coulmns in need') from t_persons natural join t_incidents natural join t_incident_persons;