-1

i have multiple array, data is retrieved from database, using unserialize function. as i know, that using foreach(array_combine) i can get the desired result, but array_combine can only have 2 parameters. so i need a solution where i can retrieve multiple array values, combine it and show it in my table.

example here only for 2 parameters working fine, this code is working fine as i have only pass 2 parameters to array_combine

$b_destinations = unserialize( base64_decode( $rs['b_destinations'] ) );
$b_nights = unserialize( base64_decode( $rs['b_nights'] ) );

foreach (array_combine($b_destinations[0], $b_nights[0]) as $desti=>$nights)
{
echo"
<tr><td>Detination</td><td> ".$desti."</td><td>Nights : ".$nights."</td></tr>";
}

but i want to show multiple array values here

$b_hdest = unserialize( base64_decode( $rs['b_hdest'] ) );
$b_hname = unserialize( base64_decode( $rs['b_hname'] ) );
$b_hadd = unserialize( base64_decode( $rs['b_hadd'] ) );
$b_hphone = unserialize( base64_decode( $rs['b_hphone'] ) );
$b_hin = unserialize( base64_decode( $rs['b_hin'] ) );
$b_hout = unserialize( base64_decode( $rs['b_hout'] ) );
$b_hroom = unserialize( base64_decode( $rs['b_hroom'] ) );
$b_hmeal = unserialize( base64_decode( $rs['b_hmeal'] ) );
$b_haextra = unserialize( base64_decode( $rs['b_haextra'] ) );
$b_hcextra = unserialize( base64_decode( $rs['b_hcextra'] ) );
$b_hspecial = unserialize( base64_decode( $rs['b_hspecial'] ) );
$b_hincl = unserialize( base64_decode( $rs['b_hincl'] ) );

$hcnt=1;

//which method or function use here to display this desired result
foreach or any other method loop
{
echo "<tr><td colspan='4'>Hotel Details ".$hcnt."</td></tr>
<tr><td>Destination : ".$b_hdest."</td><td>Hotel Name : ".$b_hname."</td><td>Add : ".$b_hadd."</td><td>Phone : ".$b_hphone."</td></tr>

<tr><td>Check In : ".$b_hin."</td><td>Check Out : ".$b_hout."</td><td>Rooms : ".$b_hroom."</td><td>Meal : ".$b_hmeal."</td></tr>

<tr><td>Extra Adult : ".$b_haextra."</td><td>Extra Child : ".$b_hcextra."</td><td>Special : ".$b_hspecial."</td><td>Inclusion : ".$b_hincl."</td></tr>";
$hcnt++;
}

and the i need the desired result to be like this. i have used array_combine but it works only for 2 paramneters is there any other method or way to do this.

.mytable table, td, th {    
    border: 1px solid #ddd;
    text-align: left;
}

.mytable table {
    border-collapse: collapse;
    width: 100%;
}

.mytable th, td {
    padding: 15px;
}
<table class='mytable'>
<tr><td colspan='4'>Hotel Details 1</td></tr>
<tr><td>Destination : Kerala</td><td>Hotel Name : Beach Resort</td><td>Add : hotel address</td><td>Phone : 7447344789</td></tr>

<tr><td>Check In : 10/11/2017</td><td>Check Out : 15/11/2017</td><td>Rooms : 4</td><td>Meal : MAP</td></tr>

<tr><td>Extra Adult : 1</td><td>Extra Child : 1</td><td>Special : no special</td><td>Inclusion : no inclusion</td></tr>
<tr><td colspan='4'>Hotel Details 2</td></tr>
<tr><td>Destination : Kerala</td><td>Hotel Name : Beach Resort</td><td>Add : hotel address</td><td>Phone : 7447344789</td></tr>

<tr><td>Check In : 10/11/2017</td><td>Check Out : 15/11/2017</td><td>Rooms : 4</td><td>Meal : MAP</td></tr>

<tr><td>Extra Adult : 1</td><td>Extra Child : 1</td><td>Special : no special</td><td>Inclusion : no inclusion</td></tr>
<tr><td colspan='4'>Hotel Details 3</td></tr>
<tr><td>Destination : Kerala</td><td>Hotel Name : Beach Resort</td><td>Add : hotel address</td><td>Phone : 7447344789</td></tr>

<tr><td>Check In : 10/11/2017</td><td>Check Out : 15/11/2017</td><td>Rooms : 4</td><td>Meal : MAP</td></tr>

<tr><td>Extra Adult : 1</td><td>Extra Child : 1</td><td>Special : no special</td><td>Inclusion : no inclusion</td></tr>
</table>
Revati
  • 65
  • 1
  • 9
  • As long as the keys are different, you can use `arrayOfArray = array1 + array2 + array3 + array4 + array5`. [Example.](https://stackoverflow.com/questions/2140090/operator-for-array-in-php) – Chris Happy Oct 21 '17 at 04:11
  • why was anything base64 encoded? I suggest how ever you are storing this data is very sub optimal, fix that first –  Oct 21 '17 at 04:15
  • as i am accepting data from textarea for storing, so when i am using names like "Asia's largest" etc because of the 's when i was storing data in database using serialize function it was giveing me error bcoz of that, so i used the base64 enocde method to store it properyl and decode to retrive the data properly – Revati Oct 21 '17 at 04:27
  • @chris-happy sir can you please explain me how can i do it. – Revati Oct 21 '17 at 04:32
  • 1
    _"so i used the base64 enocde method to store it properyl"_ - that is not "properly". You need to go read up on the basics of properly communicating with a database in PHP - that means in this specific instance, how to handle data to prevent SQL injection, resp. how and why to use prepared statements instead. – CBroe Oct 21 '17 at 04:43
  • @cbroe sir i was getting error when i was storing the textarea value using serialize into database, so in the textbox value some words contains apostropihies {Asia's , China's , India's} etc. so i searched and found to use base64encode function to store the value into database. so i used it. – Revati Oct 21 '17 at 04:50
  • _"when i was storing the textarea value using serialize into database"_ - why are you doing that in the first place? Looks like those are simply string values, so why serialize them at all? _"so i searched and found to use base64encode function to store the value into database. so i used it."_ - then do better research because, again, that's nonsense. I gave you hints what direction to look in already. – CBroe Oct 21 '17 at 04:55
  • @cbroe sir, you can check here. this is the panel i a working on. b2b.routemate.in , username : demo@demo.com password: Qwerty. you can check here as i am storing multiple textarea value into database like for this reasoni have used serialized funtion. – Revati Oct 21 '17 at 06:03
  • _"for this reason i have used serialized funtion"_ - that is another thing you should not do; instead, properly _normalize_ your database schema. – CBroe Oct 21 '17 at 06:05
  • @cbroe sir can u help me with an example, i really need to display those results. in the whole panel only this is problem i am facing. – Revati Oct 21 '17 at 06:15
  • @cbroe sir you can check here this is my tour booking page http://b2b.routemate.in/tour-booking.php and this is where i am viewing my tour http://b2b.routemate.in/view-booking.php?packid=1 – Revati Oct 21 '17 at 06:27
  • need help over here please this is only query i have. – Revati Oct 21 '17 at 07:03

1 Answers1

0

try the following and let me know

for($i=0;$i<count($b_hdest[0]);$i++){
echo"
    <tr><td>Hotel Details ".($i+1)."</td></tr>
    <tr><td>Location : ".$b_hdest[0][$i]."</td><td>Name : ".$b_hname[0][$i]."</td><td>Address : ".$b_hadd[0][$i]."</td><tr>
    <tr><td>Phone : ".$b_hphone[0][$i]."</td><td>CheckIn : ".$b_hin[0][$i]."</td><td>CheckOut : ".$b_hout[0][$i]."</td><tr>
    <tr><td>Rooms : ".$b_hroom[0][$i]."</td><td>Meals : ".$b_hmeal[0][$i]."</td><td>Extra Adult : ".$b_haextra[0][$i]."</td><tr>
    <tr><td>Extra Child : ".$b_hcextra[0][$i]."</td><td>Special : ".$b_hspecial[0][$i]."</td><td>Inclusion : ".$b_hincl[0][$i]."</td><tr>
";
}