TryingHard Posted May 20, 2012 Share Posted May 20, 2012 Hi guy's looking for some help on a project I have going on- I am using this code as my query in mysql- <?php // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $week=$_REQUEST['week']; $sql=mysql_query("SELECT team ,SUM(team_score) AS total_score FROM (SELECT away AS team ,score_away AS team_score FROM $tbl_name WHERE week='$week' UNION ALL SELECT home AS team ,score_home AS team_score FROM $tbl_name WHERE week='$week') AS u GROUP BY team")or die(mysql_error()); ?> <form name="form2" method="post" action="update4.php"> <?php while($rows=mysql_fetch_array($sql)){ ?> <td><? echo $rows['team']; ?></td> <td align="center"><input name="totalscore[]" type="text" value="<? echo $rows['total_score']; ?>"></td><br /> <? } ?> THE RESULTS ARE: Angels 12 Astros 15 Athletics 24 Blue Jays 15 Braves 22 Brewers 18 etc.... My question is 2 parts- 1st- How do I assign an ID to either the team or the total_score so I can pass the values over to a processing form? or 2nd- I already have a table set up in my database that holds the team names called 'teams', How do I pull the pull the column 'tid' from a 'teams' so that when the results from the query above display it will display the 'tid' that corresponds with the teams listed in the away or home columns of the first table 'content'. The results of the query are exactly what I need but I need to be able to display the info into a table for each team and thats where the headache comes in. Any thoughts. I've been researching arrays and values all morning and have decided to ask the experts. Please let me know if you need to see more structure. Hope everything is clear. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/262838-assigning-ids-to-result-array/ Share on other sites More sharing options...
fenway Posted May 21, 2012 Share Posted May 21, 2012 1st) don't follow. 2nd) a JOIN. Following the posting rules will help. Quote Link to comment https://forums.phpfreaks.com/topic/262838-assigning-ids-to-result-array/#findComment-1347437 Share on other sites More sharing options...
TryingHard Posted May 24, 2012 Author Share Posted May 24, 2012 Sorry for that I was not even sure what is was that I was looking for and finally came across a solution...thanks for your time and I aplogize for the rule violation, I was exhausted when posting that I did not mean to disregard them. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/262838-assigning-ids-to-result-array/#findComment-1348441 Share on other sites More sharing options...
Kays Posted May 25, 2012 Share Posted May 25, 2012 1. A hidden input field next to each entry should work. 2. JOIN Quote Link to comment https://forums.phpfreaks.com/topic/262838-assigning-ids-to-result-array/#findComment-1348508 Share on other sites More sharing options...
fenway Posted May 27, 2012 Share Posted May 27, 2012 Sorry for that I was not even sure what is was that I was looking for and finally came across a solution...thanks for your time and I aplogize for the rule violation, I was exhausted when posting that I did not mean to disregard them. Thanks again. Please post your solution. Quote Link to comment https://forums.phpfreaks.com/topic/262838-assigning-ids-to-result-array/#findComment-1348957 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.