Item to show calendar

Item to show calendar

Postby denis88 » Tue Nov 25, 2008 3:29 pm

Hi Chris,

I probably have the most stupid question but I went through all posts and could not find the anwser. I am new to php and I am now killing myself for two hours when I want to add "Item to show calendar" just like you have it here http://www.cbolson.com/code/availability-calendar/ - with nice title, so user can see for which Item he is changing values. I have added Items using form (simply filling in values in Dreamwork) and it works but it doesn't refresh, I can change values for Item 2, item 3, item 4 etc. but I always see like i have chosen item 1... I also don't know how to get title out of it... :?

I would really apriciate if you could help me :)

Best regards, Denis

Btw: really nice script :)
denis88
 
Posts: 3
Joined: Tue Nov 25, 2008 3:21 pm

Re: Item to show calendar

Postby chris » Tue Nov 25, 2008 11:11 pm

Hello there and welcome to the forum.

The id of the calendar to show is defined as a php "constant" in the lines:
Code: Select all
if(isset($_REQUEST["id_item"]))       define("ID_ITEM",   $_REQUEST["id_item"]);   #   id sent via  url, form session etc
else                           define("ID_ITEM",   2);                  #   default used for demo

So, if the page receives a value for "id_item" either from a form or from a link, it will use that "id" to show the calendar. Otherwise it will show the id "2" that I have defined as the default item.
Ideally you will have your "items" (be they hotel rooms, camping plots, etc) in a database so this "id" will simply be the id of the item in the database.
Alernativly, if your "items" aren't linked to a database and are simply "hardcoded" (ie not dynamic in anyway) you will have to assign them "id"'s manually.
This could be done by creating an array of items like this:
Code: Select all
$items=array();
$items[1]="House on the beach";
$items[2]="Cabin in the woods";
$items[3]="Flat in the village";

Where the titles would be the titles of your "items".
Now, to show the select list you could do something like this:
Code: Select all
<select name="id_item">
<?php
foreach($items as $id=>$title){
echo '<option id="'.$id.'">'.$title.'</option>';
}
?>
<select>

As hopefully you will see this simply loops through your items to add them to the select list.

Finally, to be able to show the title of the selected item you could do the following:
Code: Select all
<?php echo $items[ID_ITEM]; ?>

(please note that you might not need the opening and closing php tags if you place this code within php tags that are already open)

Well, I hope that you can follow this - let me know if it isn't what you where after or if you have any problems.

Chris
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron