PHP - Problem Comparing Dates
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> Similar Tutorialshey guys, i have my code set up to run substrings through a db to check for matches...even when there is a match it wont insert correctly Code: [Select] $result = mysql_query("select * from friends where userid=$userid"); while($row = mysql_fetch_assoc($result)) { $first_name = $row['first_name']; $last_name = $row['last_name']; $strpos_1 = strpos($friend_1, ' '); $substr_1 = substr($friend_1, 0, $strpos_1); $substr_2 = substr($friend_1, $strpos_1); if($substr_1 == $first_name && $substr_2 == $last_name) { $sql = "insert into fav_friends values('', '$userid', '$friend_1', '$friend_2', '$friend_3', '$friend_4', '$friend_5', '$friend_6')"; $query = mysql_query($sql); } } and i don't receive any errors, any thoughts? Hi All, I need to subtract dates and display the number of days left. I have a 'Start' date and an 'End' date in DATETIME format in the DB. Not quite sure where to start. A simply start - end doesn't work . Start = 2011-11-01-00:00:00 End = 2011-11-30-23:59:59 Since it is now 2011-11-27, my output should equal 3. Any help is appreciated. Hi PHPFreaks.com I wrote in here a while ago about updating table rows by selecting rows which end dates is greater than the current day, much like a experation dates with blog posts in a CMS. I was told to make sure my datatype for the end dates in the database was the datetime format is YYYY-MM-DD HH:mm:SS now I have now changed that, but I am still have trouble creating a query that does exactly what I mentioned. mysql_query("UPDATE ". $db_prefix ."events WHERE end_time >= TIMESTAMP: Auto NOW() SET cat = 1" ); Now what I am trying to is that if the current time is greater than the end date I need the "cat" row changed to 1 So thanks in advance if you can help me guys Hi guys, I am trying to do a multidates events availability calender. The script below indicates todays date by highlighting an orange colour and also indicates the start and end date of the event highlighting grey colour on the two dates (The colour are link via css classes as shown). Code: [Select] //Today's date $todaysDate = date("d/m/Y"); $dateToCompare = $daystring . '/' . $monthstring . '/' . $year; echo "<td align='center' "; if($todaysDate == $dateToCompare){ echo "class='today'"; }else{ //Compare's the event dates $sqlcount = "select event_start,event_end from b_calender where event_start ='".$dateToCompare."' AND event_end='".$dateToCompare."'"; $noOfEvent = mysql_num_rows(mysql_query($sqlcount)); if($noOfEvent >= 1){ echo "class='event'"; } } It works ok i.e. if start date = 01/01/2012 and end date = 04/01/2012 both date will be highlighted with grey colour. However I want it to also highlight grey on the dates between the 1st and 4th to show that then anydates between the 1st and 4th are not available and this is when I'm stuck. Please guys I need help. 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 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" } 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 +-----------+----------------------------------+ | 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>"; } } ?> 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! 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? 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. 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. 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 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. 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');
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! This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=330820.0 Hey 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 am comparing 2 decimal numbers I am pulling from a mysql file for ex $row[0]==$row1[0] every once in a while i get a bad positive when I do if($row[0]==$row1[0]) when they are exactly the same? One query is a SELECT amount FROM table the other is a select SUM(amount) FROM table2 any ideas why? ive tried making them both abs() when I print the out they are = 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. |