简体   繁体   English

PHP / MySqli:具有2个表的预准备MySqli语句,并且WHERE不返回数据

[英]PHP/MySqli: Prepared MySqli statement with 2 tables and WHERE not returning data

i am trying to get data from 2 tables of my criminals database, and its not returning anything when I add a "AND criminal_name = 'FIDEL URBINA'" to get only the data per criminal. 我正在尝试从犯罪分子数据库的2个表中获取数据,并且当我添加“ AND Crime_name ='FIDEL URBINA'”以仅获取每个罪犯的数据时,它什么也不返回。

This is my code and SQL statement right now, 这是我的代码和SQL语句,

$stmt = $mysqli->prepare("SELECT criminal_name, event_location FROM criminal_profile, criminal_locations 
    WHERE criminal_profile.criminal_id = criminal_locations.criminal_id");

$stmt->execute();
$stmt->bind_result($criminal_name, $event_location); //get data from statement
$stmt->store_result();


 if($formaat=='xml'){ //XML
            $xml=new SimpleXMLElement('<criminals></criminals>');


            while($stmt->fetch()) // zolang er rijen zijn
            {
                // $criminal_name, Scriminal_pob en $event_location zijn gevuld
                //voeg element criminal_pob toe met naam criminal_pob, criminal_name en event_location:
                $info = $xml->addChild('criminal');
                $item = $info->addChild('criminal_name',$criminal_name);
                $item = $info->addChild('event_location',$event_location);
            }
            header('Content-type: text/xml'); //DIT WERKT NIET? cant send headers after they were sent

            // coderen als JSON:
            echo $xml->asXML();
        }

which repeats the criminals based on how many event locations they have, as shown in this image: 如图所示,它根据事件发生的地点来重复犯罪分子:

http://grabilla.com/05b0e-a271d885-dc45-47ad-a043-c92d832162bd.png http://grabilla.com/05b0e-a271d885-dc45-47ad-a043-c92d832162bd.png

Anyone have a idea on why this is not returning data when I add a "AND criminal_name = 'FIDEL URBINA'" or anything like that? 任何人都有一个想法,为什么当我添加“ AND Crime_name ='FIDEL URBINA'”之类的东西时,它不返回数据? I also tried "AND criminal_name = 'F%'". 我还尝试了“ AND Crime_name ='F%'”。

Could be a matching problem for this you can try with like operatore instead of = 可能是一个匹配的问题,您可以尝试使用like operatore而不是=

"SELECT criminal_name, event_location FROM criminal_profile, criminal_locations 
WHERE criminal_profile.criminal_id = criminal_locations.criminal_id 
AND criminal_name LIKE '%FIDEL URBINA%");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM