I’m writing a script that will delete multiple entries in a mysql database using the id variable. I want to inform the user of the progress of the deletion. How can you return each section with just the one return in the WWW?
public IEnumerator DeleteVehicle()
{
string ID = PlayerPrefs.GetString ("DeleteID");
WWWForm VehicleDeleteForm = new WWWForm ();
VehicleDeleteForm.AddField ("DeleteID", ID);
WWW VehicleDelete = new WWW ("path/DeleteVehicle.php", VehicleDeleteForm);
yield return VehicleDelete;
}
With multiple deletes in the php, how would I get the correct return for each section?
$sql= "DELETE FROM battery WHERE VehicleID = '".$id."'";
if(mysqli_query($ms, $sql))
{
echo "All Batteries for ".$id." were deleted successfully.";
}
else
{
echo "ERROR: Could not able to execute $sql. "
. mysqli_error($ms);
}
$sql= "DELETE FROM brakes WHERE VehicleID = '".$id."'";
if(mysqli_query($ms, $sql))
{
echo "All Brakes for ".$id." were deleted successfully.";
}
else
{
echo "ERROR: Could not able to execute $sql. "
. mysqli_error($ms);
} ETC, ETC, ETC.
If the WWW can only return one item, then I would have to have multiple functions to accomplish this?
Thanks!
What I decided to do, for those people that are interested.
I put in a switch/case in php to delete the right material at the right time based on the selection that is sent via the form. In order to prevent the server and or the script from getting overwhelmed, I added in a new pause for seconds(2) so it could display the status and clear the text before the next coroutine was started.
public IEnumerator VehicleDeleteVehicle()
{
string ID = PlayerPrefs.GetString ("VehicleID");
string Select = "Vehicle";
WWWForm VehicleDeleteForm = new WWWForm ();
VehicleDeleteForm.AddField ("VehicleID", ID);
VehicleDeleteForm.AddField ("Select", Select);
WWW VehicleDelete = new WWW ("http://localhost/CMVM/DeleteVehicle.php", VehicleDeleteForm);
yield return VehicleDelete;
Debug.Log (VehicleDelete.text);
StatusText.text=VehicleDelete.text;
yield return new WaitForSeconds(2);
StatusText.text="";
yield return new WaitForSeconds(2);
StatusText.text="Vehicle Deleted!";
yield return new WaitForSeconds(2);
StatusText.text="";
loadvehicle.DestroyObjects ("Vehicle");
loadvehicle.CallVehicles ();
}
and on the PHP side:
$select=$_POST['Select'];
switch ($select)
{
case "Oil":
$sql= "DELETE FROM oilchange WHERE VehicleID = '".$id."'";
if(mysqli_query($ms, $sql))
{
echo "All Oil Changes for ".$id." were deleted successfully.";
}
else
{
echo "ERROR: Could not able to execute $sql. "
. mysqli_error($ms);
}
break;
I hope this will help someone else.