Jump to content

Recommended Posts

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]

Link to comment
https://forums.phpfreaks.com/topic/86230-solved-last-problem-of-the-night/
Share on other sites

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>';
                


?>

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>';

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>

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.