Loop through Arrays?
Moderator: General Moderators
Loop through Arrays?
How would you loop through the array, in yo,ur update code.
Here is the code for the table...
I want to be able to select the checkbox, and based on the rows selected it will update those records when I run the UPDATE script.
Thanks :
Code: Select all
<td align="center" valign="middle" class="style16"><input name="isSelected" type="checkbox" id="isSelected" value="checkbox"></td>
<td class="style16"><?php echo $row_Log_Displayї'date_created']; ?></td>
<td class="style16"><?php echo $row_Log_Displayї'event']; ?></td>
<td class="style16"><?php echo $row_Log_Displayї'region']; ?></td>
<td class="style16"><?php echo $row_Log_Displayї'quanity_sets']; ?> Sets of <?php echo $row_Log_Displayї'quanity_each']; ?> Each </td>
<td><span class="style16"><?php echo $row_Log_Displayї'size']; ?> <?php echo $row_Log_Displayї'sort']; ?></span></td>
<td><span class="style16"><?php echo $row_Log_Displayї'description']; ?></span></td>
<td class="style16"><span class="style16 style19"><span class="style21"><?php echo $row_Log_Displayї'status']; ?></span></span></td>Code: Select all
<input name="isSelected" type="checkbox" id="isSelected" value="checkbox">Thanks :
- scorphus
- Forum Regular
- Posts: 589
- Joined: Fri May 09, 2003 11:53 pm
- Location: Belo Horizonte, Brazil
- Contact:
There are good bits and pieces of information on this post. Behold the DevNetwork Forums!
Well, you better change the name and value of the checkboxes to something like:amdorsey wrote:(...) I want to be able to select thecheckbox, and based on the rows selected it will update those records when I run the UPDATE script. (...)Code: Select all
<input name="isSelected" type="checkbox" id="isSelected" value="checkbox">
Code: Select all
<input name="isSelected[]" type="checkbox" id="isSelected" value="<?php echo $row_identifier ;?>">Couple questions. What kind of update will be going on? You are going to update rows with new information, where will it come from?
-- Scorphus
This is the whole page...Form and All.
I want to update the status of multipler checked rows in my query display. So the page before this one the user sorts out info from the database. I want them to be able to update 1 column in the table (status) So I have one pulldown menu with different "status" values, and I wan't that value to be substituted into all of the rows that have been checked.
I hope this explains my scenario a little better.
Code: Select all
<form action="<?php echo $editFormAction; ?>" method="POST" name="Status_Update" id="Status_Update">
<table width="100%" height="30" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
<tr bgcolor="#FFFFFF">
<td align="left" valign="middle" class="style1"><?php echo ("$titleName"); ?> Signs Manager <span class="style23">- <?php echo ("$displayDate"); ?></span></td>
</tr>
</table>
<br>
<table width="100%" border="0" cellpadding="10" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="50%" align="left" valign="middle" bgcolor="#F2F2F2" class="style16 style19">Change Status to:
<select name="status" class="style16" id="status">
<option selected>Status...</option>
<option value="Just Added">Just Added</option>
<option value="Pending Approval">Pending Approval</option>
<option value="Approved and Printing">Approved and Printing</option>
<option value="Completed">Completed</option>
</select>
<input name="Submit" type="submit" class="style16" value="Update Sign Status">
</td>
<td width="50%" align="left" valign="middle" bgcolor="#F2F2F2" class="style16">You have selected a total of <span class="style18 style25"><?php echo $totalRows_Log_Display ?></span> Signs.</td>
</tr>
</table>
<br>
<table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#CCCCCC">
<tr align="left" valign="middle" bgcolor="#E6E6E6">
<td><span class="style18">Select</span></td>
<td><span class="style18">Date /Time Added </span></td>
<td><span class="style18">Event</span></td>
<td bgcolor="#E6E6E6"><span class="style18">Region</span></td>
<td><span class="style18">Quanity</span></td>
<td><span class="style18"> Sign </span></td>
<td><span class="style18">Description</span></td>
<td><span class="style18">Status</span></td>
</tr>
<?php $count=0; ?>
<?php do { ?>
<?php
$count++;
if(($count % 2) == 1){
$background = "#ffffff";
} else {
$background = "#F4F4F4";
}
?>
<tr align="left" valign="middle" bgcolor="<?php echo $background; ?>">
<td align="center" valign="middle" class="style16"> <input name="id" type="hidden" id="id" value="<?php echo $row_Log_Displayї'id']; ?>"> </td><td class="style16"><?php echo $row_Log_Displayї'date_created']; ?></td>
<td class="style16"><?php echo $row_Log_Displayї'event']; ?></td>
<td class="style16"><?php echo $row_Log_Displayї'region']; ?></td>
<td class="style16"><?php echo $row_Log_Displayї'quanity_sets']; ?> Sets of <?php echo $row_Log_Displayї'quanity_each']; ?> Each </td>
<td><span class="style16"><?php echo $row_Log_Displayї'size']; ?> <?php echo $row_Log_Displayї'sort']; ?></span></td>
<td><span class="style16"><?php echo $row_Log_Displayї'description']; ?></span></td>
<td class="style16"><span class="style16 style19"><span class="style21"><?php echo $row_Log_Displayї'status']; ?></span></span></td>
</tr>
<?php } while ($row_Log_Display = mysql_fetch_assoc($Log_Display)); ?>
</table>
<input type="hidden" name="MM_update" value="Status_Update">
</form>I hope this explains my scenario a little better.
- scorphus
- Forum Regular
- Posts: 589
- Joined: Fri May 09, 2003 11:53 pm
- Location: Belo Horizonte, Brazil
- Contact:
Nice! As I said above, change the name and value of the checkbox:
and write it in place of that hidden filed. This way you'll get an item in $_POST['isSelected'] holding a row ID for each marked checkbox. Then, in the form's action= page, do something like this:
References:
[php_man]foreach[/php_man]
[php_man]mysql_affected_rows[/php_man]
Regards,
Scorphus.
Code: Select all
<input name="isSelected[]" type="checkbox" id="isSelected" value="<?php echo $row_Log_Display['id']; ?>">Code: Select all
<?php
$newStatus = $_POST['status'];
foreach ($_POST['isSelected'] as $id) {
$sql = "UPDATE Log_Display SET status = '$status' WHERE id = $id";
mysql_query($sql) or die('Query error! ' . mysql_error());
}
?>[php_man]foreach[/php_man]
[php_man]mysql_affected_rows[/php_man]
Regards,
Scorphus.
- scorphus
- Forum Regular
- Posts: 589
- Joined: Fri May 09, 2003 11:53 pm
- Location: Belo Horizonte, Brazil
- Contact:
Or better yet:
-- Scorphus
Code: Select all
<?php
$newStatus = $_POST['status'];
$values = implode(', ', $_POST['isSelected']);
$sql = "UPDATE Log_Display SET status = '$status' WHERE id IN ($values)";
mysql_query($sql) or die('Query error! ' . mysql_error());
?>- scorphus
- Forum Regular
- Posts: 589
- Joined: Fri May 09, 2003 11:53 pm
- Location: Belo Horizonte, Brazil
- Contact:
Sure it is a cross post. Thanks, ol4pr0. Could some moderator please lock the other thread?
-- Scorphus
-- Scorphus