PHP - Comparing Times In Mysql
Well I'm hoping someone will have some fun with this.
My database has a list of times for a given date, and a schedule for each time. I'm trying to change the input backgrounds for rows between 2 different times. Like this: 8:00 enter some data 8:10 enter some data 8:20 enter some data etc. What I want is to change the background color of any input field between say 9:00 and 10:00, but leave everything else white. I can change the color, just can't figure out how to compare the times. Here's part of the code: Code: [Select] while($row = mysql_fetch_array( $result )) { $opentimeID = date("g:i",strtotime(1530)); //not sure if these statements are correct. $closetimeID = date("g:i",strtotime(1730)); if (strtotime($row['Time']) //...not sure how to finish this statement to compare the time in the database row to $opentime and $closetime. { echo "<tr><td>"; echo date("g:i ", strtotime($row[Time])); echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player1]' name='player1[$i]' style ='background-color: #FFFF66;'>"; echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player2]' name='player2[$i]' style ='background-color: #FFFF66;'>"; echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player3]' name='player3[$i]' style ='background-color: #FFFF66;'>"; echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player4]' name='player4[$i]' style ='background-color: #FFFF66;'>"; echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player5]' name='player5[$i]' style ='background-color: #FFFF66;'>"; } else { echo "<tr>"; echo "<td>"; echo date("g:i ", strtotime($row[Time])); echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player1]' name='player1[$i]'>"; echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player2]' name='player2[$i]'>"; echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player3]' name='player3[$i]'>"; echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player4]' name='player4[$i]'>"; echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player5]' name='player5[$i]'>"; } Thanks for any advice! Similar TutorialsHey guys, im having a slight issue with comparing mysql time stamp. I'm using the timestamp in mysql to show how many people are online with in 5 minutes. $sql = mysql_query("SELECT name,id FROM users WHERE DATE_SUB(NOW(), INTERVAL 5 MINUTE) <= last_active ORDER BY id ASC"); But I want to grab last_active from the data base and compare it like below. I dont know if strtotime just doesnt compare with mysql time stamp or what? if($last_active > strtotime('-5 minutes')) { echo "<td>Online</td>"; }else{ echo "<td>Offline</td>"; } I have a table called "friends" and 4 columns called: id......friend_1......friend_2.......date I want to retrieve all of the friends of the user that is logged in, so if the table looks like: friend_1.........friend_2 3.........................6 6.........................8 12.......................3 the result if the users id is 3 would be: 6 12 and if the users id was 6 it would be: 3 8 the query I have right now partially works, just note sure how to modify it to get the full result I want. Code: [Select] $get_friends = mysql_query("SELECT * FROM friends WHERE (friend_1='".$session."' OR friend_2='".$session."')"); while($friends = mysql_fetch_array($get_friends)) { print $friends['friend_1']; }with the code above if you use the table I showed above and assumed that $session = 3, the result is: 3 12 but should be: 6 12 hopefully that's pretty straight forward, thanks in advanced. Hi all, I have the following code that queries a MySQL database and outputs results on-screen. Code: [Select] $result= mysql_query (" SELECT email,firstname,lastname FROM tablename WHERE ID IN('".$IDs."') "); if (!$result) {die('Error: Could not search database. ' );} while($row = mysql_fetch_assoc($result)) { echo $row['firstname']," ",$row['lastname'],"<br />"; $emails[]=$row['email']; } var_dump($emails); var_dump($IDs); However, the two var_dump's output the following (in the case of 2 results for the query): array(6) { => string(14) "email1@email.com" [1]=> string(23) "email2@email.com" [2]=> string(14) "email1@email.com" [3]=> string(23) "email2@email.com" [4]=> string(14) "email1@email.com" [5]=> string(23) "email2@email.com" } string(67) "9543219aa68ffa1d434dc8530f23fe48','d4384b2b493867706b0bcedda012ed48" ($IDs is an imploded array) Even though the MySQL table only contains one email per ID, both emails are listed 3 times in $emails, instead of just once. Can anyone see why this is? I'm stuck. Thanks! I am currently working on an application to schedule conferences. I have everything completed to create a conference including start time and duration. The problem I have now though is how do I monitor MySQL for the conferences that are created and perform actions when the duration of the conference is up? I was looking into MySQL events but those seem to be only internal events and are not able to execute anything outside of that. I was thinking about a infinite loop that queries MySQL and sleeps for one second but thought that this might be a lot of load on the server. Any thoughts I really appreciate it. Hello all, I'm collecting date/time information via a form and would like to convert the info into something that I can stick in my MySql database (a timestamp???). I'm collecting the current month (variable name: month-- of the form "mm"), day (variable name: day -- of the form "dd"), year (variable name: year -- of the form "yyyy"), time of day (variable name: time -- of the form "h:00"), and before or after noon (variable name: ampm -- of the form "am" or "pm"). Any suggestions as to how to change this into a quantity that I can store as a value and then use to compare to other date/times would be appreciated. Thanks! Hi, The main idea is that I have a client running on certain desktops. Each 5th minute the client sends and update to the web-server, increasing "tick" by one. Tick start out as 0, so after 5 minutes ticket should be greater than 5. If tick is not greater than 0 then do <code omitted> I Guess I would need some kind of cronjob to complete this, but i'd love to avoid sessions & cookies at all costs, as the same server is checking the same tick but for different accounts.. Any suggestions are highly appreciated ^.^ Hello everyone, I'm currently working on a large inventory management screen; the website has multiple "distributors" with their own inventory of products. Each distributor has the potential to carry the entire catalog of SKU's so right now, I have the stock/sku/dealer ID/product ID in one table with the product data/ID in another and am only inserting new rows if they are carrying the product. However they want to manage all of the inventory at once so I need to determine which IDs are update queries and which are insert queries. I'm trying to achieve this by comparing an array of the submitted data against an array of their existing inventory. If they don't have an entry for the submitted data key, we need to insert a new row for it to track their inventory. I just can't figure out how to get the keys to line up. Here is what I have; I tried to put it all into obviously defined variables for this forum. Code: (php) [Select] // assign our submitted values to an array $submitted_data = $_POST; // remove the SKUs with 0 or no inventory submitted $submitted_data = array_filter($submitted_data); // pull the distributor id out of the array before the insertion loop $distributors_inventory_distributor_ID = array_pop($submitted_data); // pull all existing inventory for this distributor to see if we are adding new inventory // or updating old inventory $existing_Inventory_Result = mysql_query("SELECT distributors_inventory_product_ID FROM distributors_inventory WHERE distributors_inventory_distributor_ID = $distributors_inventory_distributor_ID ORDER BY distributors_inventory_product_ID ASC", $db); // verify there is a result $existing_Inventory_num_results = mysql_num_rows($existing_Inventory_Result); if ($existing_Inventory_num_results > 0){ while($existing_Inventory_row = mysql_fetch_assoc($existing_Inventory_Result)){ // put existing inventory into an array $existing_Inventory[] = $existing_Inventory_row['distributors_inventory_product_ID']; } } $update_Inventory_Array = array_diff($submitted_data, $existing_Inventory); // print the array [DEBUG ONLY] echo '<h1>$update_Inventory_Array:</h1>'; print_r($update_Inventory_Array); echo '<hr/>'; echo '<h1>$submitted_data:</h1>'; print_r($submitted_data); echo '<hr/>'; echo '<h1>$existing_Inventory:</h1>'; print_r($existing_Inventory); That is outputting this: Quote $update_Inventory_Array: Array ( [963] => 5 [979] => 2 [982] => 2 [974] => 1 [32] => 5 ) $submitted_data: Array ( [963] => 5 [979] => 2 [982] => 2 [974] => 1 [32] => 5 ) $existing_Inventory: Array ( => 32 [1] => 963 [2] => 974 [3] => 979 ) I'd like it to be: Quote $update_Inventory_Array: Array ( [963] => 5 [979] => 2 [974] => 1 [32] => 5 ) $submitted_data: Array ( [982] => 2 ) $existing_Inventory: Array ( [32] => 5 [963] => 1 [974] => 1 [979] => 2 ) Can anyone suggest how to do this? I think if I could make the existing_Inventory array line up with my submitted_data array I could sort the rest out but I'm not sure how to get the keys/data to line up properly. Hello I am having a problem getting the difference between two arrays. The first array $list has all codes that can be linked to a specific id The second array $exist has the values select and linked to a specfic id. Both arrays are storing integers array $list should have 110,111,112,113,114,115. Array $exist gets 110, 114 115 from the database the difference should be 111 & 112 I think the problem is with array $exist that is getting its values from the database. Could the problem be that the arrys are storing data differently? How do I resolve this problem? /**==========ARRAY 1=======**/ /**All values for this type in array for comparison against**/ Code: [Select] $list = array('110','111','112','113','114','115'); /**view values in array $list**/ Code: [Select] var_dump($list); array(6) { [0]=> string(3) "110" [1]=> string(3) "111" [2]=> string(3) "112" [3]=> string(3) "113" [4]=> string(3) "114" [5]=> string(3) "115" } /**==========ARRAY 2=======**/ /**Get stored types for specific id **/ Code: [Select] $exist = array();//create array //store values in array $query = "SELECT type FROM contact WHERE id ='$id' AND deleted = 'N' ORDER BY type"; $result = mysqli_query ($mysqli, $query); while($row = mysqli_fetch_array($result)) { $exist[] = $row; } /**View values in array for specific id in array $exist**/ Code: [Select] var_dump($exist); array(3){ [0]=>array(2){ [0]=>string(3) "110" ["contact_type"]=> string(3) "110"} [1]=> array(2){[0]=> string(3) "114" ["contact_type"]=> string(3) "114"} [2]=> array(2){ [0]=> string(3) "115"["contact_type"]=> string(3) "115"}} /**==========RESULT=======**/ /**Get the difference between all possible type and stored values linked to a specific id **/ Code: [Select] $difference = array_diff($list, $exist); /**viewthe difference between the two arrays**/ Code: [Select] var_dump($difference); array(6) { [0]=> string(3) "110" [1]=> string(3) "111" [2]=> string(3) "112" [3]=> string(3) "113" [4]=> string(3) "114" [5]=> string(3) "115" } How in PHP am i able to select a date from a table and compare that date with a period of 2 months? In sql we use something like Quote select @2_months_later_date =dateadd(mm,2,getdate()) how would that be done in php? +-----------+----------------------------------+ | username | password | +-----------+----------------------------------+ | user | Hash | +-----------+----------------------------------+ This is what I have set up in my database(obviously I'm not going to put the real user or hash). I'm trying to md5 what the user inputs for a password and compare it to the database, but I keep getting failed login attempts. Code: [Select] <?php error_reporting(-1); ini_set('display_errors', 1); $host = "localhost"; $dbuser = "****"; $pass = "****"; $databasename = "login"; mysql_connect($host,$dbuser,$pass)or die('Could not connect: '.mysql_error()); mysql_select_db($databasename) or die(mysql_error()); if (isset($_POST["user"]) && isset($_POST["pwd"])) { $admin = mysql_query("SELECT username FROM members"); $pass = mysql_query("SELECT password FROM members"); if ($_POST["user"] == $admin && md5($_POST["pwd"]) == $pass) { session_register("admin"); session_register("pass"); header('Location:https://deadnode.com/output.php'); } else { echo"<center><h1>Failed login attempt.</h1></center>"; } } ?> Hello
I have two arrays of mysql values $a1, $b1
I am trying to loop through each $a value, no problem,
but I want to see if each element in $a = one of the values in $b
so:
$a = array(1, 2, 3, 4, 5, 6); $b = array(4, 6); $y = ''; foreach ($a1 as $a){ foreach ($b1 as $b){ if ($a[val] == $b[val]){ $y = '*'; } } echo $y.$a.'<br />'; }I was kinna hoping it would give me 1 2 3 *4 5 *6 Its most definitely not though... Im sure Im flawed in my logic but have coded so much other crap I just can't see the answer! ty for the look/help. im having problem comparing timestamps in my where clause for some strange reason...my query works perfect but when adding WHERE it doesn't bring up a result although it should...I've been playing about with it for almost a day now...and it doesn't make sense
unix_timestamp values start_date_time 1406411505 end_date_time 1407275505 now 1406461573my query SELECT i.item_id, i.title, i.price, @start_date_time := CONVERT_TZ(i.start_date_time, '+00:00', u.time_zone), @end_date_time := DATE_ADD(@start_date_time, INTERVAL 10 DAY), @end_date_time AS `end_date_time` FROM items i LEFT JOIN sub_categories sc ON sc.sub_category_id = i.sub_category_id LEFT JOIN categories c ON c.category_id = sc.category_id JOIN users u ON username = 'Destramic' WHERE UNIX_TIMESTAMP(@start_date_time) < UNIX_TIMESTAMP(NOW()) AND UNIX_TIMESTAMP(@end_date_time) >= UNIX_TIMESTAMP(NOW())if anyone can diagnose my problem I'd it would be much appreciated I am writing a program which checks the results for a student. If the results are same as the ones inside the table, then correct message is printed. If the results are not the same then the right answer should be printed as well as wrong message and the answer the user selected. I am using checkbox to let the user choose the answers and this is saved on to the database. I need to retrieve this and compare this with the original table. my tables are Answer: ,Ans_ID,Ans_Answer1, Ans_Answer2, Ans_Answer3, Ans_Answer4,Que_ID Question:Que_ID, Que_Answer1, Que_Answer2, Que_Answer3, Que_Answer4 Answer table is what the user enters and the question table is the one with the correct answer. Code: [Select] SELECT Ans_ID, IF(answer.Ans_Answer1 = question.Que_Answer1 AND answer.Ans_Answer1 = question.Que_Answer1 AND answer.Ans_Answer1 = question.Que_Answer1 AND answer.Ans_Answer1 = question.Que_Answer1, "Correct","Wrong") AS result FROM answer LEFT JOIN question ON answer_id = question_id can someone give me ideas, not asking for you to write the code for me. just help me out as I am stuckk Hi. I have a MySQL database with 4 different fields. id, customer, case and status. No problems of getting them to show up on my page but.. I would like to change the row bgcolor depending of field value on "customer". For example row color would be white until customer changes, then color yellow until customer changes again and back to white etc.. Hope you get the point. Is this possible? Thanks. Hey I have a quick question. I am trying to have a part of this PHP script compare two numbers. There is a randomly generated two-digit number named $random and There is another two digit number named $number. I want to make it so the PHP checks to see if $number has any of the same charcters as $random. I don't know how to do this though. I suspect that somehow both numbers need to be broken apart somehow. Any advice would be appreciated. Let me know if I should explain it more clearly Thanks a ton! Hi all I am having massive problems comparing the out put of array, basically my end result is to choose a selected option on a drop down in a form. I am trying to compare the output of ['allow-nether'] which is either true or false in my file. Here is what I have tried //code to get file contents Code: [Select] $file_handle = fopen("saves/server.properties", "rb"); $vars = array(); while (!feof($file_handle) ) { $line_of_text = fgets($file_handle); $parts = explode('=', $line_of_text); //if date not required if ( !isset($parts[1]) ) { continue; } $vars[$parts[0]] = $parts[1]; } Code: [Select] <?php //allow nether =false in file echo "1 " .$vars['allow-nether']; if ( $vars['allow-nether'] == true ) { echo '<br>2 selected="selected"';} if ( $vars['allow-nether'] == false ) { echo '<br>3 selected="selected"';} if ( $vars['allow-nether'] == "true" ) { echo '<br>4 selected="selected"';} if ( $vars['allow-nether'] == "false" ) { echo '<br>5 selected="selected"';} if ( $vars['allow-nether'] === true ) { echo '<br>6 selected="selected"';} if ( $vars['allow-nether'] === false ) { echo '<br>7 selected="selected"';} if ( $vars['allow-nether'] === "true" ) { echo '<br>8 selected="selected"';} if ( $vars['allow-nether'] === "false" ) { echo '<br>9 selected="selected"';} ?> which outputs: Code: [Select] 1 false 2 selected="selected" and if I set the file to allow-nether=true Code: [Select] <?php //allow nether =true in file echo "1 " .$vars['allow-nether']; if ( $vars['allow-nether'] == true ) { echo '<br>2 selected="selected"';} if ( $vars['allow-nether'] == false ) { echo '<br>3 selected="selected"';} if ( $vars['allow-nether'] == "true" ) { echo '<br>4 selected="selected"';} if ( $vars['allow-nether'] == "false" ) { echo '<br>5 selected="selected"';} if ( $vars['allow-nether'] === true ) { echo '<br>6 selected="selected"';} if ( $vars['allow-nether'] === false ) { echo '<br>7 selected="selected"';} if ( $vars['allow-nether'] === "true" ) { echo '<br>8 selected="selected"';} if ( $vars['allow-nether'] === "false" ) { echo '<br>9 selected="selected"';} ?> Gives: Code: [Select] 1 true 2 selected="selected" What am I doing wrong? Does anybody know how I would turn this into functioning code. if $_SERVER[REQUEST_TIME] is 15 minutes greater than $time_in_database; echo 'time is 15 minutes greater'; Thanks for any help When a file is uploaded, I wish to determine whether an existing identical file (regardless of what it is named or what extension it has) already exists and if so don't save the newly uploaded file but just point it to the existing one. My primary reason for doing so is not really to save hard drive space but to be able to manage duplicate documents. One option is to store a hash of the documents in the DB and when a new document is uploaded, query the DB to see if an identical hash exists. How certain can one be that two hashes will never be duplicated? Another option is to compare the byte stream. For this, I would first query the DB to see if a file with same size and media type exists, and then compare the document to all existing files which have that same criteria. Or many some other approach? Recommendations? Thanks
<?php error_reporting(E_ALL); ini_set('display_startup_errors', 1); ini_set('display_errors', 1); function compareFilesTest(string $file_a, string $file_b) { $time = microtime(true); display($time, $file_a, $file_b, 'compareFilesTest', compareFiles($file_a, $file_b)); } function compareFilesTest2(string $file_a, string $file_b) { $time = microtime(true); display($time, $file_a, $file_b, 'compareFilesTest2', identical($file_a, $file_b)); } function compareFilesHashTest(string $file_a, string $file_b, string $algo = 'md5') { $time = microtime(true); display($time, $file_a, $file_b, 'compareFilesHashTest', hash_file($algo, $file_a)===hash_file($algo, $file_b), $algo); } function display(float $time, string $file_a, string $file_b, string $test, bool $status, string $algorithm=null) { printf("\n%s\nFile1: %s\nFile2: %s\nStatus: %s\nTime (uS): %d\n", $test.($algorithm?" ($algorithm)":''), $file_a, $file_b, $status?'EQUAL':'NOT EQUAL', 1000000*(microtime(true) - $time)); } function compareFiles(string $file_a, string $file_b):bool { if (filesize($file_a) == filesize($file_b)) { $fp_a = fopen($file_a, 'rb'); $fp_b = fopen($file_b, 'rb'); while (!feof($fp_a) && ($b = fread($fp_a, 4096)) !== false) { $b_b = fread($fp_b, 4096); if ($b !== $b_b) { fclose($fp_a); fclose($fp_b); return false; } } fclose($fp_a); fclose($fp_b); return true; } return false; } function identical($fileOne, $fileTwo) { if (filetype($fileOne) !== filetype($fileTwo)) return false; if (filesize($fileOne) !== filesize($fileTwo)) return false; if (! $fp1 = fopen($fileOne, 'rb')) return false; if (! $fp2 = fopen($fileTwo, 'rb')) { fclose($fp1); return false; } $same = true; while (! feof($fp1) and ! feof($fp2)) if (fread($fp1, 4096) !== fread($fp2, 4096)) { $same = false; break; } if (feof($fp1) !== feof($fp2)) $same = false; fclose($fp1); fclose($fp2); return $same; } $path = __DIR__.'/test_documents/'; //print_r(hash_algos()); compareFilesHashTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c07af00c_IMG_1225.jpg'); compareFilesHashTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c1c96440_MasterFormat-2016.pdf'); compareFilesHashTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'x602a9c07af00c_IMG_1225.jpg'); compareFilesHashTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c07af00c_IMG_1225.jpgx'); compareFilesHashTest($path.'file1.txt', $path.'file2.md'); compareFilesHashTest($path.'file1.txt', $path.'file3.txt'); compareFilesHashTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c07af00c_IMG_1225.jpg', 'sha256'); compareFilesHashTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c1c96440_MasterFormat-2016.pdf', 'sha256'); compareFilesHashTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'x602a9c07af00c_IMG_1225.jpg', 'sha256'); compareFilesHashTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c07af00c_IMG_1225.jpgx', 'sha256'); compareFilesHashTest($path.'file1.txt', $path.'file2.md', 'sha256'); compareFilesHashTest($path.'file1.txt', $path.'file3.txt', 'sha256'); compareFilesTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c07af00c_IMG_1225.jpg'); compareFilesTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c1c96440_MasterFormat-2016.pdf'); compareFilesTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'x602a9c07af00c_IMG_1225.jpg'); compareFilesTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c07af00c_IMG_1225.jpgx'); compareFilesTest($path.'file1.txt', $path.'file2.md'); compareFilesTest($path.'file1.txt', $path.'file3.txt'); compareFilesTest2($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c07af00c_IMG_1225.jpg'); compareFilesTest2($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c1c96440_MasterFormat-2016.pdf'); compareFilesTest2($path.'602a9c07af00c_IMG_1225.jpg', $path.'x602a9c07af00c_IMG_1225.jpg'); compareFilesTest2($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c07af00c_IMG_1225.jpgx'); compareFilesTest2($path.'file1.txt', $path.'file2.md'); compareFilesTest2($path.'file1.txt', $path.'file3.txt');
Hello (I think this is more of a php question than MySQL - sorry if I have got it wrong.) I need to know if items have been orphaned (because they lack a cat_id that actually exists). I have two MySQL tables that each have fields 'cat_id'. I have a Category table... cat_id / category 1 / fruit 2 / veg 3 / tools I have another product table cat_id / product 1 / apple 1 / Pear 2 / carrot 2 / cabbage 3 / screwdriver 1 / peach 8 / orphan I have entered the data into two arrays... $categories[] $products[] I have tried a number of combinations of foreach loops to try to determine if the products(cat_id) doesn't match the categories(cat_id) but I seem to be going around in circles. Is there perhaps a function that is available to do this? Or maybe just a straight thinking person that can point out my ineptitude? Thank you for any input. hi i have to compare dates one from database and other from the loops ..if they match background color will change ... so far i have done very thing but the problem i am getting that in while loop i am getting one date to compare with all 365 days in the year ...which are coming from the loop.. i need help to solve this... <?php if (isset($emplistshow) && ($emplistshow == 'show')) { $monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); ?> <div class="outerbox" style=" float: left;"> <table colspan="5" rowspan="4"> <tr > <td width="18%" colspan="2"><strong>Month</strong></td> <td width="12%" colspan="2"><strong>Division</strong></td> <?php for($m=1;$m <=31;$m++) { ?> <td width="26" height="20px" align="center" valign="middle" ><?php echo $m; ?></td> <?php } ?> </tr> </table> </div> <div class="outerbox" style=" float: left;"> <table > <?php //$sql ="SELECT leave_date,leave_type_id,leave_request_it, FROM `hs_hr_leave` WHERE employee_id = $emplid "; //loop to print numbers if months in a given year for($Month=1;$Month <= 12;$Month++) { ?> <tr> <td width="18%" colspan="2"><strong><?php echo $monthNames[$Month-1]; ?></strong></td> <td width="12%" colspan="2"><strong>Division</strong></td> <?php $num = cal_days_in_month(CAL_GREGORIAN, $Month, $cYear); // 31 //$dates = date("$cYear-$Month-1"); $sql ="SELECT leave_date,leave_status,leave_comments,leave_type_id,emp_depment FROM `hs_hr_leave` WHERE employee_id = $emplid "; $res = mysql_query($sql); //loop to print numbers if days in a given month for($i=1;$i<=$num;$i++) { ///$dates = date("$cYear-$Month-$i"); $dates = date("Y-m-d", mktime(0, 0, 0, $Month, $i, $cYear)); $checkdate = strtotime($dates); //loop to print dates from database while ($row = mysql_fetch_array($res, MYSQL_NUM)) { //echo $time2=date("Y-n-j",strtotime ($row[0])).'<br/>'; //here you have to seprate the year month and day coming from db and pas it to mktime function as doing above ///like $dates = date("Y-n-d", mktime(0, 0, 0, $Month, $i, $cYear)); $status = $row[1]; $comments = $row[2]; $typeid = $row[3]; $depment = $row[4]; $dbD = date("d", strtotime($row[0])); $dbM = date("m", strtotime($row[0])); $dbY = date("Y", strtotime($row[0])); $dbuser = date("Y-m-d", mktime(0, 0, 0, $dbM, $dbD, $dbY)); $userDates = strtotime($dbuser); //echo $dbuser.'<br/>'; //echo $dates.'<br/>'; } //echo $dbuser.'<br/>'; //echo $checkdate ."==". $userDates.'<br/>'; if($checkdate == $userDates) { //echo $typeid ; $cSql = "SELECT leave_type_name,leave_color FROM hs_hr_leavetype WHERE leave_type_id = '$typeid' "; $cRes = mysql_query($cSql); while ($color = mysql_fetch_array($cRes, MYSQL_NUM)) { //echo $color[1]; //echo $color[0]; //echo $status."<br/>"; echo "<td width='26' title='".$comments."' height='20px' bgcolor='#".$color[1]."' align='center' valign='middle' >"; if($status == -1) { echo "R"; } elseif ($status == 0 ) { echo "C"; } elseif ($status == 1 ) { echo "PA"; } elseif ($status == 2 ) { echo "A"; } elseif ($status == 3 ) { echo "T"; } elseif ($status == 4 ) { echo "W"; } elseif ($status == 5 ) { echo "SH"; } echo "</td>"; } } else { echo "<td width='26' height='20px' align='center' valign='middle' >".$i."</td>"; } } } ?> </tr> </table> |