You are welcome. :)
You may know about foreach here.
Make Check Button
Collapse
X
-
i was mistake with double quote... :)Originally posted by hsriatAnd what was the fault?
the first i was dont know that one quote is as a string. now i know it ... .
:)
thank you hsriat.... one thing again...
can you explain me...
what is $key=>$selected _id meaning?Code:foreach($_POST[checkbox] as $key=>$selected_id)
can you give me a link that explain this?
thank you...for your help....Leave a comment:
-
And what was the fault?Originally posted by wiresharkthank you hsriat... that was really helpful. Very glad you help me... :)
now i know where my fault... have the answer now... :)Leave a comment:
-
thank you hsriat... that was really helpful. Very glad you help me... :)Originally posted by hsriatYou have a syntax mistake. Use double quotes instead of single.
Use this..or use this..Code:<td><input type=\"checkbox\" name=\"checkbox[]\" value=\"".$row[id_Customer]."\" ></input></td>
If a string starts with double quote, it ends with double quote only. Single quote is then just treated as a part of the string, but not an operator.Code:<td><input type='checkbox' name='checkbox[]' value='".$row[id_Customer]."' ></input></td>
now i know where my fault... have the answer now... :)Leave a comment:
-
You have a syntax mistake. Use double quotes instead of single.
Use this..or use this..Code:<td><input type=\"checkbox\" name=\"checkbox[]\" value=\"".$row[id_Customer]."\" ></input></td>
If a string starts with double quote, it ends with double quote only. Single quote is then just treated as a part of the string, but not an operator.Code:<td><input type='checkbox' name='checkbox[]' value='".$row[id_Customer]."' ></input></td>
Leave a comment:
-
i have write it like this...Originally posted by hsriatTry this...[php]
<?
include("test.p hp");
mysql_select_db ("a2840013_Data base",$cipai) or die ("Cannot Connect At Delete Form");
$not_deleted = array(); //TO SAVE DELETED IDS
foreach($_POST[checkbox] as $key=>$selected _id)
{
if (!mysql_query(" DELETE FROM `customer` WHERE `id_Customer` = '".$selected_id ."'"))
array_push($not _deleted, $selected_id);
}
echo "Successful ly deleted:<br/>".implode(", ", array_diff($_PO ST[checkbox], $not_deleted));
if (count($not_del eted)>0)
echo "<br/>Unable to delete:<br/>".implode(", ", $not_deleted);
?>
[/php]
[php]
<?
include("test.p hp");
mysql_select_db ("a2840013_Data base",$cipai) or die ("Cannot Connect At Delete Form");
$not_deleted = array();
foreach($_POST[checkbox] as $key=>$selected _id)
{
if (!mysql_query(" DELETE FROM customer WHERE id_Customer = '".$selected_id ."'"))
array_push($not _deleted, $selected_id);
}
echo "Successful ly deleted:<br/>".implode(", ", array_diff($_PO ST[checkbox], $not_deleted));
if (count($not_del eted)>0)
echo "<br/>Unable to delete:<br/>".implode(", ", $not_deleted);
?>
[/php]
but the result is... Successfully deleted: and with "," in the new line...
if i try delete 3 record then ",," just like that...or maybe in my delete.php something wrong? this is the code
[php]
<?
echo "<form method='POST' action='del_cus t.php'>";
while($row=mysq l_fetch_assoc($ result)){
echo "<table width ='100%'+ border='1'>";
echo "
<tr>
<td><input type='checkbox' name='checkbox[]' value=''.$row[id_Customer].''></input></td>
<td width = '10%'> $row[id_Customer] </td>
<td width = '30%'> $row[Nama_Customer] </td>
<td width = '20%'> $row[Alamat] </td>
<td width = '10%'> $row[Kota] </td>
<td width = '20%'> $row[C_Person] </td>
<td width = '5%'align='cent er'> $row[Nom] </td>
</tr>
</table>";
}
echo "<input type='submit' value='Submit' name='submit'>" ;
echo "</br><input type='text' name='nomdat'>" ;
echo"</form>";
$Te =mysql_num_rows ($result);
echo "<b><font color='blue'><h 3> Jumlah Record Customer Tersimpan= $Te </h3></b></font>";
?>
[/php]
thank you for all your help...Leave a comment:
-
Try this...[php]
<?
include("test.p hp");
mysql_select_db ("a2840013_Data base",$cipai) or die ("Cannot Connect At Delete Form");
$not_deleted = array(); //TO SAVE DELETED IDS
foreach($_POST[checkbox] as $key=>$selected _id)
{
if (!mysql_query(" DELETE FROM `customer` WHERE `id_Customer` = '".$selected_id ."'"))
array_push($not _deleted, $selected_id);
}
echo "Successful ly deleted:<br/>".implode(", ", array_diff($_PO ST[checkbox], $not_deleted));
if (count($not_del eted)>0)
echo "<br/>Unable to delete:<br/>".implode(", ", $not_deleted);
?>
[/php]Leave a comment:
-
thanks for reply,did you mean like this? still have the same result. my primary is id_Customer.Originally posted by hsriatRun delete query with primary key.
If primary key is Nom, replace customer_id with Nom in id of checkbox, else replace Nom with customer_id.
Code:<? include("test.php"); mysql_select_db("a2840013_Database",$cipai) or die ("Cannot Connect At Delete Form"); foreach($_POST[checkbox] as $key=>$selected_id) { echo "$selected_id"; mysql_query("DELETE FROM customer WHERE id_Customer = '{$selected_id}'") or die ("Cannot Delete"); echo "$selected_id successfully deleted! <br /> \n"; }; ?>Leave a comment:
-
Run delete query with primary key.
If primary key is Nom, replace customer_id with Nom in id of checkbox, else replace Nom with customer_id.Leave a comment:
-
thanks for reply... but i dont still get it.. can u help me again? :)Originally posted by markusn00bI think, in your foreach loop, youre in need of a delete query. And you want Nom to be how you select the row?
(sorry for jumping in on this hsriat - im bored =/)
Try adding this (you might have to change the tbl_name - well, there's no 'might' about it... you will have to change it)
[php]
foreach($.... )
{
mysql_query("DE LETE FROM `tbl_name` WHERE `Nom` = '{$selected_id} '"
or die(mysql_error ());
echo "$selected_ id successfully deleted! <br /> \n";
}
[/php]
Hope this helps :)
this is what i wrote down...the result is "successful ly deleted !" but it not delete anything.Code:<? include("test.php"); mysql_select_db("a2840013_Database",$cipai) or die ("Cannot Connect At Delete Form"); foreach($_POST[checkbox] as $key=>$selected_id) { mysql_query("DELETE FROM customer WHERE Nom = '{$selected_id}'") or die ("Cannot Delete"); echo "$selected_id successfully deleted! <br /> \n"; }; ?>
can u show me again,what must i correct in my script? thank you...Leave a comment:
-
I think, in your foreach loop, youre in need of a delete query. And you want Nom to be how you select the row?
(sorry for jumping in on this hsriat - im bored =/)
Try adding this (you might have to change the tbl_name - well, there's no 'might' about it... you will have to change it)
[php]
foreach($.... )
{
mysql_query("DE LETE FROM `tbl_name` WHERE `Nom` = '{$selected_id} '"
or die(mysql_error ());
echo "$selected_ id successfully deleted! <br /> \n";
}
[/php]
Hope this helps :)Leave a comment:
-
thank for reply...
i have write this code with your suggest...
and in "del_cust.p hp" i write my code like this...Code:<? echo "<form method='POST' action='del_cust.php'>"; while($row=mysql_fetch_assoc($result)){ echo "<table width ='100%'+ border='1'>"; echo " <tr> <td><input type='checkbox' name='checkbox[]' value=''.$row[id_Customer].''></td> <td width = '10%'> $row[id_Customer] </td> <td width = '30%'> $row[Nama_Customer] </td> <td width = '20%'> $row[Alamat] </td> <td width = '10%'> $row[Kota] </td> <td width = '20%'> $row[C_Person] </td> <td width = '5%'align='center'> $row[Nom] </td> </tr> </table>"; } echo "<input type='submit' value='Submit' name='submit'>"; echo "</br><input type='text' name='nomdat'>"; echo"</form>"; ?>
1. the result is...012 (the index of the check box). i just get the index of the check box. how do i implement to delete database with that index i got?Code:<? include("test.php"); mysql_select_db("a2840013_Database",$cipai) or die ("Cannot Connect At Delete Form"); foreach($_POST[checkbox] as $key=>$selected_id){ print("$key"); } mysql_query($sql_str); ?>
2. what if i want to get "Nom" field as a direction to delete in my query. "Nom" field is a Autonumber ?
thanks for the answer...Leave a comment:
-
Include the line[php]"<td><input type=\"checkbox \" name=\"checkbox[]\" value=\"".$row[id_Customer]."\" ></input></td>"[/php] within the second echo of the while loop.
Start form tag before the while loop and end it after the while loop.
Make another PHP file (action of form tag in above code) to delete the selected id.[php]<?php
foreach($_POST[checkbox] as $key=>$selected _id)
{
//delete the $selected_id from db
}
?>[/php]Leave a comment:
-
Make Check Button
hi again... :)
please help me,how to make a check button,so the user can check which one to delete...and how to implement it with "delete" selected check button?
what code i must insert in my code,to have a check button each record... and how the procedure to check the "check button"?Code:<? while($row=mysql_fetch_assoc($result)){ echo "<table width ='100%' border='1'>"; echo " <tr> <td width = '10%'> $row[id_Customer] </td> <td width = '30%'> $row[Nama_Customer] </td> <td width = '20%'> $row[Alamat] </td> <td width = '10%'> $row[Kota] </td> <td width = '20%'> $row[C_Person] </td> <td width = '5%'align='center'> $row[Nom] </td> </tr> </table>"; } $Te =mysql_num_rows($result); echo "<b><font color='blue'><h3> Record Number= $Te </h3></b></font>"; mysql_close($cipai); ?>
if any link will answer this question,it will be help. thank you...Tags: None
Leave a comment: