I have inserted multiple id from one table to another table as an array. In database it shows like 1,2,3,4.
My question is how can i display all records where id is equal to 1,2,3,4.
I have inserted multiple id from one table to another table as an array. In database it shows like 1,2,3,4.
My question is how can i display all records where id is equal to 1,2,3,4.
If you are looking for all numbers between 1 and 4, you can use BETWEEN
.
SELECT *
FROM myTable
WHERE id BETWEEN 1 AND 4
If you need specific numbers, you can use IN()
SELECT *
FROM myTable
WHERE id IN (1, 2, 3, 4)
Try This --
SELECT * FROM table WHERE id BETWEEN 1 and 4;
OR
SELECT * FROM table WHERE id IN (1,2,3,4);
OR php array variable $con is DB connectivity.
$id = array[1,2,3,4];
$sql = mysqli_query($con,('SELECT * FROM table WHERE id IN ('.implode(", ",$id).')'));
Array Inserting data in DB through array
$ids = implode(", ",$id);
$sql3 = mysql_query("INSERT INTO `table`(`id`) VALUES ('$ids'");