pavankat Posted April 1, 2012 Share Posted April 1, 2012 I'm having trouble getting this to work. Basically I'm trying to get everything in the red boxes in the below picture to not show. http://content.screencast.com/users/rockstarvisible/folders/Jing/media/4a50bc73-f3b9-4fbd-824b-e63413e85c06/2012-04-01_1540.png Here's a screen shot of the mysql table it's pulling from: http://content.screencast.com/users/rockstarvisible/folders/Jing/media/7ec2c110-25c3-45a5-a2e6-e6c3e029b41c/2012-04-01_1842.png Only the new dosage (on row 2 of the mysql table) should start showing from march 15th and on. However, currently both dosages are showing on March 15th and on. How do I change this? Here's my code: //---------------------------------------------------drug dosage information //query database and grab dosages for different days of the week $query_drug_dosage = "SELECT * FROM `users_drug_dosage` WHERE users_drug_dosage.user_id =". $_SESSION['user_id']. " ORDER BY users_drug_dosage.id"; $query_run_drug_dosage = mysql_query($query_drug_dosage) or die(mysql_error()); //create id array $id_array = array(); while ($row_drug_dosage = mysql_fetch_assoc($query_run_drug_dosage)){ $id = $row_drug_dosage['id']; $sdd_day = $row_drug_dosage['calendar_day']; $sdd_month = $row_drug_dosage['calendar_month']; $sdd_year = $row_drug_dosage['calendar_year']; $mon_dd = $row_drug_dosage['mon_dd']; $tue_dd = $row_drug_dosage['tue_dd']; $wed_dd = $row_drug_dosage['wed_dd']; $thur_dd = $row_drug_dosage['thur_dd']; $fri_dd = $row_drug_dosage['fri_dd']; $sat_dd = $row_drug_dosage['sat_dd']; $sun_dd = $row_drug_dosage['sun_dd']; //if current date >= start date of dosage if (mktime(0, 0, 0, $month, $list_day, $year) >= mktime(0, 0, 0, $sdd_month, $sdd_day, $sdd_year) ) { //switch to find out what day of the week //the current date is and then pull the drug dosage //for that specific date switch (date("D", mktime(0, 0, 0, $month, $list_day, $year))) { case 'Mon': $drug_dosage = $mon_dd; break; case 'Tue': $drug_dosage = $tue_dd; break; case 'Wed': $drug_dosage = $wed_dd; break; case 'Thu': $drug_dosage = $thur_dd; break; case 'Fri': $drug_dosage = $fri_dd; break; case 'Sat': $drug_dosage = $sat_dd; break; case 'Sun': $drug_dosage = $sun_dd; break; } //store current id in the id array $id_array[] = $id; //find current id in id array //$key1 = array_search($id, $id_array); //echo 'key 1: ' . $key1; foreach ($id_array as $value){ if ($value == $row_drug_dosage['id']){ $calendar.= str_repeat('<div class="drugdosages">Dosage: '.$drug_dosage.' Mg</div>',1); } } //echo '<br/><br/>'; //print_r($id_array); //echo '<br/><br/>'; } } //---------------------------------------------------drug dosage information this is how I think I should do it, but i'm not sure at all: pull in all the dates for all the rows in the drug dosage table join them together by a / and join function and put into an array then do a for each loop for each value in the array explode the value and seperate by / and then use that for the $sdd_month, $sdd_day, $sdd_year Quote Link to comment Share on other sites More sharing options...
ocpaul20 Posted April 2, 2012 Share Posted April 2, 2012 Pull out the part you are having a problem with and give us that to sort out for you. Write a mickey mouse(simple) program to hide the thing you want to hide and get that working first. Then insert your other code into it. You are unlikely to get help for this amount of problem code I am afraid. It is human nature unfortunately. Quote Link to comment Share on other sites More sharing options...
batwimp Posted April 2, 2012 Share Posted April 2, 2012 Without being able to actually run and test your code, I'm going to assume that it's because you're using >= to determine the dosage information on your dates. Since the old dosages are still within the date range, it's counting them as valid. You may want to add an end date to your dosages and the code to weed out the dosages based on both start and end times. Quote Link to comment Share on other sites More sharing options...
sunfighter Posted April 2, 2012 Share Posted April 2, 2012 If you used DATE instead of calendar_month calendar_day calendar_year things would be so much easier. You need to have session_start as your first line in this script. You also need to get the date of the calendar day you are getting the dosage for and then do something like this for the query: SELECT * FROM `users_drug_dosage` WHERE users_drug_dosage.user_id =1 // Or the info from sessions AND calendar_month <= 3 AND calendar_year = 2012 AND calendar_day <= 14 ORDER BY calendar_day DESC LIMIT 1 I'm using the SELECT but you having everything in the while ($row_drug_dosage = mysql_fetch_assoc($query_run_drug_dosage)){ line should do this in that loop. Only write the array if the query day is greater or equal to the current calendar day you are writing. Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 2, 2012 Share Posted April 2, 2012 I'm not understanding your database structure from what is provided, but I'll try to offer some suggestions based on what I *think* you may have. I assume your records have a start date. But, do they also have an end date? If not, you should consider creating such a filed. So, just leave the end date NULL if that record is supposed to be used indefinitely. Then if you add a new record for the same prescription set the start date for that record and also set the end date for the previous record. Then, when you run your query, just grab all records for the user where the start date is before the end of the calendar period you are showing AND where the end date is NULL or greater than the start date for the calendar. Lastly, while processing the records you can use the end date value to determine if a particular record should be displayed on any given day. Quote Link to comment Share on other sites More sharing options...
sunfighter Posted April 2, 2012 Share Posted April 2, 2012 Went outside TOO HOT to do anything, but did have to go to town. Back and worked on this. This part will give you what you want. You'll have to make the calendar: <?php session_start(); $_SESSION["user_id"] = 1; // only because I don't have this set - you do so delete line // conect to your database here $drug_start_day = 8; // Needed because we have nothing for the first part of the month $today = 15; //$today = date('d'); use this instead of the above line /* ### You have trouble next month because your not using DATE = ex. 2012-03-08 */ $link = mysql_connect($DBhost,$username,$password) or die("Unable to connect to host"); $link = mysql_select_db($database) or die( "Unable to connect database"); $query_drug_dosage = "SELECT * FROM `users_drug_dosage` WHERE users_drug_dosage.user_id = ".$_SESSION["user_id"]." ORDER BY calendar_day DESC"; $query_run_drug_dosage = mysql_query($query_drug_dosage) or die(mysql_error()); if($today >= $drug_start_day){ $id_array = array(); while($row_drug_dosage = mysql_fetch_assoc($query_run_drug_dosage)) { $id = $row_drug_dosage["id"]; $sdd_day = $row_drug_dosage["calendar_day"]; $sdd_month = $row_drug_dosage["calendar_month"]; $sdd_year = $row_drug_dosage["calendar_year"]; $mon_dd = $row_drug_dosage["mon_dd"]; $tue_dd = $row_drug_dosage["tue_dd"]; $wed_dd = $row_drug_dosage["wed_dd"]; $thur_dd = $row_drug_dosage["thur_dd"]; $fri_dd = $row_drug_dosage["fri_dd"]; $sat_dd = $row_drug_dosage["sat_dd"]; $sun_dd = $row_drug_dosage["sun_dd"]; if($sdd_day <= $today) break; } echo $sdd_day; // here just to show you what it got. } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.