Answer the question
In order to leave comments, you need to log in
Write a random sample of strings to the database?
There are 5 lines
1
2
3
4
5
how to write a script correctly to write random 3 lines to the database
mysql_query("UPDATE table SET text = '$peremennaya');
Answer the question
In order to leave comments, you need to log in
You can for example like this:
$strings = ['one', 'two', 'three', 'four', 'five']; //массив строк
$p_array = []; // массив выбранных строк
for ($i = 0; $i < 2; $i++) {
//Элементы не будут повторятся. Если нужно, чтобы элементы повторялись - нужно юзать array_rand
$p_array[] = pop(array_shuffle(&$strings)); //собственно выбираем случайный элемент
}
$peremennaya = implode("\n", $p_array); //имплодим через нужный разделитель
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question