Wilf
Wilf

Reputation: 2315

PHP list multiple value into array

I have a hotel database which has multiple rates due to the room types. I'd like to list it dynamically into array (of each room type) accordingly. My data structures are:

And I'd like to list it into each room type. So I wrote:

while($rec = mysql_fetch_array($result_rate)) {  
    $_roomId = $rec['rid'];
    $_roomRate = $rec['rate'];

    list($ratez[]) = explode("-", $_rate); //because the room type is varied by hotel so I make it in array
}

So I expect the result should comes up like

echo "Room ID $_roomId=$ratez[$_roomId] USD ";

But the result is not as I expect. It keeps displaying error Fatal error: Unsupported operand types.

Upvotes: 2

Views: 176

Answers (2)

Wilf
Wilf

Reputation: 2315

What I did is just:

$_rCostz=explode("-",$rec['cost']);

and echo the result in currency format as :

echo number_format($_rCostz[$room_id-1]) 

//because the room id starts with 1 but the array begins` with "0" so -1

Thank you very much, Night2 and others. Problem solved.

Upvotes: 0

Night2
Night2

Reputation: 1153

Use this:

$ratez[] = explode('-', $_rate);

Or this to save rates for each room:

$ratez[$_roomId] = explode('-', $_rate);

Upvotes: 1

Related Questions