•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 423,532 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,340 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1731 | Replies: 3
![]() |
•
•
Join Date: Oct 2007
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
hi, my name is amin
this is output array $_POST
code php & sql
output
how i can get siri = 1001 and siri = 1002 and ....
this is output array $_POST
Array
(
[status_batch] => Array
(
[1001] => Verify
[1002] => Verify
[2001] => Verify
[2002] => Belum Batch
[2003] => Belum Batch
[2004] => Belum Batch
[2005] => Belum Batch
[2006] => Belum Batch
[2007] => Belum Batch
[2008] => Belum Batch
[2009] => Belum Batch
[1201] => Belum Batch
[1202] => Belum Batch
[2201] => Belum Batch
[2202] => Belum Batch
[2203] => Belum Batch
[1101] => Belum Batch
[2101] => Belum Batch
[2102] => Belum Batch
[2103] => Belum Batch
[2104] => Belum Batch
[2105] => Bersih
[2106] => Belum Batch
[2107] => Belum Batch
[2108] => Belum Batch
)
[jadual] => kawalan
[update] => update
)code php & sql
$i=0;
foreach ($_POST[status_batch] as $papar)
{
$myTable = $_POST[jadual];
//-------------------------------------------------------------------------------
$sql = "SELECT status_batch FROM ".$myTable." "; //echo "<hr><pre>$sql</pre><hr>";
$result = mysql_query($sql) or die(mysql_error()."<hr>$query<hr>");
$fields = mysql_num_fields ($result) or die("Num Fields Failed/ Nama Medan Takde");
$akhir=$fields-1;
//-------------------------------------------------------------------------------
########################################################################
$ubah = " UPDATE $myTable SET \r";
for ( $f = 0 ; $f < $fields ; $f++ )
{
$medan = mysql_field_name($result,$f);
$ubah.=($f==$akhir) ? " $medan='$papar' \r":" $medan='$papar', \r";
}
$ubah.= " WHERE siri = '".$_POST[status_batch][$i++]."'
and ".$_POST[status_batch]." = '".$_POST[status_batch]."'
";
########################################################################
echo "<pre>$ubah</pre><hr>";
//$result = mysql_query($ubah);
//header('Location:../sk/batch_sk.php?jadual=kawalan&item=10');
}
output
0) UPDATE kawalan SET status_batch='Verify' WHERE siri = '' and Array = 'Array' 1) UPDATE kawalan SET status_batch='Verify' WHERE siri = '' and Array = 'Array' 2) UPDATE kawalan SET status_batch='Verify' WHERE siri = '' and Array = 'Array' 3) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 4) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 5) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 6) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 7) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 8) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 9) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 10) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 11) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 12) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 13) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 14) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 15) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 16) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 17) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 18) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 19) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 20) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 21) UPDATE kawalan SET status_batch='Bersih' WHERE siri = '' and Array = 'Array' 22) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 23) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array' 24) UPDATE kawalan SET status_batch='Belum Batch' WHERE siri = '' and Array = 'Array'
how i can get siri = 1001 and siri = 1002 and ....
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
php Syntax (Toggle Plain Text)
WHERE siri = '".$_POST[status_batch][$i++]."' and ".$_POST[status_batch]." = '".$_POST[status_batch]."'
php Syntax (Toggle Plain Text)
$arr=$_POST['status_batch']; for ( $f = 0 ; $f < $fields ; $f++ ) { echo $arr[$f]; //...
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Nov 2007
Location: Las Vegas, Nevada
Posts: 83
Reputation:
Rep Power: 1
Solved Threads: 14
as nav33n pointed out, there are other issues going on in this script, but if you change your code like so, you should get the siri=xxx as you wanted...
php Syntax (Toggle Plain Text)
foreach ($_POST[status_batch] as $key=> $papar) { $myTable = $_POST[jadual]; //------------------------------------------------------------------------------- $sql = "SELECT status_batch FROM ".$myTable." "; //echo "<hr><pre>$sql</pre><hr>"; $result = mysql_query($sql) or die(mysql_error()."<hr>$query<hr>"); $fields = mysql_num_fields ($result) or die("Num Fields Failed/ Nama Medan Takde"); $akhir=$fields-1; //------------------------------------------------------------------------------- ######################################################################## $ubah = " UPDATE $myTable SET \r"; for ( $f = 0 ; $f < $fields ; $f++ ) { $medan = mysql_field_name($result,$f); $ubah.=($f==$akhir) ? " $medan='$papar' \r":" $medan='$papar', \r"; } $ubah.= " WHERE siri = '".$key."' and ".$_POST[status_batch]." = '".$_POST[status_batch]."' ";
•
•
Join Date: Oct 2007
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
as nav33n pointed out, there are other issues going on in this script, but if you change your code like so, you should get the siri=xxx as you wanted...
php Syntax (Toggle Plain Text)
foreach ($_POST[status_batch] as $key=> $papar) { $myTable = $_POST[jadual]; //------------------------------------------------------------------------------- $sql = "SELECT status_batch FROM ".$myTable." "; //echo "<hr><pre>$sql</pre><hr>"; $result = mysql_query($sql) or die(mysql_error()."<hr>$query<hr>"); $fields = mysql_num_fields ($result) or die("Num Fields Failed/ Nama Medan Takde"); $akhir=$fields-1; //------------------------------------------------------------------------------- ######################################################################## $ubah = " UPDATE $myTable SET \r"; for ( $f = 0 ; $f < $fields ; $f++ ) { $medan = mysql_field_name($result,$f); $ubah.=($f==$akhir) ? " $medan='$papar' \r":" $medan='$papar', \r"; } $ubah.= " WHERE siri = '".$key."' and ".$_POST[status_batch]." = '".$_POST[status_batch]."' ";
ooo, i want to say thank you johnsquibb and nav33n
$_POST[status_batch] as $key=> $papar
must use $key , but this $_POST is multiarray
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Shopping Cart Not Working (ASP.NET)
- looping to insert event types into schedule (PHP)
- serious problem..in online examination ..plz solve that as soon as possible (JavaScript / DHTML / AJAX)
- Schedule Repeat events (PHP)
- Store multiple selection from pagination info into single array (PHP)
- Variable passed to each() is not an array (PHP)
- Trying to update entire column in database (PHP)
- The mysterious errors of PHP (PHP)
- Storing dynamic form values in Arrays for display & insert (PHP)
- This ought to be simple - extra spaces (PHP)
Other Threads in the PHP Forum
- Previous Thread: Populating a MySQL table with data from a csv file
- Next Thread: FCKeditor



Linear Mode