PHP - Select Overdue Record Using Date Type Column
Ok basic setup is
Table name = unit_data I have a field unit_paid_date colum type = DATE unit_paid_date = 2011-03-02 thats yyyy-mm-dd lets say for example the DueDate is the Second of every month I need to select all records from unit_data that are PAST DUE so if the last paid date is 2011-01-02 that record will pop up as PAST DUE BUT if that paid date is say 2011-03-10 it will not be shown because the invoice was paid Ahead of due date I had this almost working properly -- but can use any help you guys offer. I was attempting to use mysql WHERE queries and do checks against paid_date but failed Thanks Similar Tutorialsis it possible to do something like Code: [Select] $today = date("Y-m-d"); $result = mysql_query("SELECT * FROM staff where date = '.$today.' "); also, is it normal for the first entry in the database not to be displayed? i have 6 entries in a table and only 2-6 are shown. when i changed the id for 1 to 7, it only displayed 3-7. Hellow, i need help please, writing code and it doesn't work. please help...
Here it is
WHERE start_date BETWEEN 'start_date".strtotime('-3 day')."' AND 'start_date'";without this code everithing works fine Thank you I am learning PHP/MySQL and am modifying a tutorial to make a contact database. All I want is to be able to make a web page for each contact(record) and display one record on each webpage. I want to use the URL featu "http://www.mysite.com/script.php?=item1" type of thing Can any help me as I can't get it to work. I get no errors - it just doesnt display the info. I'm sure I cant be far off as I've only modified a working script ever so slightly. Code: [Select] mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); ?> <? $query="SELECT * FROM contacts WHERE id='$id'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; ?> <table border="0" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif">Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Phone</font></th> <th><font face="Arial, Helvetica, sans-serif">Mobile</font></th> <th><font face="Arial, Helvetica, sans-serif">Fax</font></th> <th><font face="Arial, Helvetica, sans-serif">E-mail</font></th> <th><font face="Arial, Helvetica, sans-serif">Website</font></th> </tr> <? $i=0; while ($i < $num) { $first=mysql_result($result,$i,"first"); $last=mysql_result($result,$i,"last"); $phone=mysql_result($result,$i,"phone"); $mobile=mysql_result($result,$i,"mobile"); $fax=mysql_result($result,$i,"fax"); $email=mysql_result($result,$i,"email"); $web=mysql_result($result,$i,"web"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><? echo "$first $last"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$phone"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$mobile"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$fax"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><a href="mailto:<? echo "$email"; ?>">E-mail</a></font></td> <td><font face="Arial, Helvetica, sans-serif"><a href="<? echo "$web"; ?>">Website</a></font></td> </tr> <? ++$i; } echo "</table>"; ?> Hi i have this drop down list for date which contain 3 selects DAY MONTH YEAR hwo can i make so that when update form select keeps the same value has before help please <?php $months = array('','January','February','March','April','May','June','July','August','September','October','November','December'); echo '<select name="month_of_birth">'; for ($i=1;$i<13;++$i) { echo '<option value="' . sprintf("%02d",$i) . '">' . $months[$i] . '</option>'; } echo '</select>'; echo '<select name="day_of_birth">'; for ($i=1;$i<32;++$i) { echo '<option value="' . sprintf("%02d",$i) . '">' . $i . '</option>'; } echo '</select>'; echo '<select name="year_of_birth">'; $year = date("Y"); for ($i = $year;$i > $year-50;$i--) { $s = ($i == $year)?' selected':''; echo '<option value="' . $i . '" ' . $s . '>' . $i . '</option>'; } echo '</select>'; ?> Hey guys! I'm making a locally run web based application for entering/storing/editing data. I am trying to do this thing where I export a 'records.txt' file to a different location which can be selected by the user. I have a lame <input type='text' value='H:\'> box going on which I was going to use to define the path for the file to be saved, but I want to be able to use a pop up windows (or whatever native OS finder application) just like the one which appears when you use <input type='file'>. Now that I think about it, I think this is more of a html question, but it's 2.30am and my project is due today... See! what the hell, I just habitually pressed ctrl-s after working in dreamweaver for hours and the exact function which I am looking for popped up, how do I do that?! Please thanks guys I have a calendar select date function for my form that returns the date in the calendar format for USA: 02/16/2012. I need to have this appear as is for the form and in the db for the 'record_date' column, but I need to format this date in mysql DATE format (2012-02-16) and submit it at the same time with another column name 'new_date' in the database in a hidden input field. Is there a way to do this possibly with a temporary table or something? Any ideas would be welcome. Doug The Script:
<?php include("connect.php"); ?> <?php echo "<h1>The Hashtag: </h1>"; if(isset($_GET['hashtag'])){ echo $_GET['hashtag']; } // Select the ID of the given hashtag from the "hashtags" table. $tqs = "SELECT `id` FROM `hashtags` WHERE `hashtag` = '" . $_GET['hashtag'] . "'"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); $row = mysqli_fetch_assoc($tqr); // This prints e.g.: // 100 echo "<br/><br/>"; print_r($row['id']); // Select the threads from the "thread" table which contains the hashtag ID number. $tqs_two = "SELECT * FROM `thread` WHERE `hashtag_id` IN ('" . $row['id'] . "')"; $tqr_two = mysqli_query($dbc, $tqs_two) or die(mysqli_error($dbc)); $row_two = mysqli_fetch_assoc($tqr_two); echo "<br/><br/>"; print_r($row_two); ?>The script should select the rows by that ID number of the hashtag. It should look in the "hashtag_id" column of the table and see if that ID number can be found there, if it can be found there, then it should select that row. The ID numbers are inside that "hashtag_id" column separated by commas. Example: 98, 99, 100My Question: How to do the SQL query so it selects the rows by the hashtag ID number? Edited by glassfish, 17 October 2014 - 10:35 AM. Hi, I've been scratching my head for a while now about how to do this, I'm relatively new to php and mysql and perhaps foolishly taking on creating a user area for a website. I have everything else working, all of my register account functions and confirmations and all of the login scripts etc. I have created a profile page which returns various information to the user (this bit works fine) and I've got some nice show/hide toggles running with some javascript/css but my intention is to allow the user to change thier information (e-mail address, contact phone number and also whether they are subscribed to the e-mail list), it also displays any support tickets or messages. So after the long intro, here's what I'm struggling with... I have a form in a visibility toggled <div> which submits a 'change_email' script, so a user wants to change their e-mail, clicks on change, the <div> appears, they bang in the new e-mail and hit submit. My php script appears to work (because it doesn't throw up any errors), until you realise that actually it's not updated the record in the db... I'm using mysql_query("UPDATE users SET email='$new_email' WHERE username='$user'"); Do I need to setup variables for all of the information in the db (name, username, password, email, contno etc etc) and include them in the command to get it to work or should that just pick the correct record and then update it? If that is the case is there a way I can include 'blank' variables so I don't have to set them all up... e.g. mysql_query("UPDATE users SET user='',password='',email='$new_email', etc WHERE username='$user'"); Many thanks in anticipation Please I want get data from mysql; 1. The last 24 hours. 2 the last 7 days 3. the last Months 4. Last 12 hours please try and help me I have searched this forum as well as over 200 other forums and have not found the answer that is specific to my question. I have shortened my code drastically to assist in resolving this quickly -
I have a search form that has criteria for the search criteria with "virtual" "columns" in an array but it's not working. If I search one column at a time it works just fine but when I try to search 8 columns with one select I get the following error: SELECT Error: Unknown column 'achievements' in 'where clause'.
When a user selects search in Achievements, I need it to look at all 8 columns that are associated with achievements and bring back the results that match - the same as if the user selects search in Associations, I need it to look at all 5 columns and bring back the results that match.
My shortened code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Search</title> </head> <body> <form name="search" action="" method="POST"> <p>Search:</p> <p> Achievements/Associations: <input type="text" name="find1" /> in <Select NAME="field1"> <Option VALUE="achievements">Achievements</option> <Option VALUE="associations">Associations</option> </Select> <br><br> Secondary Education: <input type="text" name="find2" /> in <Select NAME="field2"> <Option VALUE="edu1sectype">Highest Certificate Attained</option> <Option VALUE="edu1secname">Highest Grade Passed</option> <Option VALUE="edu1secinst">Name of High School</option> <Option VALUE="edu1secdate">Date Completed</option> <Option VALUE="edu1secinsttyp">Type of Institution</option> <Option VALUE="subjects">Subjects</option> </Select> <br><br> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </p> </form> <?php $searching = $_POST['searching']; $find1 = $_POST['find1']; $field1 = $_POST['field1']; $find2 = $_POST['find2']; $field2 = $_POST['field2']; if ($searching =="yes") { echo "<br><b>Searched For:</b> $find1 $find2<br>"; echo "<br><h2>Results</h2><p>"; //If they did not enter a search term we give them an error // Otherwise we connect to our Database include_once "connect_to_mysql.php"; mysql_select_db("table_name") or die(mysql_error()); // We preform a bit of filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim($find); $find = mysql_real_escape_string($find); $field = mysql_real_escape_string($field); $data = mysql_query("SELECT * FROM table_name WHERE upper(".$field1.") LIKE '%$find1%' AND upper(".$field2.") LIKE '%$find2%' ") or die("SELECT Error: ".mysql_error()); $result = mysql_query("SELECT * FROM table_name WHERE upper($field1) LIKE '%$find1%' AND upper($field2) LIKE '%$find2%' ") or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); echo "There are $num_rows records:<br>"; echo '<center>'; echo "<table border='1' cellpadding='5' width='990'>"; // set table headers echo "<tr><th>Reference</th> <th>First Name</th> <th>Last Name</th> </tr>"; //get images and names in two arrays $name= $row["name"]; $surname= $row["surname"]; $achieve1 = $row["achieve1"]; $achieve2 = $row["achieve2"]; $achieve3 = $row["achieve3"]; $achieve4 = $row["achieve4"]; $achieve5 = $row["achieve5"]; $achieve6 = $row["achieve6"]; $achieve7 = $row["achieve7"]; $achieve8 = $row["achieve8"]; $assoc1 = $row["assoc1"]; $assoc2 = $row["assoc2"]; $assoc3 = $row["assoc3"]; $assoc4 = $row["assoc4"]; $assoc5 = $row["assoc5"]; $edu1sectype = $row["edu1sectype"]; $edu1secinst = $row["edu1secinst"]; $edu1secname = $row["edu1secname"]; $edu1secdate = $row["edu1secdate"]; $edu1secinsttyp = $row["edu1secinsttyp"]; $subject1 = $row["subject1"]; $subject2 = $row["subject2"]; $subject3 = $row["subject3"]; $subject4 = $row["subject4"]; $subject5 = $row["subject5"]; $subject6 = $row["subject6"]; $subject7 = $row["subject7"]; $subject8 = $row["subject8"]; $compsoft1name = $row["compsoft1name"]; $compsoft2name = $row["compsoft2name"]; $compsoft3name = $row["compsoft3name"]; $compsoft4name = $row["compsoft4name"]; $compsoft5name = $row["compsoft5name"]; $compsoft6name = $row["compsoft6name"]; $achievements = array('achieve1', 'achieve2', 'achieve3', 'achieve4', 'achieve5', 'achieve6', 'achieve7', 'achieve8'); $associations = array('assoc1', 'assoc2', 'assoc3', 'assoc4', 'assoc5'); $subjects = array('subject1', 'subject2', 'subject3', 'subject4', 'subject5', 'subject6', 'subject7', 'subject8' ); $compsoft = array('compsoft1name', 'compsoft2name', 'compsoft3name', 'compsoft4name', 'compsoft5name', 'compsoft6name'); while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td ALIGN=LEFT>" . $row['id'] . "</td>"; echo "<td ALIGN=LEFT>" . $row['name'] . "</td>"; echo "<td ALIGN=LEFT>" . $row['surname'] . "</td>"; echo "</tr>"; } echo "</table>"; //This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query"; } } ?> </body> </html>Any assistance will be greatly appreciated as I have been working on this website for the past 4 months which has totalled over 150 pages and this is one of the last pages left to program and it's taken 6 days to get to this search page to this point. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=349563.0 Hi. Maybe a tricky question? How do I reflect the content of a column from a database table in a roll down select menu in the browser? Let's say that the content of the table column is: Anna Michael These names should be reflected in this select menu like this: <select name="friends"> <option value="Choose a name">Choose a name</option> <option value="Anna">Anna</option> <option value="Michael">Michael</option> So visitors can choose a name, and thereby turn it into a variable, for reuse in the database. Best regards Morris hi, what is the proper way to to $now $next tuesday select * where date is between now and next tuesday thanks all So I have this program I purchased and it allows me to create custom form fields. I have been trying to create a date select box but have been struggling because I am just learning php. I was wondering if someone could lend a hand. I will try and give as much info as i can. First I will show a picture of the custom field box and then i will give the description of both boxes that the company gave me. Next i will give you the php code i have been trying to work with. Please if my code is not the best then i will take any advice. I found the code for the date selector online. Parsed Default Value - You may specify a variable or a function as the default value; for example $_SERVER[HTTP_USER_AGENT] or mktime() Parsed PHP Code - You can specify actual PHP code that will be used to return a variable. // You should assign the value you wish to use to the variable $str. Code: [Select] <?PHP FUNCTION buildDate($name, $m, $d, $y) { $date = DATE("m-d-Y",STRTOTIME("now")); $date_array = EXPLODE("-",$date); $now_m = ""; $now_d = ""; $now_y = ""; $month = '<select class="small" name="'.$name.'_month">'; $month .= '<option value="" selected disabled>mm</option>'; FOR ($i=1;$i<=12;$i++) { IF ( $m != "" ) { IF ( $m == $i ) { $now_m = "selected"; } }ELSEIF ( $m == "0" ) { $now_m = ""; }ELSE{ IF ( $date_array[0] == $i ) { $now_m = "selected"; } } $month .= '<option value="'.$i.'" '.$now_m.'>'.$i.'</option>'; $now_m = ""; }//END month for loop $month .= '</select>'; $day = '<select class="small" name="'.$name.'_day">'; $day .= '<option value="" selected disabled>dd</option>'; FOR ($i=1;$i<=31;$i++) { IF ( $d != "" ) { IF ( $d == $i ) { $now_d = "selected"; } }ELSEIF ( $d == "0" ) { $now_d = ""; }ELSEIF ( $d == $i ) { $now_d = "selected"; }ELSE{ IF ( $date_array[1] == $i ) { $now_d = "selected"; } } $day .= '<option value="'.$i.'" '.$now_d.'>'.$i.'</option>'; $now_d = ""; }//END day for loop $day .= '</select>'; $year = '<select class="small" name="'.$name.'_year">'; $year .= '<option value="" selected disabled>yyyy</option>'; FOR ($i=GMDATE("Y"); $i <=SUBSTR(get330Date(),0,4); $i++) { IF ( $y != "" ) { IF ( $y == $i ) { $now_y = "selected"; } }ELSEIF ( $y == "0" ) { $now_y = ""; }ELSEIF ( $y == $i ) { $now_y = "selected"; }ELSE{ IF ( $date_array[2] == $i ) { $now_y = "selected"; } } $year .= '<option value="'.$i.'" '.$now_y.'>'.$i.'</option>'; $now_y = ""; }//END year for loop $year .= '</select>'; //------------------------------------------- ECHO $month." ".$day." ".$year; }//END buildDate function // ------------------------------------ FUNCTION get330Date() { RETURN DATE("Y-m-d", MKTIME(0, 0, 0, SUBSTR(GMDATE("Y m d"),5,2), SUBSTR(GMDATE("Y m d"),8,2) + 330, SUBSTR(GMDATE("Y m d"),0,4)))."<br />"; } ?> I might just be totaly wacked here with what i am trying to do but i am sure someone will tell me one way or the other. lol Hi, How can I check mysql date/time field for all records with tommorows date.. ? Thanks This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=309828.0 Hi all, I have done a script that works fine on a single basis... SELECT * FROM company WHERE so <> 0 AND so_active = 'yes' AND DATE_FORMAT(so_start_date, '%e') = '18' ORDER BY company_name ASC The problem I have is when I try to do a range... SELECT * FROM company WHERE so <> 0 AND so_active = 'yes' AND DATE_FORMAT(so_start_date, '%e') BETWEEN '5' AND '26' ORDER BY company_name ASC It should return at least 1 result as I am looking for '18', any help would be much appreciated. Many Thanks. hello with tis button i generate some statistics from mysql if(isset($_POST['sub1'])) { $result = mysql_query("SELECT servitoros1, COUNT(*) from history WHERE serv LIKE '%be%' group by serv1"); while($row = mysql_fetch_row($result)) { echo "<tr>"; foreach($row as $cell) echo "<td ALIGN=\"center\">$cell<FONT></td>"; echo "</tr>\n"; } mysql_free_result($result); } but each record have datetime field!! so how can i set this display betwean 2 selectable datetimes e.g. from 2/2/2011 15:45 to 3/2/2011 23:59 |