table del stuff

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

table del stuff

Post by elecktricity »

I have a code like this:

Code: Select all

<input type='checkbox' name='val[]' value='table1-number1'>
<input type='checkbox' name='val[]' value='table1-number2'>
<input type='checkbox' name='val[]' value='table2-number4'>
<input type='checkbox' name='val[]' value='table6-number9'>
and on the next page have a query that updates it like this or something, im thinking like exploding it or something:

Code: Select all

$array = explode($table, "-", $number);
$query = "UPDATE $table SET number= '2' WHERE id='$number'";
or something like this, could somebody help me out? I think you can see what im trying to do
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

do a foreach or somtin

Code: Select all

foreach ($_POST['val'] as $value)
{
  $arr = explode('-', $value);
  //$arr[0] = table name and $arr[1] = number
  $sql = 'UPDATE '.$arr[0].' SET numer='2' WHERE id="'.$arr[1].'"';
  $query = mysql_query($sql) or die(mysql_error());
}
Post Reply