Current location: Hot Scripts Forums » Programming Languages » PHP » Help with MySQL Query!


Help with MySQL Query!

Reply
  #1 (permalink)  
Old 10-21-04, 02:50 PM
Wraith Wraith is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Help with MySQL Query!

I got this:
PHP Code:

$query mysql_query("SELECT * FROM `tbl_cheats` WHERE `Letter` = '".$l."' in(

SELECT DISTINCT `Game` FROM `tbl_cheats`')"
) or die(mysql_error()); 
I get this error: You have an error in your SQL syntax near 'SELECT DISTINCT `Game` FROM `tbl_cheats`')' at line 2.

All help will be greatfull!

-Neo
Reply With Quote
  #2 (permalink)  
Old 10-21-04, 05:28 PM
Sabu Sabu is offline
Junior Code Guru
 
Join Date: Sep 2004
Posts: 458
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

  $query mysql_query("SELECT * FROM `tbl_cheats` WHERE `Letter` = '".$l."' in('SELECT DISTINCT `Game` FROM `tbl_cheats`')") or die(mysql_error()); 

Try that. While you CLOSED the second query with an apostrophe ( ' ), you never opened it.
__________________
define('TRUE', FALSE);
Reply With Quote
  #3 (permalink)  
Old 10-21-04, 06:02 PM
Wraith Wraith is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Ok thanks. But Now, its not getting any data. Dont get me wrong, but I want to do this:
  • Get all records, but only one of each game.
  • Then get only the ones with the letter $l (which for testers is R)
Now, just looking at my signiture, you can see these more than one cheat. all 4 being the same - RS3 letter R.

Goto http://home.prcentral.co.uk/neo/gs/index.php?p=cheats and check for yourself if you like.

Thanks All - I really need to get this finished (look at the front page and you'll notice im 11 days behind!).

Thanks
-Wraith aka NeoPuma
Reply With Quote
  #4 (permalink)  
Old 10-22-04, 09:25 AM
moronovich moronovich is offline
Junior Code Guru
 
Join Date: Oct 2004
Posts: 460
Thanks: 0
Thanked 0 Times in 0 Posts
hello wraith,
i hesitate the select statement will work as you wish. you tried to execute sub query which is unavailable till MySQL 4.1.x.
__________________
just an ignorant noob with moronic solution...
Reply With Quote
  #5 (permalink)  
Old 10-22-04, 11:34 AM
Wraith Wraith is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by moronovich
hello wraith,
i hesitate the select statement will work as you wish. you tried to execute sub query which is unavailable till MySQL 4.1.x.
Ah...Thanks .

Ok, now how would I do what I want (in php)? I have a rough idea like this but I ain't tryed it...

Would: SELECT DISTINCT * FROM `tbl_cheats` work?
Reply With Quote
  #6 (permalink)  
Old 10-22-04, 01:11 PM
Wraith Wraith is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Sorry couldn't find the edit button!

I have tried my idea, and it has actually worked (change ).

PHP Code:

    $query mysql_query("SELECT * FROM `tbl_cheats` WHERE `Letter` = '".$l."'") or die(mysql_error()); 

    if(
mysql_num_rows($query) > 0) {
        echo 
'<table width="100%" border="0">
          <tr>
            <td><div align="center"><font size="1"><font face="Verdana, Arial, Helvetica, sans-serif">Game
                Title</font></font></div></td>
            <td><div align="center"><font size="1"><font face="Verdana, Arial, Helvetica, sans-serif">Consoles
        </font></font></div></td>
            <td><div align="center"><font size="1"><font face="Verdana, Arial, Helvetica, sans-serif">Number
            Of Cheats</font></font></div></td>
          </tr>'
;
        while(
$row mysql_fetch_array($query)) {
            if(
strpos($games$row['smlGame']) === false) {
                
$games .= $row['smlGame']. ' ';
                
$result2 mysql_query("SELECT `smlGame` FROM `tbl_cheats` WHERE `smlGame` = '".$row['smlGame']."'");
                echo 
'<tr>
                    <td><div align="center"><font size="1"><font face="Verdana, Arial, Helvetica, sans-serif">
                <a href="index.php?p=cheats&a=view&game='
.$row['smlGame']. '">'.$row['Game'].'</a></font></font></div></td>
                <td><div align="center"><font size="1"><font face="verdana, Arial, Helvetica, sans-serif">'
.$row['Console'].'</font></font></div></td>
                    <td><div align="center"><font size="1"><font face="Verdana, Arial, Helvetica, sans-serif">'
.mysql_num_rows($result2).'</font></font></div></td>
                  </tr>'
;
            }
        }
        echo 
'</table>';
    } else {
        echo 
'We havn\'t got any cheats at the moment! Why not sign up and add some?';
    } 
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Query Performance / MySql HenLab PHP 1 08-12-04 04:38 PM
MySQL SELECT query result dividing ICE Flame PHP 1 06-06-04 02:50 PM
PHP:search by MySQL query lowdog PHP 0 02-15-04 10:04 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


All times are GMT -5. The time now is 04:40 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.