After thinking my brain will explode. I have came to 3 questions. 1. What does the explode() function do? 2. Is there a way to do a batch delete in MySQL? I am running the newest version. So no worries there. How can you do $sql="delete from comments where gossip_id='5'"; Would that work for more than 1? There is a comment_id which is Auto incremented, and then there is a gossip_id (NON INCREMENTED) 3. I want to limit the comments to 10 (No problem), but when someone adds a new comment and it goes to the top (due to date) is there any way for it to delete the last one, like that would be #11? If so how? Ok I know these are a lot of questions, but I am a very curious guy. I am getting better with this...Really! Sorry! Thanks!
JackedUp
Batch Delete MySQL
There's a better way - instead of deleting, simply use a LIMIT 10 directive in your SQL query. This will return only 10 records, then quit.
Explode splits a string by a specified character into an array. For example,
explode("-","123-456-678-0");
returns
array (
"123",
"456",
"789",
"0"
)
All of this is in the PHP and MySQL manuals.
Question 1:
The explode function seperates a variable into more usable array by way of some common deliminater.
For example, within a string you have:
$string = "Applerange:Banana
each"
Each fruit is seperated by an ':', you can use the explode function to exploit that and seperate the data into an array.
$fruit = explode(":",$string);
returns:
$fruit[0] = "Apple";
$fruit[1] = "Orange";
$fruit[2] = "Banana;
$fruit[3] = "Peach";
Question 2: Yes, you can batch delete with MySQL. For example, when you run your SQL statements within PHP, you typically do something like this:
$table_name = "fruit";
$fruit_name = "Apple";
$color = "Red";
Some additional database connection code, which I'm leaving out for space reasons.
$sql = "
INSERT INTO $table_name
(Fruit_Name, Color)
VALUES
(\"$fruit_name\", \"$color\")
";
This would insert 'Apple' and 'Red' into the database.
Instead you would do the following:
$sql = "
DELETE FROM $table_name
";
This statement would delete everything within the 'Fruit' table. You could add some restraits to it, so that it would only delete the 'Red' fruits if you did something like this:
$sql = "
DELETE FROM $table_name
WHERE $color = "Red"
";
Question 3:
I'm not sure what you are talking about.