Jump to content

[SOLVED] Query Help


JustinMs66@hotmail.com

Recommended Posts

What i am trying to do is get all videos where the game has a console of #123, and has a group of #12345.

Now i have to do it differently because the consoles are not in the video table, they are in the game table.

 

SELECT

video.groups,video.randname,games.consoles,video.timestamp,video.id

FROM

video,

games

WHERE

video.groups LIKE "%12345%"

AND

games.consoles LIKE "%123%"

LIMIT 3

 

That query is, when i do while($row=mysql_fetch_array...etc, outputting 3 of the same video randnames. It outputs 3 of the same video id's.

 

Help please?

 

Link to comment
https://forums.phpfreaks.com/topic/114930-solved-query-help/
Share on other sites

Tables:

table: video

important rows:

id int(30)

randname int(8)

gameid int(10)

groups text

 

table: games

id int(30)

name text

consoles text

 

Samples:

Games:

id: 8

name: Half Life 2

consoles: 4,8,9

 

Video:

id: 6

randname: 57954341

gameid: 8

groups: 78239

 

 

Now i want to get all videos which it's game has the console number 4, and that are in the group 78239. I can get the group, but getting the console of the game is different, i'm not sure how to do it.

Link to comment
https://forums.phpfreaks.com/topic/114930-solved-query-help/#findComment-591238
Share on other sites

well i normally i would create another table for consoles and link it in..

but you could do this

SELECT video.id, games.id, video.groups,video.randname,games.consoles,video.timestamp
FROM
video, games
WHERE
video.groups LIKE "%12345%"
AND
CONCAT(',', games.consoles, ',') LIKE "%,4,%"
GROUP BY video.id, games.id
LIMIT 3

 

basically it changes "4,8,9" to ",4,8,9," then looks for [something],4,[something]

this works better as [something]4[something] would find 4 or 40 or 14, and if we don't concat the comma's then 1,2,3,4 wouldn't work (no trailing comma)

Link to comment
https://forums.phpfreaks.com/topic/114930-solved-query-help/#findComment-591271
Share on other sites

Two things --- first, DISTINCT is not a function, it's a modifier to SELECT; it filters out rows where ALL field values in the column list match.  Very different than GROUP BY.  Second, you can use FIND_IN_SET() if you values are comma separated without all that string manipulation.  But it's a bad idea to store lists in fields.

Link to comment
https://forums.phpfreaks.com/topic/114930-solved-query-help/#findComment-591417
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.