-1

Hi Daniweb,

I am confused, how to explode the numbers from database. Simply I can Explode, but after explode I have to relate the numbers to another table. If any one not clear abt my problem, pls reply

Eg: 1, 2 Relate to Basket, football

$sql1=mysql_query("SELECT impid FROM customer where c_id=1") or die (mysql_error());

$result1 = mysql_fetch_array($sql1);

echo $exp= $result1['impid']; // get 1, 2 from here

echo $array=explode(",",$exp); // cannot get the output from explode function, How can 


I get the sports name from here.
Votes + Comments
Duplicate thread < 10 hrs apart....
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by nukabolhi
0
<?php
//Let's assume you have two tables "birth" and "explode_birth". Now assume the birth table contains on
//one column "birthday" and "explode_birth" table contains three columns "day", "month",and "year".
//You have the date 2010-11-22 in the "birth" table and you want to break it up and put the individual components into "explode_birth" table 
//like this: 22 for "day" column , 11 for "month" column, and 2010 for "year" column. You will do something like this.

$connection = mysql_connect("localhost", "root", "password") or die("Connection failed. ".mysql_error());
mysql_select_db("mydatabase", $connection) or die("Unable to select db. ".mysql_error());

//Get the date from the birth table
$query = "SELECT birthday FROM birth";
$result = mysql_query($query) or die("Error in query" .mysql_error());
$result_returned = mysql_fetch_object($result) or die(mysql_error());

//explode the result into its components
$exploded = explode("-", $result_returned->birthday);
//Now $exploded is an array containing 3 element $exploded[0] = 2010, exploded[1] = 11, and exploded[2] = 22

//Insert the result into the explode_birth table
$query = "INSERT INTO explode_birth VALUES(".$exploded[2].", ".$exploded[1].", ".$exploded[0].")";
mysql_query($query) or die("Can't inser into table".mysql_error());

//You have done it! you now have the individual components of the date you fetch from the birth table 
//in the explode_birth table

?>

Edited by cossay: n/a

0

Thanks @cosay. At last I figure out the problem.

$sql4=mysql_query("SELECT * FROM customer WHERE c_id=1") or die (mysql_error());

// while loop to explode 
while ($row4=mysql_fetch_array($sql4))  {
$exp=$act_name=$row4['impid'];
$aname=$row4['sport_name'];
$price=$row4['sport_price'];
$try=explode(",",$exp);
}

if(strstr($try, ',')){
$array=explode(",",$try);
}else{

$array = array($try);
}

// For each to link 
foreach( $try as $name){
 $sql2 = mysql_query("SELECT * FROM sports where sport_id='".$name."'") or die (mysql_error());
 $result2 = mysql_fetch_array($sql2);
 echo $result2['sport_name']; 
 echo " $". $id[]=$result2['sport_price'] ."<br>"; 
}
echo $total = array_sum($id);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.