Imran Khan Imran Khan - 5 months ago 14
SQL Question

how to insert multiple of values in a single field in mysql

i want to insert multiple values into a single field, i don't know how to achieve this i'm using a long-text data type field. And also tell me how to fetch these a value only one separate value at a time.

Answer

Insert Mutliple values in a single Field:

For inserting the flat no's in a single field, use implode and the values separated by comma.

$r=implode(",",$available);
$insert=mysql_query("insert into flatdetails(available) value ('$r')")

For retrieve the values from database use, explode to separate out all the values..

For Retrieve the values using $i=explode(",",$r);

<?php
$select_tbl=mysql_query("select * from flatdetails",$conn);
while($fetch=mysql_fetch_object($select_tbl))
{
$r=$fetch->available;


$i=explode(",",$r);


echo $i[0]."</br>";
}
?>