TimUSA Posted January 16, 2008 Share Posted January 16, 2008 Everything is working with this now, but I want only one submit button. I tried moving it outside the loop but it stopped working then: global $scripturl , $context; echo' <a href="http://vsk-ayc.totalh.com/index.php?page=221">RETURN TO THE START PAGE</a><br> <table class = "bordercolor" cellSpacing="1" cellPadding="1" width="100%" border="0"> <tr class ="catbg"> <td width = "100%">Recent Race Reports:</td> </tr> </table> <form action="'.$scripturl.'?page=221'.$GET['page'].'" method="post"> <input id="submitted" name="submitted" type="hidden" value="TRUE" />'; $raceq = "SELECT race_table.raceID, race_table.raceDate, race_table.hostName, race_table.boatsInRace, race_table.seriesID, series_table.seriesName, race_table.factor , race_screenshots_table.imageURL, race_table.approved FROM race_table LEFT JOIN series_table ON race_table.seriesID = series_table.seriesID LEFT JOIN race_screenshots_table ON race_table.raceID = race_screenshots_table.raceID ORDER BY raceID DESC;"; $result = mysql_query($raceq); while($row = mysql_fetch_array($result)) { $raceID = $row['raceID']; echo '<br /> <table class="bordercolor" cellSpacing="1" cellPadding="1" width="100%" border="0"> <tr class ="catbg"> <td>Race ID:</td> <td>Date:</td> <td>Host Name:</td> <td>Boats:</td> <td>Series Name:</td> <td>Factor</td> <td>Image URL:</td> <td>Approved</td> </tr> <tr class="catbg4"> <td width="10%">' . $row['raceID'] . '</td> <td width="10%">' . $row['raceDate'] . '</td> <td width="20%">' . $row['hostName'] . '</td> <td width="10%">' . $row['boatsInRace'] . '</td> <td width="20%">' . $row['seriesName'] . '</td> <td width="5%">' . $row['factor'] . '</td> <td width="20%"> <a href="javascript:void(window.open(\'' . $row['imageURL'] .'\',\'\',\' resizable=yes,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no, fullscreen=no,dependent=no,width=1024,height=768\'))">VIEW IMAGE</a></td>'; if ($context['allow_admin'] AND $row['approved'] != "Yes") { echo' <td width = "5%"> <select id="approved" name="approved" style="WIDTH: 50px" value ="" /> <option value="Yes">Yes</option> <option value="No">No</option> </td> </tr> </table> <table class = "bordercolor" cellSpacing="1" cellPadding="1" width="100%" border="0"> <TR class ="windowbg3"> <td width = "20%">Skipper Name</td> <td width = "20%">Position</td> <td width = "20%">Race Points</td> <td width = "20%">Match Points</td> <td width = "20%">Fleet Points</td> </tr> </table>'; } else echo' <td width = "5%">' . $row['approved'] . '</td> </tr> </table> <table class = "bordercolor" cellSpacing="1" cellPadding="1" width="100%" border="0"> <TR class ="windowbg3"> <td width = "20%">Skipper Name</td> <td width = "20%">Position</td> <td width = "20%">Race Points</td> <td width = "20%">Match Points</td> <td width = "20%">Fleet Points</td> </tr> </table>'; $ptsq = "SELECT race_table.raceID , pts_table.skipperName, pts_table.position, pts_table.racePoints , pts_table.matchPoints , pts_table.fleetPoints FROM pts_table LEFT OUTER JOIN race_table ON pts_table.raceID = race_table.raceID WHERE race_table.raceID = '$raceID' GROUP BY pts_table.skipperName, race_table.raceID ORDER BY race_table.raceID, pts_table.racePoints DESC LIMIT 0 , 30;"; $result2 = mysql_query($ptsq); while($row2 = mysql_fetch_array($result2)) { echo' <TABLE class = "bordercolor" cellSpacing="1" cellPadding="1" width="100%" border="0"> <TR class ="windowbg3"> <TD width = "20%">' . $row2['skipperName'] . '</td> <TD width = "20%">' . $row2['position'] . '</td> <TD width = "20%">' . $row2['racePoints'] . '</td> <TD width = "20%">' . $row2['matchPoints'] . '</td> <TD width = "20%">' . $row2['fleetPoints'] . '</td> </tr> </table>'; } if ($context['allow_admin']) { echo' <br> <table class = "bordercolor" cellSpacing="1" cellPadding="1" width="100%" border="0"> <tr class ="catbg"> <td>Submit Approvals:</td> </tr> </table> <br> <table> <tr> <INPUT type="submit" value="Submit"><INPUT type="reset" value="Reset"> </tr> </table> </form>'; } if (isset($_POST['submitted']) and isset($_POST['approved'])) { $approved = mysql_real_escape_string($_POST['approved']); mysql_query ("UPDATE race_table SET approved = '$approved' WHERE raceID = '$raceID'") or die ("Could not execute query"); } } [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/86230-solved-last-problem-of-the-night/ Share on other sites More sharing options...
KrisNz Posted January 16, 2008 Share Posted January 16, 2008 Does this help, obviously i cant test it <?php global $scripturl , $context; //process postback if (isset($_POST['submitted']) and isset($_POST['approved'])) { //approved should be an array so you can update all your different records #$approved = mysql_real_escape_string($_POST['approved']); if (is_array($_POST['approved'])) { foreach ($_POST['approved'] as $raceID => $yesOrNo) { mysql_query ("UPDATE race_table SET approved = '$approved' WHERE raceID = '$raceID'") or die ("Could not execute query"); } } } //show the tables, what is $GET['page']??? it seems like this just posts back to the same //page so just make action="" echo' <a href="http://vsk-ayc.totalh.com/index.php?page=221">RETURN TO THE START PAGE</a><br> <table class = "bordercolor" cellSpacing="1" cellPadding="1" width="100%" border="0"> <tr class ="catbg"> <td width = "100%">Recent Race Reports:</td> </tr> </table> <form action="'.$scripturl.'?page=221'.$GET['page'].'" method="post"> <input id="submitted" name="submitted" type="hidden" value="TRUE" />'; $raceq = "SELECT race_table.raceID, race_table.raceDate, race_table.hostName, race_table.boatsInRace, race_table.seriesID, series_table.seriesName, race_table.factor , race_screenshots_table.imageURL, race_table.approved FROM race_table LEFT JOIN series_table ON race_table.seriesID = series_table.seriesID LEFT JOIN race_screenshots_table ON race_table.raceID = race_screenshots_table.raceID ORDER BY raceID DESC;"; $result = mysql_query($raceq); while($row = mysql_fetch_array($result)) { $raceID = $row['raceID']; echo '<br /> <table class="bordercolor" cellSpacing="1" cellPadding="1" width="100%" border="0"> <tr class ="catbg"> <td>Race ID:</td> <td>Date:</td> <td>Host Name:</td> <td>Boats:</td> <td>Series Name:</td> <td>Factor</td> <td>Image URL:</td> <td>Approved</td> </tr> <tr class="catbg4"> <td width="10%">' . $row['raceID'] . '</td> <td width="10%">' . $row['raceDate'] . '</td> <td width="20%">' . $row['hostName'] . '</td> <td width="10%">' . $row['boatsInRace'] . '</td> <td width="20%">' . $row['seriesName'] . '</td> <td width="5%">' . $row['factor'] . '</td> <td width="20%"> <a href="javascript:void(window.open(\'' . $row['imageURL'] .'\',\'\',\' resizable=yes,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no, fullscreen=no,dependent=no,width=1024,height=768\'))">VIEW IMAGE</a></td>'; $noSelected = 'selected="selected"'; if ($context['allow_admin'] AND $row['approved'] != "Yes") { $yesSelected =$noSelected; $noSelected = ''; //echo out the drop down box for this raceID - notice that its an array //using the unique id of the race as the key echo<<<EOF <td width = "5%"> <select id="approved" name="approved[$raceID]" style="WIDTH: 50px" value ="" /> <option $yesSelected value="Yes">Yes</option> <option $noSelected value="No">No</option> </td> </tr> </table> <table class = "bordercolor" cellSpacing="1" cellPadding="1" width="100%" border="0"> <TR class ="windowbg3"> <td width = "20%">Skipper Name</td> <td width = "20%">Position</td> <td width = "20%">Race Points</td> <td width = "20%">Match Points</td> <td width = "20%">Fleet Points</td> </tr> </table>; EOF; } else echo' <td width = "5%">' . $row['approved'] . '</td> </tr> </table> <table class = "bordercolor" cellSpacing="1" cellPadding="1" width="100%" border="0"> <TR class ="windowbg3"> <td width = "20%">Skipper Name</td> <td width = "20%">Position</td> <td width = "20%">Race Points</td> <td width = "20%">Match Points</td> <td width = "20%">Fleet Points</td> </tr> </table>'; $ptsq = "SELECT race_table.raceID , pts_table.skipperName, pts_table.position, pts_table.racePoints , pts_table.matchPoints , pts_table.fleetPoints FROM pts_table LEFT OUTER JOIN race_table ON pts_table.raceID = race_table.raceID WHERE race_table.raceID = '$raceID' GROUP BY pts_table.skipperName, race_table.raceID ORDER BY race_table.raceID, pts_table.racePoints DESC LIMIT 0 , 30;"; $result2 = mysql_query($ptsq); while($row2 = mysql_fetch_array($result2)) { echo' <TABLE class = "bordercolor" cellSpacing="1" cellPadding="1" width="100%" border="0"> <TR class ="windowbg3"> <TD width = "20%">' . $row2['skipperName'] . '</td> <TD width = "20%">' . $row2['position'] . '</td> <TD width = "20%">' . $row2['racePoints'] . '</td> <TD width = "20%">' . $row2['matchPoints'] . '</td> <TD width = "20%">' . $row2['fleetPoints'] . '</td> </tr> </table>'; } } //end of loop if ($context['allow_admin']) { echo' <br> <table class = "bordercolor" cellSpacing="1" cellPadding="1" width="100%" border="0"> <tr class ="catbg"> <td>Submit Approvals:</td> </tr> </table> <br> <table> <tr> <INPUT type="submit" value="Submit"><INPUT type="reset" value="Reset"> </tr> </table>'; } echo ' </form>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/86230-solved-last-problem-of-the-night/#findComment-440470 Share on other sites More sharing options...
TimUSA Posted January 16, 2008 Author Share Posted January 16, 2008 tested, and did not do the updates:( Quote Link to comment https://forums.phpfreaks.com/topic/86230-solved-last-problem-of-the-night/#findComment-440596 Share on other sites More sharing options...
KrisNz Posted January 16, 2008 Share Posted January 16, 2008 SET approved = '$approved' should be SET approved = '$yesOrNo'. Does the foreach loop get executed when you submit the form? do $raceID and $yesOrNo hold their expected values? Quote Link to comment https://forums.phpfreaks.com/topic/86230-solved-last-problem-of-the-night/#findComment-440625 Share on other sites More sharing options...
TimUSA Posted January 16, 2008 Author Share Posted January 16, 2008 I changed what you said above, and echoed out $raceID and $yesandNo returned the $raceID but not the other. if (is_array($_POST['approved'])) { foreach ($_POST['approved'] as $raceID => $yesOrNo) { echo $raceID; echo $yesorNo; and the full code: global $scripturl , $context; //process postback if (isset($_POST['submitted']) and isset($_POST['approved'])) { //approved should be an array so you can update all your different records #$approved = mysql_real_escape_string($_POST['approved']); if (is_array($_POST['approved'])) { foreach ($_POST['approved'] as $raceID => $yesOrNo) { echo $raceID; echo $yesorNo; mysql_query ("UPDATE race_table SET approved = '$yesorNo' WHERE raceID = '$raceID'") or die ("Could not execute query"); } } } //show the tables, what is $GET['page']??? it seems like this just posts back to the same //page so just make action="" echo' <a href="http://vsk-ayc.totalh.com/index.php?page=221">RETURN TO THE START PAGE</a><br> <table class = "bordercolor" cellSpacing="1" cellPadding="1" width="100%" border="0"> <tr class ="catbg"> <td width = "100%">Recent Race Reports:</td> </tr> </table> <form action="'.$scripturl.'?page=221'.$GET['page'].'" method="post"> <input id="submitted" name="submitted" type="hidden" value="TRUE" />'; $raceq = "SELECT race_table.raceID, race_table.raceDate, race_table.hostName, race_table.boatsInRace, race_table.seriesID, series_table.seriesName, race_table.factor , race_screenshots_table.imageURL, race_table.approved FROM race_table LEFT JOIN series_table ON race_table.seriesID = series_table.seriesID LEFT JOIN race_screenshots_table ON race_table.raceID = race_screenshots_table.raceID ORDER BY raceID DESC;"; $result = mysql_query($raceq); while($row = mysql_fetch_array($result)) { $raceID = $row['raceID']; echo '<br /> <table class="bordercolor" cellSpacing="1" cellPadding="1" width="100%" border="0"> <tr class ="catbg"> <td>Race ID:</td> <td>Date:</td> <td>Host Name:</td> <td>Boats:</td> <td>Series Name:</td> <td>Factor</td> <td>Image URL:</td> <td>Approved</td> </tr> <tr class="catbg4"> <td width="10%">' . $row['raceID'] . '</td> <td width="10%">' . $row['raceDate'] . '</td> <td width="20%">' . $row['hostName'] . '</td> <td width="10%">' . $row['boatsInRace'] . '</td> <td width="20%">' . $row['seriesName'] . '</td> <td width="5%">' . $row['factor'] . '</td> <td width="20%"> <a href="javascript:void(window.open(\'' . $row['imageURL'] .'\',\'\',\' resizable=yes,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no, fullscreen=no,dependent=no,width=1024,height=768\'))">VIEW IMAGE</a></td>'; $noSelected = 'selected="selected"'; if ($context['allow_admin'] AND $row['approved'] != "Yes") { $yesSelected =$noSelected; $noSelected = ''; //echo out the drop down box for this raceID - notice that its an array //using the unique id of the race as the key echo<<<EOF <td width = "5%"> <select id="approved" name="approved[$raceID]" style="WIDTH: 50px" value ="" /> <option $yesSelected value="Yes">Yes</option> <option $noSelected value="No">No</option> </td> </tr> </table> <table class = "bordercolor" cellSpacing="1" cellPadding="1" width="100%" border="0"> <TR class ="windowbg3"> <td width = "20%">Skipper Name</td> <td width = "20%">Position</td> <td width = "20%">Race Points</td> <td width = "20%">Match Points</td> <td width = "20%">Fleet Points</td> </tr> </table>; EOF; } else echo' <td width = "5%">' . $row['approved'] . '</td> </tr> </table> <table class = "bordercolor" cellSpacing="1" cellPadding="1" width="100%" border="0"> <TR class ="windowbg3"> <td width = "20%">Skipper Name</td> <td width = "20%">Position</td> <td width = "20%">Race Points</td> <td width = "20%">Match Points</td> <td width = "20%">Fleet Points</td> </tr> </table>'; $ptsq = "SELECT race_table.raceID , pts_table.skipperName, pts_table.position, pts_table.racePoints , pts_table.matchPoints , pts_table.fleetPoints FROM pts_table LEFT OUTER JOIN race_table ON pts_table.raceID = race_table.raceID WHERE race_table.raceID = '$raceID' GROUP BY pts_table.skipperName, race_table.raceID ORDER BY race_table.raceID, pts_table.racePoints DESC LIMIT 0 , 30;"; $result2 = mysql_query($ptsq); while($row2 = mysql_fetch_array($result2)) { echo' <TABLE class = "bordercolor" cellSpacing="1" cellPadding="1" width="100%" border="0"> <TR class ="windowbg3"> <TD width = "20%">' . $row2['skipperName'] . '</td> <TD width = "20%">' . $row2['position'] . '</td> <TD width = "20%">' . $row2['racePoints'] . '</td> <TD width = "20%">' . $row2['matchPoints'] . '</td> <TD width = "20%">' . $row2['fleetPoints'] . '</td> </tr> </table>'; } } //end of loop if ($context['allow_admin']) { echo' <br> <table class = "bordercolor" cellSpacing="1" cellPadding="1" width="100%" border="0"> <tr class ="catbg"> <td>Submit Approvals:</td> </tr> </table> <br> <table> <tr> <INPUT type="submit" value="Submit"><INPUT type="reset" value="Reset"> </tr> </table>'; } echo ' </form>'; Quote Link to comment https://forums.phpfreaks.com/topic/86230-solved-last-problem-of-the-night/#findComment-440673 Share on other sites More sharing options...
TimUSA Posted January 17, 2008 Author Share Posted January 17, 2008 bump Quote Link to comment https://forums.phpfreaks.com/topic/86230-solved-last-problem-of-the-night/#findComment-441595 Share on other sites More sharing options...
KrisNz Posted January 17, 2008 Share Posted January 17, 2008 this //you've closed your select tag and the select tag doesn't have a value attribute, only the options inside it do <select id="approved" name="approved[$raceID]" style="WIDTH: 50px" value ="" /> <option $yesSelected value="Yes">Yes</option> <option $noSelected value="No">No</option> should be <select id="approved" name="approved[$raceID]" style="WIDTH: 50px"> <option $yesSelected value="Yes">Yes</option> <option $noSelected value="No">No</option> </select> Quote Link to comment https://forums.phpfreaks.com/topic/86230-solved-last-problem-of-the-night/#findComment-441600 Share on other sites More sharing options...
TimUSA Posted January 17, 2008 Author Share Posted January 17, 2008 changed that, still no luck Quote Link to comment https://forums.phpfreaks.com/topic/86230-solved-last-problem-of-the-night/#findComment-441660 Share on other sites More sharing options...
KrisNz Posted January 17, 2008 Share Posted January 17, 2008 email me an export file of the relevant tables if you like so I can try it out... Quote Link to comment https://forums.phpfreaks.com/topic/86230-solved-last-problem-of-the-night/#findComment-441666 Share on other sites More sharing options...
TimUSA Posted January 17, 2008 Author Share Posted January 17, 2008 off to bed for now, but will send you a pm in the morning. Quote Link to comment https://forums.phpfreaks.com/topic/86230-solved-last-problem-of-the-night/#findComment-441668 Share on other sites More sharing options...
KrisNz Posted January 17, 2008 Share Posted January 17, 2008 note that the variable is $yesOrNo not $yesorNo (i.e the capital O) Quote Link to comment https://forums.phpfreaks.com/topic/86230-solved-last-problem-of-the-night/#findComment-441674 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.