Jump to content

goosebriar

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

goosebriar's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. That worked!! It created some duplicates, but I was able to unset those. Thanks so much for your help and for being there on a weekend!
  2. My merged array looks like this: Var export of array: array ( 0 => array ( 1182529800 => array ( 'time' => 1182529800, 'type' => 'Middle', 'date' => '12:30', 'bgcolor' => 1, ), 1182531600 => array ( 'time' => 1182531600, 'type' => 'Middle', 'date' => '13:00', 'bgcolor' => 1, ), ), 1 => array ( 1182519000 => array ( 'time' => 1182519000, 'type' => 'Middle', 'date' => '9:30', 'bgcolor' => 0, ), 1182520800 => array ( 'time' => 1182520800, 'type' => 'Middle', 'date' => '10:00', 'bgcolor' => 0, ), 1182522600 => array ( 'time' => 1182522600, 'type' => 'Middle', 'date' => '10:30', 'bgcolor' => 0, ), ), 2 => array ( 'time' => '1182517200', 'type' => 'Start', 'date' => '9:00', 'bgcolor' => 0, ), 3 => array ( 'time' => '1182524400', 'type' => 'End', 'date' => '11:00', 'bgcolor' => 0, ), 4 => array ( 'time' => '1182528000', 'type' => 'Start', 'date' => '12:00', 'bgcolor' => 1, ), 5 => array ( 'time' => '1182533400', 'type' => 'End', 'date' => '13:30', 'bgcolor' => 1, ), ) Index 0 and 1 above need to be on the same dimension as 2 and above so that I can sort them put them into a table. What I am trying to do is make a day view of a calendar that would eventually look like this: 9:00Start 9:30Middle 10:00Middle 10:30Middle 11:00End 12:00Start 12:30Middle 13:00Middle 13:30End And my current approach to get the day view (after several attempts at different approaches!) is to make arrays of the start and end time (which I have in a database) and then merge them, which works fine except that to create the middle range I have to create an additional array which calculates a range of middle times for each record in the database (so, for example, the first record with a start and end time in my database created 3 middle range elements) and, as you can see from above, that turns out as an associative array where as the start and end arrays are not. Therein lies my dilemma.
  3. Thanks for your help, but neither worked. This solution: foreach ($first_array as $key => $array) { $new_array[$key] = $array; } created the same array I had in the first place, which was: [0] => Array ( [1182519000] => Array ( [time] => 1182519000 [type] => Middle [date] => 9:30 [bgcolor] => 0 ) [1182520800] => Array ( [time] => 1182520800 [type] => Middle [date] => 10:00 [bgcolor] => 0 ) [1182522600] => Array ( [time] => 1182522600 [type] => Middle [date] => 10:30 [bgcolor] => 0 ) ) [1] => Array ( [1182529800] => Array ( [time] => 1182529800 [type] => Middle [date] => 12:30 [bgcolor] => 1 ) [1182531600] => Array ( [time] => 1182531600 [type] => Middle [date] => 13:00 [bgcolor] => 1 ) ) The second solution: $new_array=$old_array[0]; gave me [1182519000] => Array ( [time] => 1182519000 [type] => Middle [date] => 9:30 [bgcolor] => 0 ) [1182520800] => Array ( [time] => 1182520800 [type] => Middle [date] => 10:00 [bgcolor] => 0 ) [1182522600] => Array ( [time] => 1182522600 [type] => Middle [date] => 10:30 [bgcolor] => 0 ) which was only one of the two keys I needed. I am stumped. I've been working on this all weekend (ignoring my husband) going through several different looping situations to try to solve it, but haven't been able to. Any other suggestions?
  4. Can anyone suggest a method for merging two different types of arrays? My first array: [0] => Array ( [1] => Array ( [time] => 1183638600 [type] => middle [name] => [date] => 8:30 [bgcolor] => 1 ) [2] => Array ( [time] => 1183640400 [type] => middle [name] => [date] => 9:00 [bgcolor] => 2 ) I need to look like this: [12] => Array ( [time] => 1183647600 [type] => [name] => [date] => 11:00 [bgcolor] => ) [13] => Array ( [time] => 1183649400 [type] => [name] => [date] => 11:30 [bgcolor] => ) So that I can merge the two to look like the second one. Any suggestions?
  5. Thanks, that didn't work though. I think I will post a new topic. Thanks for all your help!
  6. I would like it to look like: [6] => Array ( [time] => 1183473000 [type] => middle [name] => [date] => 10:30 [bgcolor] => ) Right now it looks like: [0] => Array ( [1] => Array ( [time] => 1183473000 [type] => middle [name] => [date] => 10:30 [bgcolor] => 1 ) I just need to get rid of that extra level. Right now I'm experimenting with some looping to make a new array, but its not happening. I tried your example, but got "Warning: Invalid argument supplied for foreach() in". Thanks for all your help, btw!
  7. That worked beautifully! I'm merging this into another array that doesn't have that many levels, though. How do I reduce the levels? I tried array_combine, but I don't have PHP 5.
  8. Wow - that was fast. Sometimes, I will have no results or I may several results. I dropped the first result and did a while loop, but it still only creates an array from one record. $entry=sprintf("SELECT * FROM lrms_entry WHERE start >='$start' AND start <'$end'"); $rs_entry=mysql_query($entry); $numrecords=mysql_num_rows($rs_entry); echo "Num records: ".$numrecords."<br />"; while ($row_rs_entry=mysql_fetch_assoc($rs_entry)) { $starttime=$row_rs_entry['start']; $endtime=$row_rs_entry['end']; $diff=$endtime-$starttime; $periodno=($diff/$period)/60; for ($c=1; $c<$periodno; $c++) { $add=($c*$period)*60; $middle[$c]['time']=$start+$add; $middle[$c]['type']="middle"; } }
  9. I am trying to create a new array out of results from a query, but can't get it to create from more than one row of the results. How can I get the rest of the rows? $entry=sprintf("SELECT * FROM lrms_entry WHERE start >='$start' AND start <'$end'"); $rs_entry=mysql_query($entry); $row_rs_entry=mysql_fetch_assoc($rs_entry); do { $period=30; $starttime=$row_rs_entry['start']; $endtime=$row_rs_entry['end']; $diff=$endtime-$starttime; $periodno=($diff/$period)/60; for ($c=1; $c<$periodno; $c++) { $add=($c*$period)*60; $middle[$c]['time']=$start+$add; $middle[$c]['type']="middle"; } } while ($row_rs_entry=mysql_fetch_assoc($rs_entry)); This only makes an array of the first record. How do I get the rest?
  10. I've tried some solutions but am in a looping nightmare. Any suggestions? $today=date("l, F jS Y"); $dayofweek=date("w"); $month=date("m"); $day=date("d"); $year=date("Y"); $labID=$_GET['labID']; /////////////////////////////////// $avail=sprintf("SELECT * FROM lrms_res_avail WHERE resID='$insert_resourceID' AND Day='$dayofweek'"); $rs_avail=mysql_query($avail); $row_rs_avail=mysql_fetch_assoc($rs_avail); $numrows_avail=mysql_num_rows($rs_avail); //echo "Numrows: ".$numrows_avail."<br />"; $res_avail=sprintf("SELECT * FROM lrms_resource WHERE labID='$labID'"); $rs_res_avail=mysql_query($res_avail); $row_rs_res_avail=mysql_fetch_assoc($rs_res_avail); $numrows_res_avail=mysql_num_rows($rs_res_avail); ///////////////////////////////// if ($numrows_avail==0) { ///////////////////////////////// if ($numrows_res_avail==0) { echo ""; } else { echo "The availability for this day and resource have not been entered.\n"; echo "<br />Please enter availability <a href='lab_resources.php?labID=".$labID."'>here</a>.\n"; } ///////////////////////////////// } else { //for numrows avail ///////////////////////////////// $startlen=strlen($row_rs_avail['start_time']); //make sure start and end time 4 digits if ($startlen==3) { $start="0".$row_rs_avail['start_time']; } else { $start=$row_rs_avail['start_time']; } $endlen=strlen($row_rs_avail['end_time']); if ($endlen==3) { $end="0".$row_rs_avail['end_time']; } else { $end=$row_rs_avail['end_time']; } //Determine start and end $starthour=substr($start,0,2); $startmin=substr($start,2,2); $endhour=substr($end,0,2); $endmin=substr($end,2,2); //Convert to timestamp $startstamp=mktime($starthour, $startmin, 0, $month, $day, $year); $endstamp=mktime($endhour, $endmin, 0, $month, $day, $year); //Determine number of segments $period=($row_rs_avail['period']); //find number of minutes between start and end $diffstamp=($endstamp-$startstamp)/60; $periodno=$diffstamp/$period; //start table echo "<table width='300' class='table' cellspacing='0'>\n"; echo "\t<tr class='green'>\n"; echo "\t\t<th width='100'>Time</th>\n"; echo "\t\t<th width='200'>Reserved</th>\n"; echo "\t</tr>\n"; //find entries $entry=sprintf("SELECT * FROM lrms_entry WHERE resourceID='$insert_resourceID' AND start >='$startstamp' AND start <'$endstamp'"); $rs_entry=mysql_query($entry); $row_rs_entry=mysql_fetch_assoc($rs_entry); $numrecords=mysql_num_rows($rs_entry); //create range for($i=0;$i<mysql_numrows($rs_entry);$i++) { for($j=0;$j<mysql_num_fields($rs_entry);$j++) { $retval[$i][mysql_field_name($rs_entry,$j)] = mysql_result ($rs_entry,$i,mysql_field_name($rs_entry,$j)); }//end inner loop }//end outerloop //$rowstart=array(); $rowstart=$row_rs_entry['start']; $startrange[]=$rowstart; $rowend=$row_rs_entry['end']; $endrange[]=$rowend; $retval_count=count($retval); //create periods for ($i=0; $i<=$periodno; $i++) { //for loop #1 $add=($i*$period)*60; $newtime=$startstamp+$add; $newtime_date=date("G:i", $newtime); if (!in_array($newtime, $retval)) { echo "\t\t<tr><td align='right'>".$newtime_date."</td><td>".$newtime."</td></tr>\n"; } //loop through retval array for ($n=0; $n<$retval_count; $n++) { //for loop #2 if (in_array($newtime, $retval[$n])) { //if loop#1 $startval=$retval[$n]['start']; $endval=$retval[$n]['end']; //echo "Start Value: ".$startval."<br />"; if ($newtime==$startval) { echo "<tr>"; echo "\t\t<td align='right'>".$newtime_date."</td><td>"; echo "Start: "; echo $retval[$n]['userID']."</td></tr>\n"; } //create range for middle $rowstart=$retval[$n]['start']; $rowend=$retval[$n]['end']; $rowdiff=($rowend-$rowstart)/60; $periodrow=$rowdiff/$period; $rangeno=count($range); for ($j=0; $j<=$periodrow; $j++) { $addnew=($j*$period)*60; $range[$j]=$rowstart+$addnew; } $range=array($range); if (in_array($newtime, $range[0])) { echo "<tr>"; echo "\t\t<td align='right'>".$newtime." ".$newtime_date."</td><td>"; echo "Middle</td></tr>\n"; } if ($newtime==$endval) { echo "<tr>"; echo "\t\t<td align='right'>".$newtime_date."</td><td>"; echo "End: "; echo $retval[$n]['userID']."</td></tr>\n"; } } //end if loop#1 } //end for loop #2 } //end for loop #1 echo "</table>"; //////////////////////////////// } //end if num rows res avail /////////////////////////////////
  11. I am trying to create a day view of a lab resource reservation system. So far, I've been able to generate a day view table with php, using variables for start time, end time and periods. Periods represent intervals on the day view. I have two columns in the table: the first one starts at the start time (say 8:00) and there is a row for every time until the end time, each row time being increased by the period, ie. 8:00, 8:30, 9:00 where the period is 30 minutes and the end time is 9:00. My second column in the table is filled with unix timestamps representing the date for that particular row, so the 8:00 row on July 1, 2007 is represented by a timestamp of 1183291200. I then created variables to represent start and end times and date of a reserved lab resource. I did a little switch statement in my second column of my table saying, if that row's timestamp equals the start or end time of my reserved resource, than give it a certain style. All well and good, except I need to tie this into a mysql database where the reservation details (start, end, date) are stored. Where I am getting fuzzy is how to integrate the query results from the database into my little system. I would like to have that second column pick up the results from my query and display the reservations, but I'm not sure now to do that. I'd like to post the code here, but I'm not sure how to post php code on these forums without getting yelled at for doing it wrong (I did that once, can you tell?) Any help or advice would be appreciated.
  12. Beautiful! That is much more simple than trying to put an order in and it allows me to have a wider range of functions. I will try it!
  13. Would anyone have any suggestions as to how to set up a waitlist? Here is what I have: A user goes on to my site and registers for workshop. They are offered a list of open workshops or they can be waitlisted for workshops that are full. What would be the best way to structure this? I currently have 3 basic tables: users register (transaction info that connects users to workshop, has timestamp) workshops (info about each workshop, date, time, cap, etc.) My idea was to have an "order" field in the register table that would renumber itself every time someone registers or changes registration, but I am having difficulty with this renumbering. I was thinking I could use this order field to tell if someone's order has changed. So for instance, I cap the workshop at 5 people, and 6 people are registered. The 6th person is actually on a waiting list. Then someone drops out of the workshp and now that 6th person is the 5th person and is no longer on the wait list. I could create some php code that said, if the person's old order field is 6 and the new order field is 5, then send an email "you are registered!" That is what I am trying, but I am having difficult storing the old value and then renumbering and finding the new value. Any ideas?
×
×
  • 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.