how to get diffrent data from single column in mysql and php -
i want store multiple data comma separated in single column , data of php in different different line in column view looks this-- toothbrush-1234,glass-1234, in there 1234 product id want data in php separated values each line details.
<?php $sql="select product_name form products product_id=1234" ?> so possible data , separat - , , single column.
you want display comma separated data separate rows. can try this.
<? //here complete example of code using mysqli object oriented: $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "mydb"; // create connection $conn = new mysqli($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } $sql = "select product_id,product_name form products product_id=1234"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row $yourdata = array(); while($row = $result->fetch_assoc()) { $yourdata[$row['product_id']] = explode(",",$row['product_name']); } if(count($yourdata) > 0){ foreach ($yourdata $key => $value) { foreach ($value $productname) { echo "product id >> ".$key. " -- product name >> ".$productname; } } } } else { echo "0 results"; } $conn->close(); ?> side note: if using mysql_* in application suggest use mysqli_* or pdo because mysql_* deprecated , not available in php 7.
Comments
Post a Comment