Jump to content

john-formby

Members
  • Posts

    91
  • Joined

  • Last visited

About john-formby

  • Birthday 08/16/1981

Profile Information

  • Gender
    Male
  • Location
    Mahe, Seychelles

john-formby's Achievements

Member

Member (2/5)

0

Reputation

  1. Hi, I just figured out the problem. It was because of the line break tag at the end of this line: $bookDate = date('Y-m-j', strtotime('Monday +'.$i. ' days')).'<br />'; Once I removed this, it gives the correct results. Thank you so much to everyone who has helped with this. John
  2. Hi Psycho, Thank you again, I ran it as it was, but no records were returned. I changed the $query on line $result = mysql_query($query) or die(mysql_error()); to $SingleQueryToRun and it returns results. It is now returning all the rooms again, including the one that should be excluded as it appears in the roomsbooked table. Sorry to be such a pain, I just have no idea how to get this to work. Many thanks, John
  3. Hi Psycho, Thank you for the help with this. How do I get the code above to output the records? I have run the code, but nothing is displayed in the browser. Many thanks, John
  4. Thanks jcbones, I am beginning to see that :-) The problem is that I need to run the query five time, once for each day of the following week as I have more code to put under this. I am not sure how to do this without nesting the query within the loop? Many thanks, John
  5. Oops, sorry, yes the roomID in the roomsbooked table should have been 1 not 12. It is getting late :-) I can get your code to work perfectly when I run it on its own, but as soon as I try to nest it inside my for loop, it returns all the records from the rooms table, not just the empty ones. I know this is cheeky, but would it be possible for you to see if you get the same result? for($i=0;$i<5;$i++) { $currentDate = date('Y-m-j', strtotime('Monday+'.$i. ' day')).'<br />'; echo $currentDate; $sql3 = mysql_query("SELECT roomID, roomNum FROM rooms WHERE rooms.roomID NOT IN (SELECT roomID FROM roomsbooked WHERE roomsbooked.event_date = '$currentDate')"); $numrows3 = mysql_num_rows($sql3); echo $numrows3; while($row3 = mysql_fetch_array($sql3)) { $rooms[] = $row3['roomNum']; } print_r($rooms); } I am trying to loop through each day for the following week (Monday to Friday) and return the available rooms for that day. It just doesn't ignore any rooms that are already occupied. Many thanks, John
  6. Hi, Thank you for all the replies. I have just read through and tried changing the query to a join and the other one with the two select statements, but am still not getting the results. Below is some data for the two tables I have and I will explain what the output should be: Table 1 = rooms Fields roomID roomNum Data 1, 12 2, 14 3, 18 Table 2 = roomsbooked Fields event_date roomID Data 2013-03-25, 12 I am querying based on an event_date (e.g. 2013-03-25). What I need to do is return roomID = 2 and roomID = 3 into an array from the rooms table as these two rooms do not appear in the roomsbooked table. I have been trying to get this to work, but nothing I try gives me the result I need. Many thanks for all your help. John
  7. Hi, I am trying to write a query, but it is not giving the correct results. I have 2 mysql tables: roomsbooked = records the date (date datatype) and userID of who has a room booked rooms = a list of all rooms What I need to do is look at the roomsbooked table for a given date and create an array of any rooms from the rooms table that are not included for that date in roomsbooked. Essentially, I am trying to find out what rooms are still available. I have written a query, but it is not giving me the correct data: $sql3 = mysql_query("SELECT * FROM rooms, roomsbooked WHERE roomsbooked.event_date = '$currentDate' && rooms.roomID != roomsbooked.roomID"); $numrows3 = mysql_num_rows($sql3); echo $numrows3; while($row3 = mysql_fetch_array($sql3)) { $rooms[] = $row3['rooms.roomnum']; } print_r($rooms); The problem is that when I echo numrows3 I get zero. I know that there is a record in the roomsbooked table for the event_date I am querying and I have lots of room in the rooms table. Please can someone kindly point me in the right direction. Many Thanks, John
  8. Wow, thank you very much for your replies. PaulRyan, I can follow the logic of yours and I understand what you have done, so thank you. Trq, I love how short your code is, but I am unfamiliar with those array functions. I will be heading off to php.net to check them out now Thanks to both of you, John
  9. Perfect, thank you very much to both of you. I have changed week to day as suggested and works great. Many Thanks, John
  10. Hi, I need help with looping through the dates of working days (Monday to Friday) for the following week. I need to send an email once a week (probably on a Thursday or Friday) informing people of their rooms for the following week. I need to loop through each day, starting with Monday and finishing on Friday. I wrote this: for($i=0;$i<5;$i++) { echo date('Y-m-j', strtotime('Monday+'.$i)).'<br />'; } I thought this would work, but it returns the correct date for next Monday (2013-03-25) and then the other 4 days are all showing as 2013-03-24. Any ideas how I can get this to work? Thank you for taking the time to help. Many Thanks, John
  11. Hi, I am trying to develop a room allocation application, but am struggling a bit to get my head around the coding. I am trying to break it down into small chunks and then maybe see if I can get everything to work together. I have a mysql table which contains a list of users. I have returned the results of the user IDs from my select query into an array. I also have another table which holds a numeric marker. The marker will change. My array of user IDs would look like: Array ( [0] => 1 [1] => 3 [2] => 5 ) My numeric marker could be: 1 What I need to do is do a complete loop through my array starting at the numeric marker position. This would return: [1]=>3 [2]=>5 [0]=>1 As you can see, it jumps back to the beginning of the array and outputs the first element to complete the loop. Depending on the numeric marker and this particular data set, the array could also run like: Marker = 0: [0]=>1 [1]=>3 [2]=>5 Marker = 2: [2]=>5 [0]=>1 [1]=>3 I have had a go at writing the code and if I start at numeric marker 1, I can get it to run to the end of the array. I just have no idea how to reset back to the beginning and run until I reach numeric marker minus 1. Here is what I have so far: $i = $numericMarker; foreach ($userID as $key => $value) { if ($key < $numericMarker) continue; echo '$i = '.$i.' $value = '.$value.'<br />'; $i++; } Any help you can give me would be greatly appreciated. Many thanks, John
  12. Hi testing7, Sorry, it is the table name I mis-spelled in my example. Your table is: referals and in my example I wrote referrals (extra R). If you change this, it should be ok. John
  13. Hi testing7, Do you want to display the count for an individual user (i.e. you are passing a value to the database for one user) or do you want to return the count for all users in the database? For the first option, you can use something like this: <?php $user = 'John'; $total= mysql_query("SELECT user, COUNT(user) AS user_total FROM referrals WHERE user = '$user'"); echo '<tr>'; while($row = mysql_fetch_array($total)) { echo '<td>User: '.$row['user'].', Count: '.$row['user_total'].'</td>'; } ?> For the second option you can use something like this: <?php $total= mysql_query("SELECT user, COUNT(user) AS user_total FROM referrals GROUP BY user"); echo '<tr>'; while($row = mysql_fetch_array($total)) { echo '<td>User: '.$row['user'].', Count: '.$row['user_total'].' / </td>'; } ?> Hope this helps, John
  14. The example you posted should work: $value = 32; for($i = 0; $i<=$value; $i++) { echo $i.', '; }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.