2

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:

  • Hotel A : 1200-1500-1300-1700 //room type 1=1200usd/night, room type 2=1500usd/night ...
  • Hotel B : 1500-1200-1300
  • Hotel C : 800-850

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.

1
  • list does not work like that. Also, this code has 6 different variables all of which are used only once??? Commented Sep 15, 2012 at 11:43

2 Answers 2

1

Use this:

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

Or this to save rates for each room:

$ratez[$_roomId] = explode('-', $_rate);
Sign up to request clarification or add additional context in comments.

2 Comments

This is what I'm talking about @Night2. But still, I have an error : Fatal error: Unsupported operand types.
Change your echo to this: echo 'Room ID '.$_roomId.'='.$ratez[$_roomId][0].' USD'; Inplace of [0] you can loop the array and use the right index.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.