TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-20-2008, 04:31 PM   #1 (permalink)
The Contributor
Newcomer 
 
Join Date: Jan 2008
Posts: 27
Thanks: 1
lesP is on a distinguished road
Default 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"];
lesP is offline  
Reply With Quote
Old 01-20-2008, 04:43 PM   #2 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Have you run that query against a database (and I mean manually)? If so, what does it say/do?
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
The Following User Says Thank You to xenon For This Useful Post:
lesP (01-20-2008)
Old 01-20-2008, 06:46 PM   #3 (permalink)
The Addict
Upcoming Programmer Top Contributor 
 
Rendair's Avatar
 
Join Date: Nov 2007
Location: UK
Posts: 319
Thanks: 18
Rendair is on a distinguished road
Default

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()); 
__________________
www.jooney.co.uk - the online portfolio
Send a message via MSN to Rendair
Rendair is offline  
Reply With Quote
Old 01-20-2008, 07:55 PM   #4 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Well spoted, Rendair! I usually have a problem reading code floating around, and I don't even bother reading further That's his problem, I believe (I know for sure that && is not valid in MySQL).
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 01-20-2008, 08:21 PM   #5 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

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

MySQL AB :: MySQL 5.0 Reference Manual :: 10.2.4 Logical Operators
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-20-2008, 08:27 PM   #6 (permalink)
The Addict
Upcoming Programmer Top Contributor 
 
Rendair's Avatar
 
Join Date: Nov 2007
Location: UK
Posts: 319
Thanks: 18
Rendair is on a distinguished road
Default

Ah well you learn something new everyday
__________________
www.jooney.co.uk - the online portfolio
Send a message via MSN to Rendair
Rendair is offline  
Reply With Quote
Old 01-20-2008, 08:28 PM   #7 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
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
Salathe is offline  
Reply With Quote
Old 01-20-2008, 10:14 PM   #8 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

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.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 01-21-2008, 08:55 PM   #9 (permalink)
The Contributor
Newcomer 
 
Join Date: Jan 2008
Posts: 27
Thanks: 1
lesP is on a distinguished road
Default

Thx a lot guys! it really helped me out.
lesP is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:39 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design