Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old September 3rd, 2003, 04:50 AM
AeroWing AeroWing is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: USA
Posts: 2 AeroWing User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Need help with links from data returned from DB

I need help with this I am about to pull my hair out!. OK I have my code set up to display like I want it, but now I have come across a new problem. I am going to make it so that when you click a team name, it will take you to an information page about that team. I am also going to make it so that when you click a players name, it takes you to a page about that player. Now my problem is, that it uses the index table to determine the ID at the end of the URL. BUT, The coaches index number must come from th coach table and the players index number must come from the players table, but since I did a left join for comparison reasons, it is querying both indexes wich creates a problem for my links! The only index I seem to be able to get results from is my coache table index, so my team links work fine. Here is an example of one of my player links:

php Code:
Original - php Code
  1. <td><a href="http://mysite/player_info.php?id=<?php echo $row_data['index']; ?>"><?php echo $row_data['player_name']; ?></a></td>


This method makes it link to the team page, since it is only recognising the coach index. I tried this:

php Code:
Original - php Code
  1. <td><a href="http://mysite/player_info.php?id=<?php echo $row_data['players.index']; ?>"><?php echo $row_data['player_name']; ?></a></td>


And when I do that, no number appears at the end. So I tried doing a seperate query for only the index of the player and when I do that, and change the link to reflect it, thet all just link to player.index 1 instead of linking to thier respective index number like they should. Here is most of my script:


php Code:
Original - php Code
  1. $query_data = "SELECT * FROM players left join coaches on players.index = coaches.index where players.avail = 'yes'ORDER BY coach_name";
  2. $data = mysql_query($query_data, $dbConnect) or die(mysql_error());
  3. $row_data = mysql_fetch_assoc($data);
  4. $totalRows_data = mysql_num_rows($data);
  5. ?>
  6. <html>
  7. <head>
  8. <title>Available Players</title>
  9. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  10. </head>
  11.  
  12. <body>
  13. <?php
  14. $last_coach_name = '';
  15. do {
  16. ?>
  17. <?php if ($row_data['coach_name'] != $last_coach_name) { ?>
  18.  <p><?php echo $row_data['subname']; ?><br>
  19.   <?php echo $row_data['city']; ?>, <?php echo $row_data['state']; ?><br>
  20.   Contact Name: <?php echo $row_data['contact_name']; ?> Telephone: <?php echo $row_data['contact_tel']; ?><br>
  21.   Email: <?php echo $row_data['lead_email']; ?> Fax: <?php echo $row_data['contact_fax']; ?></p>
  22. <?php }
  23. $last_coach_name = $row_data['coach_name'] ?>
  24. <table width="75%" border="0">
  25.   <tr bgcolor="#1C213D">
  26.     <td><font color="#FFFFFF">Player Name</font></td>
  27.     <td><font color="#FFFFFF">Hits</font></td>
  28.     <td><font color="#FFFFFF">Scores</font></td>
  29.     <td><font color="#FFFFFF">Outs</font></td>
  30.     <td><font color="#FFFFFF">Address</font></td>
  31.     <td><font color="#FFFFFF">Phone Number</font></td>
  32.     <td><font color="#FFFFFF">Available</font></td>
  33.   </tr>
  34.   <tr>
  35.     <td><?php echo $row_data['player_name']; ?></td>
  36.     <td><?php echo $row_data['hits']; ?></td>
  37.     <td><?php echo $row_data['scores']; ?></td>
  38.     <td><?php echo $row_data['out']; ?></td>
  39.     <td><?php echo $row_data['address']; ?></td>
  40.     <td><?php echo $row_data['lot']; ?></td>
  41.     <td><?php echo $row_data['phone']; ?></td>
  42.     <td><?php echo $row_data['avail']; ?></td>
  43.     </tr>
  44. </table>
  45. <?php } while ($row_data = mysql_fetch_assoc($data)); ?>
  46. <p></p>
  47. </body>
  48. </html>
  49. <?php
  50. ?> 


Also, I can't change the name of the index of either table.

Reply With Quote
  #2  
Old September 3rd, 2003, 11:17 AM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: Need help with links from data returned from DB

you need to specify the exact column names in the select statement and assign aliases instead of using * for example...

use.

select coaches.index as cid, players.index as pid,players.player_name from players left join coaches on players.index = coaches.index where players.avail = 'yes'ORDER BY coach_name";


this will give you the coaches index assignrd to cid nd the players index assigned to pid (of course you can add all the other fields you want to the select statement)

then you link would look like
php Code:
Original - php Code
  1.  
  2. <td><a href="http://mysite/player_info.php?id=<?php echo $row_data['pid']; ?>"><?php echo $row_data['player_name']; ?></a></td>


Hope that helps

Reply With Quote
  #3  
Old September 3rd, 2003, 01:36 PM
AeroWing AeroWing is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: USA
Posts: 2 AeroWing User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Need help with links from data returned from DB

Thank you soooo much I was afraid I was going to have to re-write it another way, That was major help

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Need help with links from data returned from DB


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT