Current location: Hot Scripts Forums » Other Discussions » Database » grrr... i wanna do this with one query...


grrr... i wanna do this with one query...

Reply
  #1 (permalink)  
Old 11-19-06, 09:53 AM
stormshadow's Avatar
stormshadow stormshadow is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 355
Thanks: 0
Thanked 0 Times in 0 Posts
grrr... i wanna do this with one query...

im not too sure i can but i think so...

all i want to do is select the name of an item from the game_items table where tradeable='Y'

In addition to that I need it to select the game_items id column and check to see if that id equals Y in the members table... yes it will be there....ya dig?

PHP Code:

$sel_ntitems mysql_query("SELECT gi.name FROM game_items gi, member m WHERE gi.tradable='N' && m.gi.name='Y' && m.id='$player[id]'")or die("Error:"mysql_error() ."!"); 

is it possible?
Reply With Quote
  #2 (permalink)  
Old 11-19-06, 12:40 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
it should be like this:
PHP Code:

$sel_ntitems mysql_query("SELECT gi.name FROM game_items AS gi INNER JOIN member AS m ON (gi.id = m.id) WHERE gi.tradable='N' && gi.name='Y' && m.id='".$player[id]."'")or die("Error:"mysql_error() ."!"); 

i think this should do, i haven't tested it.

UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #3 (permalink)  
Old 11-19-06, 01:05 PM
stormshadow's Avatar
stormshadow stormshadow is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 355
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by UnrealEd
it should be like this:
PHP Code:

$sel_ntitems mysql_query("SELECT gi.name FROM game_items AS gi INNER JOIN member AS m ON (gi.id = m.id) WHERE gi.tradable='N' && gi.name='Y' && m.id='".$player[id]."'")or die("Error:"mysql_error() ."!"); 

i think this should do, i haven't tested it.

UnrealEd
not like that... what i think your code does is match the member id and the game_items id correct? i could be wrong but that is what i think... but i could be wrong...

in the members table there will be something like gympass which would = Y if they have it and N if they dont... now in the game_items table the id would be gympass so i would want to get the column gi.id from the members table get it? its hard to explain....
Reply With Quote
  #4 (permalink)  
Old 11-19-06, 01:13 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
Quote:
Originally Posted by stormshadow
not like that... what i think your code does is match the member id and the game_items id correct? i could be wrong but that is what i think... but i could be wrong...
correct, that's what it does.
Quote:
Originally Posted by stormshadow
in the members table there will be something like gympass which would = Y if they have it and N if they dont... now in the game_items table the id would be gympass so i would want to get the column gi.id from the members table get it? its hard to explain....
So you would have a table looking like this:
Code:
CREATE TABLE `mytable`(
  `id` INT(10) AUTO_INCREMENT PRIMARY KEY NOT NULL,
  `gympass` CHAR(1) NOT NULL
)
and a table like this:
Code:
CREATE TABLE `table2`(
  `id` VARCHAR(50) NOT NULL
)
and in this table2, the value of id could be 'gympass'. Do i understand this correctly?
I don't think this is possible using only 1 query (i might be wrong, i don't know that much about mysql).
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #5 (permalink)  
Old 11-20-06, 04:17 PM
stormshadow's Avatar
stormshadow stormshadow is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 355
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by UnrealEd
and in this table2, the value of id could be 'gympass'. Do i understand this correctly?
I don't think this is possible using only 1 query (i might be wrong, i don't know that much about mysql).
Yes that is what i need... will i need to run a while loop?
Reply With Quote
  #6 (permalink)  
Old 11-20-06, 07:17 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
I think that would be best. You'll be needing the "SHOW TABLE mytable" query, this returns all columns, and some information about the table. Then you'll have to loop over the results.

I think that's the only way. I'm not that good with mysql though. It's weird that no one else has replyed yet.

UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

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
running Query, but 2 Get statements dont wanna work together 0o0o0 Database 9 08-14-06 05:22 PM
code problem throws error matt001 ASP.NET 0 10-23-05 03:30 AM
Nested Query in PHP/MYSQL truesilentassassin PHP 2 07-27-04 07:50 PM
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:56 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.