How to combine these two array into one using php? -
i want take out data database , store in different array can plot graph it. there problem occur when take out data. take out part of coding.
$query =mysqli_query($con,"select * appointment l_name='$lname' , a_status='confirmed' , extract(month a_date) = '$month' ") or die(mysqli_error()); if(mysqli_num_rows($query)>0) { echo "<h3 align=center style=font-size:20px;>" .$_post['month']. "</h3>"; echo "<table width=500 cellpadding=10 border=0 align=center><tr style='color:#fff;background-color:#000'><td><div align='center'>name</td><td align='center'>total no. of appointment</td><td align='center'>details</td></tr>"; while($row=mysqli_fetch_assoc($query)) { $name=$row['s_name']; if($tempname!=$name) { $sql=mysqli_query($con,"select * appointment l_name='$lname' , a_status='confirmed' , extract(month a_date) = '$month' , s_name='$name' ") or die(mysqli_error()); if(mysqli_num_rows($sql)>0) { $count = mysqli_num_rows($sql); $x=array($name); $no=array($count); echo "<tr bgcolor='#f7d358' width=60><td align=center>".$name."</td><td width=200 align=center>" .$count. "</td>"; echo "<td align=center width=80><a href='view_month.php?sname=$name&num=$count&month=$month'><img src='select.jpeg' width='80' height='30'></a></td></tr>"; } $tempname=$name; } } $data = array_combine($x, $no); print_r($data);
the output 1 data there should 2 data inside database. how can solve it?
current output
array ( [ken] => 1 )
expected output
array ( [alice] => 2 ), array ( [ken] => 1 )
the problem below lines of code. should use array_push
, overwriting array data
$x=array($name); $no=array($count);
you should use instead
$x = array(); //declare below loop $no = array(); //declare below loop array_push($x, $name); array_push($no, $count);
note: array_push() raise warning if first argument not array.
this why have declare variables array first.
Comments
Post a Comment