简体   繁体   中英

how to write this sql statement

I have a rather simple question. How would I write this statement in php?

$q="SELECT t1.gebruikersnaam FROM tbel_leden as t1,instellingen as t2 WHERE
    t2.ledenid=t1.ledenid AND t2.livetracking=1";

I know it's just supposed to be a string but the error says unexpected t_variable and php admin is not helping either.

Thanks

缺少美元符号来表示php变量:

$q="SELECT t1.gebruikersnaam FROM tbel_leden as t1,instellingen as t2 WHERE t2.ledenid=t1.ledenid AND t2.livetracking=1";

$q="SELECT t1.gebruikersnaam FROM tbel_leden as t1 Left join instellingen as t2 on t2.ledenid=t1.ledenid WHERE t2.livetracking=1";

or

$q="SELECT t1.gebruikersnaam FROM tbel_leden as t1 join instellingen as t2 on t2.ledenid=t1.ledenid WHERE t2.livetracking=1";

it depends on what you want to get from DB. It's recommended to read a SQL spec about JOIN.

<?php
$con = mysql_connect("localhost","username","password");
if (!$con){
  die('We don't have a connection: ' . mysql_error());
}

mysql_select_db("yourDB", $con);


$q = "SELECT t1.gebruikersnaam FROM tbel_leden as t1 Left join instellingen as t2 on       t2.ledenid=t1.ledenid WHERE t2.livetracking=1"; 
$result = mysql_query($q); 

while ($row = mysql_fetch_array($result,MYSQL_NUM)){ 
echo $row[0]."<br />"; 
} 


?>

you should try this code snippet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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