Jump to content

Checkbox While Loop


rascle

Recommended Posts

Hi

I am creating a page which shows a list of all the data i have on a mysql table.

I want to be able to edit the data, and so i have made that, but at the moment i would have to edit them individually and this can take a long time especially with a slow internet connection, so i have added some checkboxes to the paeg and i would like to be able to select the checkboxes and then when i press the edit button all of the rows i have check selected will appear so that i can edit them without having to do this individually.

I know this will need a while loop on the edit page, but i am not sure what to do about sending the values of what checkboxes are selected. For example if i have a table like:

Name      Age      Location

John        36        Wales

Rhys          52      England

Stephen    75        Scotland

Brian        22        Ireland

 

and then the page displays these with a check box:

Checked    Name      Age      Location

yes            john        36        Wales

no              Rhys          52      England

yes            Stephen    75        Scotland

yes            Brian        22        Ireland

 

Edit

 

and then i edit it, i want John, Stephen and Brian rows to all appear on the edit.php page because i have selected them, but i am not sure how to tell the computer that i have sent them ones???

Any ideas.

 

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/194254-checkbox-while-loop/
Share on other sites

Sorry i cant get that to work.

 

Here is the code:

//FOR THE EDIT SECTION:


<?php
if(isset($_GET['edit'])){
//EDIT THE GAME DETAILS THROUGH THE ID CONNECTING TO THE DB
$id = $_GET['id'];
if($id == "ALL"){
echo "We are having problems.";
}else{
$oldgame = mysql_query("SELECT * FROM games WHERE `gamenumb` = '$id'");
$oldgame = mysql_fetch_array($oldgame);
echo'<form name="editdetails" method="get" action="gamestatus.php">
<input type="hidden" name="editdetails">
<input type="hidden" name="id" value="'.$id.'"><br/>
Game Name: <div id="addgameinput"><input type="text" size="100" maxlength="150" name="gamename" class="input1" value="'.$oldgame['text'].'"></div><br/>
Game Description: <div id="addgameinput"><input type="text" size="100" maxlength="1500" name="description" class="input1" value="'.$oldgame['description'].'"></div><br/>
Game Picture: <div id="addgameinput"><input type="text" size="100" maxlength="150" name="gamepicture" class="input1" value="'.$oldgame['picture'].'"></div><br/>
Game SWF: <div id="addgameinput"><input type="text" size="100" maxlength="150" name="gameswf" class="input1" value="'.$oldgame['gameswf'].'"></div><br/>
Game SWF Backup: <div id="addgameinput"><input type="text" size="100" maxlength="150" name="gameswfbackup" class="input1" value="'.$oldgame['backup'].'"></div><br/>
Game Type: <div id="addgameinput"> ';
echo"<select size='1' style='width:190px' name='type' class='input1' value='".$oldgame['gametype']."'> </div>
<option value='Action' "; if($oldgame['gametype'] == "Action") {  
echo "selected"; }  
echo ">Action</option> 
<option value='Arcade' "; if($oldgame['gametype'] == "Arcade") {  
echo "selected"; }  
echo ">Arcade</option> 
<option value='Puzzle' "; if($oldgame['gametype'] == "Puzzle") {  
echo "selected"; }  
echo ">Puzzle</option> 
<option value='Racing' "; if($oldgame['gametype'] == "Racing") {  
echo "selected"; }  
echo ">Racing</option> 
<option value='Sport' "; if($oldgame['gametype'] == "Sport") {  
echo "selected"; }  
echo ">Sport</option> 
</select>";  
echo'</div><br/>
<br/>
<center><input type="submit" value="Edit Game Details" class="submit"></center>';
}
}

//AND NO THE MAIN PART YOU SEE WHEN YOU VIEW THE PAGE:

else{
//Have all games in rows, along with small picture icon, so we know it is working as well as game name, id, reported{ reported by }, 
echo"<table border='1'>
<tr>
<th>Check</th>
<th>Flagged </th>
<th>Reported By</th>
<th>Image</th>
<th>Game Name </th>
<th>Game Type </th>
<th>Game SWF </th>
<th>Game Backup </th>
<th>Hits</th>
<th>Rascle's</th>
<th>Size</th>
<th>Action</th>
</tr>
";
$getgames = mysql_query("SELECT * FROM games ORDER BY `gamenumb`");
while($game = mysql_fetch_array($getgames)){
$id = $game['gamenumb'];
if($game['reported'] == "broken"){
echo '<tr bgcolor="#666666">';
}else{
echo "<tr>";
}
echo '<td><input type="checkbox" name="'.$game['gamenumb'].'checked" class="check"></td>';
echo "<td>";
if($game['reported'] == "reported"){
//FLAG IF GAME IS REPORTED BROKEN
echo '<img src="/webimages/alerts.gif " alt="Flagged - Reported">';
}
else if($game['reported'] == "broken"){
echo '<img src="/webimages/delete.png" alt="Flagged - Broken">';
}
else{
//TO SHOW BORDER ADD A SPACE INTO IT
echo ' ';
}
echo "</td>";
echo '<td> '.$game['reportedby'].'</td>';
echo '<td><img src="'.$game['picture'].'" width="50" height="50"></td>';
echo '<td><a href="playgames.php?id='.$game['gamenumb'].'">'.$game['text'].'</a></td>';
echo '<td>'.$game['gametype'].'</td>';
echo '<td> '.$game['gameswf'].'</td>';
echo '<td>'.$game['backup'].'</td>';
echo '<td>'.$game['hits'].'</td>';
echo '<td>'.$game['rascles'].'</td>';
echo '<td>'.$game['size'].'</td>';
echo '<td> <a href="gamestatus.php?default&id='.$id.'" onclick="return confirm(\'Are you sure you want to Default? Click Ok to proceed and Default or Cancel if you do not want to default!\');"><img src="/webimages/edit.png" alt="Default The Game SWF" border="0" ></a><a href="gamestatus.php?edit&id='.$id.'" onclick="return confirm(\'Are you sure you want to Edit? Click Ok to proceed and Edit or Cancel if you do not want to Edit!\');"><img src="/webimages/blogsearch2.gif" alt="Edit Game Details" width="20" height="20"border="0"></a><a href="gamestatus.php?clear&id='.$id.'" onclick="return confirm(\'Are you sure you want to Clear? Click Ok to proceed and Clear or Cancel if you do not want to Clear!\');"><img src="/webimages/broom.png" alt="Clear Flagged" width="20" height="20"border="0"></a><a href="gamestatus.php?hitreset&id='.$id.'" onclick="return confirm(\'Are you sure you want to Reset Hitcounter? Click Ok to proceed and Reset or Cancel if you do not want to reset!\');"><img src="/webimages/undo.png" alt="Reset Hitcounter"border="0"width="20" height="20"></a><a href="gamestatus.php?rasclereset&id='.$id.'" onclick="return confirm(\'Are you sure you want to Reset Rascle Counter? Click Ok to proceed and Reset or Cancel if you do not want to reset!\');"><img src="/webimages/resetrasclecounter.png" alt="Reset Rascle Counter"border="0"width="20" height="20"></a><a href="gamestatus.php?delete&id='.$id.'" onclick="return confirm(\'Are you sure you want to Delete? Click Ok to proceed and Delete or Cancel if you do not want to delete!\');"><img src="/webimages/delete.png" alt="Delete Post"border="0"></a> ';

echo "</tr>";
}
echo "<tr>";
echo '
<td>ALL GAMES</td>
<td><a href="gamestatus.php?default&id=ALL" onclick="return confirm(\'Are you sure you want to Default? Click Ok to proceed and Default or Cancel if you do not want to default!\');"><img src="/webimages/edit.png" alt="Default The Game SWF"border="0"></a><a href="gamestatus.php?edit&id=ALL" onclick="return confirm(\'Are you sure you want to Edit? Click Ok to proceed and Edit or Cancel if you do not want to Edit!\');"><img src="/webimages/blogsearch2.gif" alt="Edit Game Details" width="20" height="20"border="0"></a><a href="gamestatus.php?clear&id=ALL" onclick="return confirm(\'Are you sure you want to Clear? Click Ok to proceed and Clear or Cancel if you do not want to Clear!\');"><img src="/webimages/broom.png" border="0"alt="Clear Flagged" width="20" height="20"></a><a href="gamestatus.php?hitreset&id=ALL" onclick="return confirm(\'Are you sure you want to Reset Hitcounter? Click Ok to proceed and Reset or Cancel if you do not want to reset!\');"><img src="/webimages/undo.png" alt="Reset Hitcounter"border="0"width="20" height="20"></a><a href="gamestatus.php?rasclereset&id=ALL" onclick="return confirm(\'Are you sure you want to Reset Rascle Counter? Click Ok to proceed and Reset or Cancel if you do not want to reset!\');"><img src="/webimages/resetrasclecounter.png" alt="Reset Hitcounter"border="0"width="20" height="20"></a><a href="gamestatus.php?delete&id=ALL" onclick="return confirm(\'Are you sure you want to Delete? Click Ok to proceed and Delete or Cancel if you do not want to delete!\');"><img src="/webimages/delete.png" alt="Delete Post"border="0"></a> </td>';
echo "</tr>";
echo "</table>";


}



 

How could i integrate it into that???

Thanks

Link to comment
https://forums.phpfreaks.com/topic/194254-checkbox-while-loop/#findComment-1021942
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.