Jump to content

Recommended Posts

Here are my tables

 

game_systems

gs_idgame_idsystem_id

10146

102414

18845

 

games

game_idtitledescrurl_wikipedia

4Fallout 3Blah blah blahnone

 

genres

genre_idgenre

5Role-Playing

 

systems

system_idabbreviation

5PS3

6360

14PC

 

Now here's my query

SELECT gs.gs_id, g.title, g.descr, ge.genre, g.url_wikipedia, gs.system_id, s.abbreviation

FROM games AS g

Inner Join game_systems AS gs ON gs.game_id=g.game_id

Inner Join systems AS s ON s.system_id=gs.system_id

Inner Join game_genres AS gg ON gg.game_id=g.game_id

Inner Join genres AS ge ON gg.genre_id=ge.genre_id

WHERE gs.game_id='4'

ORDER BY s.abbreviation ASC

 

If I run this query I get the following output.

101 Fallout 3 Blah blah blah none 6 360

102 Fallout 3 Blah blah blah none 14 PC

188 Fallout 3 Blah blah blah none 5 PS3

 

Now when I run this code through PHP

$que_t="SELECT gs.gs_id, g.title, g.descr, ge.genre, g.url_wikipedia, gs.system_id, s.abbreviation
  FROM games AS g
  Inner Join game_systems AS gs ON gs.game_id=g.game_id
  Inner Join systems AS s ON s.system_id=gs.system_id
  Inner Join game_genres AS gg ON gg.game_id=g.game_id
  Inner Join genres AS ge ON gg.genre_id=ge.genre_id
  WHERE gs.game_id='4'
  ORDER BY s.abbreviation ASC";
$res_t=mysql_query($que_t) or die(mysql_error());
if(mysql_num_rows($res_t)<=0) { $othersys="<i> no system(s)</i>"; }
else { while($systems=mysql_fetch_array($res_t)) { $othersys.="<a href='title.php?type=games&s=$systems[system_id]&g=all&c=all&i=4'>$systems[abbreviation]</a> "; } }
echo "$othersys";

 

I get the following output to the page

<a href='title.php?type=games&s=14&g=all&c=all&i=4'>PC</a> <a href='title.php?type=games&s=5&g=all&c=all&i=4'>PS3</a>

 

It should be

<a href='title.php?type=games&s=6&g=all&c=all&i=4'>360</a> <a href='title.php?type=games&s=14&g=all&c=all&i=4'>PC</a> <a href='title.php?type=games&s=5&g=all&c=all&i=4'>PS3</a>

 

Where'd 360 go??

Link to comment
https://forums.phpfreaks.com/topic/156016-help-with-a-query/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.