TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Weird error with query (http://www.talkphp.com/advanced-php-programming/2030-weird-error-query.html)

lesP 01-20-2008 04:31 PM

Weird error with query
 
Hi there.

I do not understand it. I get no output from this query:

$id_bruger=$_SESSION['id_bruger'];
$query=mysql_query("select distinct b_spil.titel as titel,b_spil.id as id from b_spil,f_spil where f_spil.id_bruger='$id_bruger' && f_spil.id_spil=b_spil.id");
while($result=mysql_fetch_array($query)){
echo ' <a href="index.php?mode=mine_spil&action=vis_spil&spi l='.$result["id"].'" class="undermenupunkt">';
echo $result["titel"];

xenon 01-20-2008 04:43 PM

Have you run that query against a database (and I mean manually)? If so, what does it say/do?

Rendair 01-20-2008 06:46 PM

Have you tried putting a mysql error function at the end

PHP Code:

$query=mysql_query("select distinct b_spil.titel as titel,b_spil.id as id from b_spil,f_spil where f_spil.id_bruger='$id_bruger' && f_spil.id_spil=b_spil.id")or die(mysql_error()); 

least will tell you whats wrong

Plus i don't know if you can use && in mysql queries iv never done it that way, but usually its

PHP Code:

$query=mysql_query("select distinct b_spil.titel AS titel,b_spil.id AS id from b_spil,f_spil WHERE f_spil.id_bruger='$id_bruger' AND f_spil.id_spil=b_spil.id")or die(mysql_error()); 


xenon 01-20-2008 07:55 PM

Well spoted, Rendair! I usually have a problem reading code floating around, and I don't even bother reading further :-P That's his problem, I believe (I know for sure that && is not valid in MySQL).

Alan @ CIT 01-20-2008 08:21 PM

&& is valid SQL - it's just the normal logical AND operator :-)

MySQL AB :: MySQL 5.0 Reference Manual :: 10.2.4 Logical Operators

Rendair 01-20-2008 08:27 PM

Ah well you learn something new everyday :-P

Salathe 01-20-2008 08:28 PM

Quote:

Originally Posted by xenon (Post 9089)
I know for sure that && is not valid in MySQL.

How sure is sure? As far as I'm aware, both AND and && are perfectly valid -- as they are with PHP too.

As said before, if we could get a reply stating what the error is that MySQL is saying, that would help us to help you. :-)

Edit: Thanks for providing a link Alan. I'm so slow in replying to topics :-(

xenon 01-20-2008 10:14 PM

Oh, so && works in SQL, too. I supposed it didn't because I've never seen a SQL statement to contain it. I will never make assumptions again. Stupid me.

lesP 01-21-2008 08:55 PM

Thx a lot guys! it really helped me out.


All times are GMT. The time now is 12:12 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0