Hi, I am building a room availability form that contains a foreign key 'roomNumber' that references the multiple dropdown list that contains the data time starting from 07:00 AM to 09:00 PM from monday to saturday, i can already store the data into the database but my problem now is editing the intended available time of a roomNumber. basically, my idea is that i have an edit button, and i will click on the roomNumber list my desired roomnumber and when i click the edit button, the previous entry made on the multiple dropdown lists will be shown again, and when i change 1 of the values on the dropdown lists it will edit the database entry.

I apologize for my poor explanation :icon_question:

Not too sure what you're asking.

The best method i can think of to store that data is to store all bookings it all in its own table.

id,roomid,start,end
1,1,2012-03-05 07:00:00,2012-03-05 21:00:00
2,1,2012-03-07 07:00:00,2012-03-07 21:00:00
3,2,2012-03-02 07:00:00,2012-03-08 12:00:00
4,3,2012-03-04 07:00:00,2012-03-05 12:00:00

Then on any updates of people staying longer/leaving early update the booking to its new time, then get the site to reference the table to check if a room is free.

Or are you just asking how can you update a database just by selecting an option in a dropdown box?

Not too sure what you're asking.

The best method i can think of to store that data is to store all bookings it all in its own table.

id,roomid,start,end
1,1,2012-03-05 07:00:00,2012-03-05 21:00:00
2,1,2012-03-07 07:00:00,2012-03-07 21:00:00
3,2,2012-03-02 07:00:00,2012-03-08 12:00:00
4,3,2012-03-04 07:00:00,2012-03-05 12:00:00

Then on any updates of people staying longer/leaving early update the booking to its new time, then get the site to reference the table to check if a room is free.

Or are you just asking how can you update a database just by selecting an option in a dropdown box?

i just want to know how can i update my database by clicking a desired room and the entry on that desired room will be loaded from the drop down list :(

http://farm8.staticflickr.com/7183/6958705131_2b5fef847a_z.jpg

i want to know how can i do these when i click a specific room, revealing all my previous entries on that room and changing it using a new button called edit. Then, removing the previous post.

That sounds like ajax you want for that, heres a quick example of ajax i use

ajaxfunc.js

function getXMLHTTPRequest() {
   var req =  false;
   try {
      /* for Firefox */
      req = new XMLHttpRequest(); 
   } catch (err) {
      try {
         /* for some versions of IE */
         req = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (err) {
         try {
            /* for some other versions of IE */
            req = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (err) {
            req = false;
         }
     }
   }
   
   return req;
}
function showRoomAvailability(roomid,eid){
	var updReq = getXMLHTTPRequest();
	var url = 'showRoomAvailability.php';
	var vars = 'roomid='+roomid;
	updReq.open('POST', url, true);
	updReq.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	updReq.onreadystatechange = function() {//Call a function when the state changes.
		if(updReq.readyState == 4 && updReq.status == 200) {
			if(updReq.responseText == 'N'){
				alert('error!');
			}else{
				document.getElementById(eid).innerHTML = updReq.responseText;
			}
		}
	}
	updReq.send(vars);
}

showRoomAvailability.php

<?php
//if you use a app based site check the request is from a logged in user
//require_once('includes/application.php');
//if($A['seccheck'] === true){
	$roomid = escapeFunction($_POST['roomid']);
	//******************************//
	//select room data from database//
	//******************************//
	
	if($roomfound){
		//Display all the html content of your room selection options
		//eg.
		echo "<form>
		<select name='available'>
		<option value='2012-03-12'></option>
		<option value='2012-03-13'></option>
		<option value='2012-03-16'></option>
		<option value='2012-03-17'></option>
		</select>
		</form>";
	}else{
		echo 'N';
	}
	?>
	
	<?php 
//}else{
//	
//}
 ?>

Then just include the js file and make a call to the function with the roomid you want the info for whenever the select box changes value

<select name='roomid' onchange="showRoomAvailability(this.value,'roomDataDiv');">
<option value='55'>55</option>
<option value='56'>56</option>
<option value='57'>57</option>
</select>
<div id='roomDataDiv'></div>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.