View Full Version : delete a x number of vars (mysql ,flash)
webreake
08-11-2004, 08:38 PM
hi
my problem is
from flash i output to php a x number of vars like this:::
countvars=3&fromlist2=108&fromlist1=109&fromlist0=112
where countvars is the number of vars and fromx=value the value is the id of some row
so i need php delete all this rows my code is this but is not working::
<?php
include 'conexion.php';
//Capture data from $_POST array
$countvars = $_POST['countvars'];
$i=0;
while($i<$countvars){
$todelete='fromlist$i';
$eraser = $_POST[$todelete];
$result = mysql_query("DELETE FROM tableform WHERE ID=$eraser");
$i++;
}
?> im new in php so i really need help
thanks
vosgien
08-12-2004, 05:59 PM
Hi webreake,
Not sure if this will help as I haven't tested it, but have you tried using a for loop in conjunction with $i, like this could be worth a try:
<?php
include 'conexion.php';
//Capture data from $_POST array
$countvars = $_POST['countvars'];
for(i = 0;$i<$countvars i++)
{
$todelete='fromlist$i';
$eraser = $_POST[$todelete];
$result = mysql_query("DELETE FROM tableform WHERE ID=$eraser");
}
?>
Hope it helps
Vosgien
webreake
08-12-2004, 08:24 PM
hi vosgien
i test it and nothing still doesnt delete any of the records
i dont know to much about php but i think the problem is not on the loop
i believe is in the way im making the constructor of the vars
what i mean is that
$todelete='fromlist$i'; is not returning this 'fromlist1'
im trying to test it whit echo or print '$todelete' but it shows nothing in the output
and another doubt i have is within the condition on the loop i dont know if
for(i = 0;$i<$countvars i++) acepts countvars as a string
do you know how to transform a string into a number ??
any way thx a lot for your answer
vosgien
08-13-2004, 06:30 AM
Hi,
Can you show us your AS code for passing countvars to php, also it looks like you only need the numbers as ( if I have understood) these represent $row ID.
Also, can you echo $countvars to see how it is arriving to your php
Cheers
Vosgien
webreake
08-13-2004, 06:29 PM
hi again vosgien
here is the as code:
axionBtn.onRelease = function() {
/////////if there is items selected on the list
select = area.selectedIndices;
if (select != undefined) {
delete = new LoadVars();
///selectedIndices method returns an array
size = idList.selectedIndices;
////get the values of the selected components and
////capture them into a var inside delete object
for (var i = 0; i<size.length; i++) {
delete["fromlist"+i] = idList.getItemAt(size[i]).label;
}
delete.countvars=size.length
///////show the vars to output
trace( delete);
delete.sendAndLoad("delete.php", delete, "POST");
/////idList.removeItemAt(idList.selectedIndex);
/////area.removeItemAt(area.selectedIndex);
status = "records deleted";
} else {
status = "there is no item selected on the list to delete";
}
};
and yes the values to output are the row id , my DB has 3 columns
(id , name, age) in flash i have 2 lists one shows the id's and the other the name and age so when i choose two or more names from one list i get
the values ids for those names from the other list and send them to php
the countvars shows 3 or any number of selected items on my list
vosgien
08-13-2004, 07:27 PM
Hi webreake,
I might be missing something here - so bear with me, this line :
the countvars shows 3 or any number of selected items on my list
Is the 3 what appears in the output window if you run echo $countvars; in your php script, if yes then all you are passing to your php file is the number of elements inside array size, the problem lays with the line
delete.countvars=size.length
// in your AS code
That will pass the number of elements in size and not the actual elements.
So the first thing to do is to trace the two in Flash - like this:
/*last block of code before the else statement*/
delete.countvars=size.length
///////show the vars to output
trace( delete);
delete.sendAndLoad("delete.php", delete, "POST");
/////idList.removeItemAt(idList.selectedIndex);
/////area.removeItemAt(area.selectedIndex);
status = "records deleted";
trace(size)
trace(delete)
} else {
Obviously, this will tell you if the correct info is being passed to your loadvars object, then if you run the echo line in your php you will see what is being recieved, but my guess is the AS line I pointed to above is the problem.
Cheers
Vosgien
webreake
08-14-2004, 05:25 AM
hi vosgien
echo "$countvars"; ////returns the number of elements
i did the countvars variable only to know the number of variables im sending to php whitout counting countvars itself
This is what flash output to php when i do a trace(delete)
countvars=3&fromlist2=108&fromlist1=109&fromlist0=112
as you can see countvars point that there are 3 fromlist vars
i dont use the countvars as id row if that is what you mean
the ids rows are the values of the fromlist vars like
fromlist2= 108
108 is the row id
i think all the problem is on php but i cant see the problem there because im new in php
one more question how can i make the id of mysql return to 0 after a certain number is reached lets say 1000?
i really apreciate your help
freddycodes
08-14-2004, 07:16 AM
Okay I have held of on chiming in here, but let me show you a really simple way to do what you want.
Be forewarned it is dangerous to run strings like this on your database, but if you are confident you are the only one who will be hitting this script, use the IN() clause from your flash movie. You could even do regex on it, to make sure its only numbers separated by commas
countvars=3&dellist=108,109,112
$result = mysql_query(sprintf("DELETE FROM tableform WHERE ID = IN({0}", $_POST['dellist']));
freddycodes
08-14-2004, 07:20 AM
i think all the problem is on php but i cant see the problem there because im new in php
one more question how can i make the id of mysql return to 0 after a certain number is reached lets say 1000?
You could drop the table and recreate it on the fly. But you don't really want to reuse ids, thats the point of them. Especially when you get into more complex structures, where you have foreign keys, you should try not to reuse ids.
webreake
08-15-2004, 09:03 AM
it works :cool:
thx a lot vosgien
here is the code::
<?php
include 'conexion.php';
$countvars = $_POST['countvars'];
$i=0;
while($i<$countvars){
$todelete='fromlist'.$i;
$eraser = $_POST[$delalista];
$result = mysql_query("DELETE FROM tableform WHERE ID=$eraser ");
$i++;
}
?>
thx freddycodes but there was a problem with the output of flash
i made a trace() of my loadVars object and it didnt send a comma it output this:::
countvars=3&dellist=139%2C133%2C136
i guess %2c is an hexadecimal or something similar code for commas
but im happy that finally it woooorks !!
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.