Monday, 20 July 2015

PHP implode and explode concept

This concept based on multiple value to store on array function. its post to the database after that value fetch explode mode. previously fetch the value on array function but unlimited array value not possible to fetch array function. so follow this to learn about foreach mode fetch array function.
using array to collect the similar data in select box Ex; Multiple city

<?php
    if(isset($_POST['submit'])){
    $pal=$_POST['palce'];
    $palce=implode(',',$pal);
    $insert=mysql_query("insert into location (engines) values ('$palce')");
    }
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>mostlikers</title>
</head>
<form  method="post"><p><select name="palce[]" multiple="multiple"  style="width:200px">
<option value="google">google</option>
<option value="yahoo">yahoo</option>
<option value="Awasome">Awasome</option>
</select></p>
<p><input type="submit" value="submit" name="submit" /></p></form>
<body>
</body>
</html>
Explode
<table>
<?php  
$result_opt = mysql_query("select * from location ") or die(mysql_error());
while($data_opt = mysql_fetch_array($result_opt)){    
 $id = $data_opt['id'];
 $place1 = $data_opt['engine']; 
 $place2 = explode(',',$place1);
 $count1 = count($place2);
?>

<tr><td><?php  echo $id ?></td><td><?php for($i=0; $i<$count1; $i++){ echo $place2[$i].",";}?></td></tr>


<?php }
?>
</table>

0 comments:

Post a Comment