vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Need help with a query/result (https://vborg.vbsupport.ru/showthread.php?t=78566)

Adrian Schneider 03-22-2005 07:24 PM

Need help with a query/result
 
Ok here are my 2 tables being used:

fc_team and fc_player

I need to display the player name of each field in team [which are just ids] (ie fc_team.batsmanid1=fc_player.id)

I tried using left join but since there would be a different 'name' field for each id it won't work.

I got the query working using
[sql]
SELECT team.batsmanid1, player1.name, team.batsmanid2, player2.name
FROM fc_team team, fc_player player1, fc_player player2
WHERE team.batsmanid1=player1.id
AND team.batsmanid2=player2.id
AND team.id=$teamid
[/sql]

Upon showing this (I just used 2 of the positions for testing), I could only get one name to display, so how would I go about doing this? Can you rename the result to something like name2 instead of having 4 names, which causes conflicts?

Marco van Herwaarden 03-22-2005 07:33 PM

Are you just now designing these tables, or are they existing?

I think you are making it yourself difficult with not normalising your team table. Instead of having a batsmanid1, batsmanid2 etc in the team table, you could better make a table with the fields: teamid, playernumber, playerid. So instead of just 1 record, split it up for every batsman.

Adrian Schneider 03-23-2005 12:35 AM

edit: sorry, existing already.

Do you mean teamid, playername, playerid?

edit: or teamid, positionname, playerid

For future reference, how would I go about doing this without a different table?

Marco van Herwaarden 03-23-2005 07:20 AM

Well without modifying your table your example would just work if you chage it like:
[sql]SELECT team.batsmanid1, player1.name AS name1, team.batsmanid2, player2.name AS name2
FROM fc_team team, fc_player player1, fc_player player2
WHERE team.batsmanid1=player1.id
AND team.batsmanid2=player2.id
AND team.id=$teamid
[/sql]
The question is if you really want the tables to stay like this. How many players you can have in a team? Is this a fixed number?

Adrian Schneider 03-23-2005 05:29 PM

Oh so you can rename the result thanks a lot.

Yes I need the tables to stay like this, it's far too complicated to go back and make changes.

Thanks a lot.


All times are GMT. The time now is 11:37 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01403 seconds
  • Memory Usage 1,711KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete