Jump to content

PHP Array list


rascle

Recommended Posts

Hi

I am using some code that i dont quite understand and i need some help

here is the code so far:

if(isset($_GET['box'])){
$box = $_GET['box'];
echo '<form name="edit" method="get">';
while(list($key,$val)= @each ($box)){
$rhys = mysql_query("SELECT * FROM games WHERE gamenumb = '$val'");

while($oldgame = mysql_fetch_array($rhys)){

echo'
<input type="hidden" value="'.$oldgame['gamenumb'].'" name="editcheck[]">
Game Name: <div id="addgameinput"><input type="text" size="100" maxlength="150" name="gamename" class="input1" value="'.$oldgame['text'].'"></div><br/>
<br/>
<hr/><br/>';
}
}
echo'<center><input type="submit" class="submit"></center></form>';
}else if(isset($_GET['editcheck'])){
$rhys = $_GET['editcheck'];
while(list($key,$val)= @each ($rhys)){
$rhys2 = $_GET['gamename'];
echo "$val <br/> $rhys2 <br/> ";
}
}else{
echo"<table border='1'>
<tr>
<td><form name='multiselect' method='get'></td>
</tr>
<tr>
<th>Check</th>
</tr>
";
$getgames = mysql_query("SELECT * FROM games ORDER BY `gamenumb`");
while($game = mysql_fetch_array($getgames)){
$id = $game['gamenumb'];
echo"<tr>";
echo '<td><input type="checkbox" name="box[]" value="'.$game['gamenumb'].'" class="check"></td>';
echo "<td>";
echo "</tr>";
}
echo "<tr><td><input type='submit' value='Edit'></form></td></tr>";
echo "</table>";
}

 

At the moment When i check the checkbox and click submit it will take me to the edit page and then i can make an edit click submit and go to a page which will use mysql to submit the data to a db, the only problem is, is that at the moment i can only seem to list the game number and not the edits that have been made to the game, to do this i would need to change something on the while loop where the list() is but i am not sure what to change it to.

Any Ideas?

Thanks

Rhys

 

Link to comment
https://forums.phpfreaks.com/topic/195134-php-array-list/
Share on other sites

THe only problem is is that on the code with

}else if(isset($_GET['editcheck'])){
$rhys = $_GET['editcheck'];
while(list($key,$val)= @each ($rhys)){
$rhys2 = $_GET['gamename'];
echo "$val <br/> $rhys2 <br/> ";
}

I cant get it to display all of the entries that have been editted, since i would need some kind of while loop that can display the arrays in - this i do not know how to do.

Thanks

Link to comment
https://forums.phpfreaks.com/topic/195134-php-array-list/#findComment-1025910
Share on other sites

When processing your checkboxes your code can be simplified and be much more efficient. So instead of this

while(list($key,$val)= @each ($box)){
$rhys = mysql_query("SELECT * FROM games WHERE gamenumb = '$val'");

while($oldgame = mysql_fetch_array($rhys)){

echo'
<input type="hidden" value="'.$oldgame['gamenumb'].'" name="editcheck[]">
Game Name: <div id="addgameinput"><input type="text" size="100" maxlength="150" name="gamename" class="input1" value="'.$oldgame['text'].'"></div><br/>
<br/>
<hr/><br/>';
}
}

 

You can do

    $ids = implode(',', $box);
    $rhys = mysql_query("SELECT * FROM games WHERE gamenumb IN ($ids)");
   
    while($oldgame = mysql_fetch_array($rhys))
    {
       echo'<input type="hidden" value="'.$oldgame['gamenumb'].'" name="editcheck[]">
Game Name: <div id="addgameinput"><input type="text" size="100" maxlength="150" name="gamename" class="input1" value="'.$oldgame['text'].'"></div><br/>
<br/>
<hr/><br/>';
    }

Link to comment
https://forums.phpfreaks.com/topic/195134-php-array-list/#findComment-1025931
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.