tags:

views:

130

answers:

2

Hello,

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

+3  A: 

Missed a dollar sign to denote a php variable:

$q="SELECT t1.gebruikersnaam FROM tbel_leden as t1,instellingen as t2 WHERE t2.ledenid=t1.ledenid AND t2.livetracking=1";
Quassnoi
Ok, that was too easy, haha. Sorry I missed that, but that wasn't it
Unexpected t_varable is a PHP error, not MySQL. Check youк PHP code: you must have missed a brace or a parenthesis or something.
Quassnoi
I know, the error stops exactly on that line?
Please post some code before and after this line.
Quassnoi
I put the solution already in the comment above, thank you
A: 

$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.

vaske
thank you, hope that works.be back in a bit
nope, php doesn't like that either
I get what I want with my first select from within phpadmin, but not from the phpscript?
What kind or error you got?
vaske
<?php$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 />"; }?>try this one.
vaske
of course you need first to make a db connection. before you do the select.
vaske