PHP - How To Query According To The Value That Is Get From Selected Date.
I'm creating a line graph using ChartJs. I wanted to display my data according to the month selected by the user. For example, if the user select "2021-03" all the order that is made in the month of March will be plotted in the graph. It works well for the current month, but it does not work for the selected month. I use Ajax to get the data but i do not know why my graph does not shown when i click on my `loadchart();` button. Can anyone enlighten me how can i do it? Because i do not know what mistake did i made here. Any kind of explanation will be appreciated. Thanks!
This is the where i place my `loadchart()` button and also the javascript to plot the graph. <div class="col-md-12 form-group"> <div class="card" style="box-shadow: 0 0 8px rgb(0,0,0,0.3)"> <div class="row"> <div class="col col-lg-1"></div> <div class="col-2 my-auto"> <input type="month" id="month" class="form-control" value="<?php echo date('Y-m'); ?>"> </div> <div class="col-2 my-auto"> <button type="button" class="btn btn-info" onclick="loadchart();"> <i class="nc-icon nc-zoom-split"></i> </button> </div> </div> <div id="loadchart"> <h6 class="text-muted text-center p-3"><i class="fa fa-line-chart"></i> Daily Gross Sales (Current Month)</h6> <div class="card-body"> <canvas id="attChart"></canvas> </div> </div> </div> </div> </div> </div> </div> </div> <!-- Chart JS --> <script src="./assets/js/plugins/chartjs.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> <?php $days = array(); $gross_sales = array(); $average_sales = array(); $type = CAL_GREGORIAN; $month = date('n'); // Month ID, 1 through to 12. $year = date('Y'); // Year in 4 digit 2009 format. $day_count = cal_days_in_month($type, $month, $year); // Get the amount of days //loop through all days for ($i = 1; $i <= $day_count; $i++) { $sql = "SELECT *, SUM(purchase_price) as purchase_price FROM ordered_items WHERE DAY(order_datetime) = '$i' AND MONTH(order_datetime) = MONTH(NOW()) AND YEAR(order_datetime) = YEAR(NOW()) AND order_status = 5 "; $query = $conn->query($sql); $total = $query->num_rows; $row = $query->fetch_assoc(); if($row['purchase_price'] != 0) { $gross_sales[] = $row['purchase_price']; } else if ($row['purchase_price'] == 0 && $i <= date('d')) { $gross_sales[] = 0; } $average_sales[] = $row['purchase_price'] / $day_count; $day = $i.'/'.$month; //format date array_push($days, $day); } $days = json_encode($days); $daily_gross_sales = json_encode($gross_sales); $average_gross_sales = json_encode($average_sales); ?> <script> const colors = { colorcode: { fill: '#51cbce', stroke: '#51cbce', }, }; var ctx2 = document.getElementById("attChart").getContext("2d"); const attChart = new Chart(ctx2, { type: 'line', data: { labels: <?php echo $days; ?>, //labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], datasets: [{ label: "Gross Sales: RM", fill: true, //backgroundColor: colors.colorcode.fill, pointBackgroundColor: colors.colorcode.stroke, borderColor: colors.colorcode.stroke, pointHighlightStroke: colors.colorcode.stroke, borderCapStyle: 'dot', pointRadius: 5, pointHoverRadius: 5, pointStyle: 'dot', data: <?php echo $daily_gross_sales; ?>, showLine: true }, { label: "Average Sales: RM", fill: true, //backgroundColor: colors.colorcode.fill, pointBackgroundColor: '#FF0000', borderColor: ' #FF0000 ', pointHighlightStroke: colors.colorcode.stroke, borderCapStyle: 'dot', pointRadius: 5, pointHoverRadius: 5, pointStyle: 'dot', data: <?php echo $average_gross_sales; ?>, showLine: true } ] }, options: { responsive: true, // Can't just just `stacked: true` like the docs say scales: { yAxes: [{ stacked: false, gridLines: { display: true, color: "#dee2e6" }, ticks: { stepSize: 100000, callback: function(tick) { return 'RM'+tick.toString(); } } }], xAxes: [{ stacked: false, gridLines: { display: false }, }] }, animation: { duration: 3000, }, legend:{ display: false, } } }); </script> This is my AJAX method <script type="text/javascript"> function loadchart() { $('#spin1').show(); var month= $('#month').val(); //alert(date); var data = { // create object month: month, } $.ajax({ method:"GET", data:data, url:"includes/loadchart.php", success:function(data) { $('#loadchart').html(data); } }); } </script> This is where i use to load the graph whenever a month is selected. (loadchart.php) <?php include '../session.php'; if(isset($_GET['month'])) { $months = $_GET['month']; ?> <h6 class="text-muted text-center p-3"><i class="fa fa-line-chart"></i> Daily Gross Sales (<?php echo $months ?>)</h6> <div id="loadchart" class="card-body"> <canvas id="attChart"></canvas> </div> </div> </div> </div> </div> </div> </div> <!-- Chart JS --> <script src="./assets/js/plugins/chartjs.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> <?php $days = array(); $gross_sales = array(); $average_sales = array(); $type = CAL_GREGORIAN; // Gregorian (localized) calendar $month = date('n'); // Month ID, 1 through to 12. $year = date('Y'); // Year in 4 digit 2009 format. $day_count = cal_days_in_month($type, $month, $year); // Get the amount of days //loop through all days for ($i = 1; $i <= $day_count; $i++) { $sql = "SELECT *, SUM(purchase_price) as purchase_price FROM ordered_items WHERE DAY(order_datetime) = '$i' AND MONTH(order_datetime) = MONTH('".$months."') AND YEAR(order_datetime) = YEAR('".$months."') AND order_status = 5 "; $query = $conn->query($sql); $total = $query->num_rows; $row = $query->fetch_assoc(); if($row['purchase_price'] != 0) { $gross_sales[] = $row['purchase_price']; } else if ($row['purchase_price'] == 0 && $i <= date('d')) { $gross_sales[] = 0; } $average_sales[] = $row['purchase_price'] / $day_count; $day = $i.'/'.$month; //format date array_push($days, $day); } $days = json_encode($days); $daily_gross_sales = json_encode($gross_sales); $average_gross_sales = json_encode($average_sales); ?> <script> const colors = { colorcode: { fill: '#51cbce', stroke: '#51cbce', }, }; var ctx2 = document.getElementById("attChart").getContext("2d"); const attChart = new Chart(ctx2, { type: 'line', data: { labels: <?php echo $days; ?>, //labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], datasets: [{ label: "Gross Sales: RM", fill: true, //backgroundColor: colors.colorcode.fill, pointBackgroundColor: colors.colorcode.stroke, borderColor: colors.colorcode.stroke, pointHighlightStroke: colors.colorcode.stroke, borderCapStyle: 'dot', pointRadius: 5, pointHoverRadius: 5, pointStyle: 'dot', data: <?php echo $daily_gross_sales; ?>, showLine: true }, { label: "Average Sales: RM", fill: true, //backgroundColor: colors.colorcode.fill, pointBackgroundColor: '#FF0000', borderColor: ' #FF0000 ', pointHighlightStroke: '#FF0000', borderCapStyle: 'dot', pointRadius: 5, pointHoverRadius: 5, pointStyle: 'dot', data: <?php echo $average_gross_sales; ?>, showLine: true } ] }, options: { responsive: true, // Can't just just `stacked: true` like the docs say scales: { yAxes: [{ stacked: false, gridLines: { display: true, color: "#dee2e6" }, ticks: { stepSize: 100000, callback: function(tick) { return 'RM'+tick.toString(); } } }], xAxes: [{ stacked: false, gridLines: { display: false }, }] }, animation: { duration: 3000, }, legend:{ display: false, } } }); </script> <?php } ?> Edited April 27 by sashavalentina Similar TutorialsI have this function where i want to pass the month and year according to the date drop down that is chosen by the user. But can't seem to get the selected month and year. But instead, i got the month and year for now (which is April 2020). Can any one show me how can i achive this? I mean how can i pass the month and year selected to my `allreport-summary.php` page. It would be better if you guys can show me examples of codes on how can i implement this. Any help will be appreciated. Thank you so much. cheers!
<div class="row"> <div class="col-4 my-auto"> <input type="month" id="month" class="form-control" value="<?php echo date('Y-m'); ?>"> </div> <div class="col-4 my-auto"> <select class="form-control" id="seller"> <option value="">Select All</option> <?php $sql = "SELECT * FROM sellers ORDER BY seller_registered"; $query = $conn->query($sql); while ($row = $query->fetch_assoc()) { ?> <option value="<?php echo $row['id'];?>"><?php echo $row['seller_fullname'];?></option> <?php } ?> </select> </div> <div class="col-4"> <button type="button" class="btn btn-info" onclick="loadreports();"> <i class="nc-icon nc-zoom-split"></i> </button> <a href="allreport-summary.php?month=<?php echo date('Y-m');?>"> <button type="button" class="btn btn-info" style="height: 40px;"> <i class="fa fa-file-excel-o"></i> Export All Report </button> </a> </div>
I am working on a report generation. Here I need to count the number of months involved in the selected date range. I need to apply the monthly charges accordingly. Example: If the user selects 25-08-2011 to 03-10-2011, it should return 3 as the number of months. Yes, the number of days are less than 60 but still the date range is spread across 3 months. Any solution.. Please. Girish Hi, I have a select box that has every week day as an option. When a user picks "Monday" and submits the form I want to echo the date of monday last week. And if he picks tuesday, I want it to give the date of Tuesday last week, on so on. How would I do that? Thank you in advance! Hello, I have a datepicker that when a date is selected, the post to a php file will get the sum values for that selected day, month, and year. I have the "by day" working with this... <?php $choice = (isset($_POST['choice'])) ? date("Y-m-d",strtotime($_POST['choice'])) : date("Y-m-d"); $con = mysql_connect("localhost","root","xxxxxxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("inverters", $con); $sql = "SELECT sum(power/1000) AS choice FROM feed WHERE date = '".$choice."' group by date"; $res = mysql_query($sql) or die('sql='.$sql."\n".mysql_error()); $row = mysql_fetch_assoc($res); echo $row['choice'].'<br />'; ?> But by month and year are not clicking... Help Please Alan I've got a HTML drop down box as similar to this: <select name="dropdown"> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> </select> If I run a mysql query and get a result of "Option 3", is there anyway using PHP to give Option 3 the selected value? I have a mysql database where users enter their data using a form that includes a rundate input field that generates a calendar date in this type of format: xx/xx/xxxx into a mysql database field called rundate. I would like to query the database to search a string of dates that are in the database, such as 01/01/2011, 01/02/2011, 01/03/2011 but I'm not sure on how to code this into my search.php. I have attached the search page to this post. Any suggestions would be greatly appreciate, and if you need me to be more expanded on my explanation, just let me know....i try to keep it very simplistic. [attachment deleted by admin] Hi everyone I have a database with table containing my news it has a `start_date` field and a `end_date` field and I store dates as YYYY-MM-DD I have a PHP script on my webpage which I have a date set on it, such as $date = '2010-10-23' What QUERY would I need to run to return all rows which the date defined falls between the start and end date Any help would be great I tried WHERE `start_date` >= '2010-09-13' AND `end_date` <= '2010-09-13' but that doesn't seem to work // Nav Tabs $query = "select DISTINCT YEAR(sold_date) FROM Sold"; $result = mysql_query($query); $numrows = mysql_num_rows($result); while($row = mysql_fetch_array($result)){ $year = substr($row['sold_date'], 0, -6); $navTab .= '<a class="miniTabOn" href="index.php?date='.$year.'">'.$year.'</a>'; } I am trying to create a link for each year of items in my database, yet the text is not showing up... The "nav tab" is, because I can see the background image from the class="miniTabOn". Can anyone spot an error? With unixtimestamps? I have let's say 20records, and like 5 of them are from January and 15 are in February, how would I go about showing all the records that were just in February (2012) or maybe 2013? (trick is using timestamps) Pretty much sort the records by each Monthy, by using unixtimestamp as the value in the db field, possible? Hi i have the following code Quote
$sql= "SELECT * FROM income WHERE month(date) between '04' and '12' and year(date) between 2020 and 2020"; This obviously selects all the information from April 2020 to December 2020
How do i change this to add a date as well for example if i wanted to display all the information from April 6th 2020 to December 5th 2020 ?
Hello, I am doing a hotel reservation website.First am getting the checkin (arrival) and Check out(Departure) date from user.Then in next from i fetch both this values using POST method and store it in variable $arrival and $departure and then am formattind the date as i want it in the form YYYY-MM-DD(My SQL). Then am using the value of variable $arr and $dep in a query to fetch the records from DB but it is giving error.But when i do it in Hard code way I mean directly inserting the date in query it is running smmothly.Please help!!!! Am using Xampp 2.5 Heres my code... <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>ROOMS</title> <?php $arrival = $_POST['start']; $departure = $_POST['end']; $adults=6; $child=2; $room_id=101; function changeFormatDate($cdate){ list($day,$month,$year)=explode("/",$cdate); return $year."-".$month."-".$day; } // $arr="'".$arr."'"; $arr= changeFormatDate($arrival); //settype($arr, "string"); // $timestamp=strtotime($arr1); // $arr=date("Y-m-d",$timestamp); $dep= changeFormatDate($departure); // $timestamp=strtotime($dep1); // $dep=date("Y-m-d",$timestamp); ?> <style type="text/css"> <!-- .style2 { font-size: 12px; font-weight: bold; } --> </style> </head> <body> <!-- TOP --> <div id="top1"><a href="index.php"></a></div> <div id="top"> <ul class="menu"> <li class="home"><a href="index.php">Home</a></li> <li class="about"><a href="about.php">About</a></li> <li class="contacts"><a href="contact.php">Contacts</a></li> <li class="renting"><a href="gallery.php">GALLERY</a></li> <li class="selling"><a href="rates.php">RATES</a></li> </ul> </div> <!-- HEADER --> <!-- CONTENT --> <div id="content"> <div id="leftPan"> <div id="services"> <h2>RESERVATION DETAILS </h2> <p> <ul> Check In Date :<?php echo $arrival; ?><br /> Check Out Date :<?php echo $departure; ?> <br /> </ul> </p> </p> </div> </div> <div id="featured"><br /> <div> <form action="personnalinfo.php" method="post" onsubmit="return validateForm()" name="room"> <input name="start" type="hidden" value="<?php echo $arrival; ?>" /> <input name="end" type="hidden" value="<?php echo $departure; ?>" /> <input name="rooms" id="rooms" type="hidden" /> <input name="adult" type="hidden" value="<?php echo $adults; ?>" /> <input name="child" type="hidden" value="<?php echo $child; ?>" /> </div> <table bgcolor="white" border="1" width="100%" style="float:left;table-layout:fixed" cellpadding="10" cellspacing="0" > <col width="70%"> <tr> <th colspan="2" bgcolor="white"><h2><font color=maroon>Room Type</font></h2></th> </tr> <tr> <td> <table border="0" style="float:left;table-layout:fixed" width="100%"> <col width="55%"> <tr> <td valign="top"> <img src="img1/apt.jpg" style="float:left" /> </br> <div style="margin-top:120px;margin-left:5px"> <img src="img1/apt1.jpg" /> <img src="img1/apt2.jpg" /> <img src="img1/apt3.jpg" /> </div> </td> <td> <h3>Appartment</h3> <br> <span class="price">Price:</span> <span class="number">Rs. 5,000.00</span><br /> <a> Apparment in HOTEL BELLA has 2 Rooms with connecting door.It can accomodate 4 Adult and 2 children. And are located on Beach side to give you comfort and a panoramic view so that you can have a luxury accommodation.<br> *Sitting area <br>*jacuzzi shower</br> *Large terrace overlooking the sea *Jacuzzi *Light therapy *Air treatment <a href="#">more...</a></p><br /> </td> </tr> </table> </td> <td valign="top"> <table border=0 width="100%" cellspacing="10"> <tr> <td align="left"> <label><h3>People : </h3></label> </td> <td align="right"> <img src="img1/i1.jpg" /> </td> </tr> <tr> <td align="left" > <label><h3>Rooms : </h3></label> </td> <td align="right" > <?php gen_options("single")?> </td> </tr> </table> </td> </tr> <tr> <td> <table border="0" style="float:left;table-layout:fixed" width="100%"> <col width="55%"> <tr> <td valign="top"> <img src="img1/double.jpg" style="float:left" /> </br> <div id="featured"> <img src="img1/double1.jpg" /> <img src="img1/double2.jpg" /> <img src="img1/double3.jpg" /> </div> </td> <td> <h3>Double</h3> <br> <span class="price">Price:</span> <span class="number">Rs. 3,000.00</span><br /> <a>Double rooms in HOTEL BELLA has Double bed. And can accomodate 2 Adults and 2 kids. It is comfortable and pleasant, with balcony and sea view. We hope that you will enjoy your summer holidays in Bella. BASIC: Telephone. Satellite TV. Safety Deposit Box. Mini Bar - Refrigerator. Air condition. Shower with or without cabin. Hair Dryer. Balcony.<a href="#">more...</a></p><br /> </td> </tr> </table> </td> <td valign="top"> <table border=0 width="100%" cellspacing="10"> <tr> <td align="left"> <label><h3>People : </h3></label> </td> <td align="right"> <img src="img1/i2.jpg" /> </td> </tr> <tr> <td align="left"> <label><h3>Rooms : </h3></label> </td> <td align="right" > <?php gen_options("double")?> </td> </tr> </table> </td> </tr> <tr> <td> <table border="0" style="float:left;table-layout:fixed" width="100%"> <col width="55%"> <tr> <td valign="top"> <img src="img1/single.jpg" style="float:left" /> </br> <div id="featured"> <img src="img1/single1.jpg" /> <img src="img1/single2.jpg" /> <img src="img1/single3.jpg" /> </div> </td> <td> <h3>Single</h3> <br> <span class="price">Price:</span> <span class="number">Rs. 2,000.00</span><br /> <a> Single Room in HOTEL BELLA has single bed, bathroom.Can accomodated single person. is comfortable and pleasant, with balcony and sea view Telephone Satellite TV Safety Deposit Box Mini Bar - Refrigerator Air condition Hair Dryer <a href="#">more...</a></p><br /> </td> </tr> </table> </td> <td valign="top"> <table border=0 width="100%" cellspacing="10"> <tr> <td align="left"> <label><h3>People : </h3></label> </td> <td align="right"> <img src="img1/i3.jpg" /> </td> </tr> <tr> <td align="left"> <label><h3>Rooms : </h3></label> </td> <td align="right" > <?php gen_options("apartment")?> </td> </tr> </table> </td> </tr> </table> <div style="margin-top:1200px;margin-left:5px;text-align:right;"> <input type="image" src="img1/book.jpg" name="book" value="submit"/> </div> <?php function gen_options($type) { // print "$id"; // print "$type"; $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("hotel", $con); $count=0; $result = mysql_query("SELECT * FROM rooms where type='$type'"); while($row = mysql_fetch_array($result)) { $a=$row['room_no']; //print "$a"; // $query1 = mysql_query("SELECT count(*) FROM `room_inventory` WHERE room_no='$a' and status='active'"); // $query=mysql_query("SELECT count(*) FROM `room_inventory` WHERE room_no='$a' and ((arrival<='2012-05-11' AND departure>='2012-05-11')OR(arrival<='2012-05-13' AND departure>='2012-05-13'))"); //$query=mysql_query("SELECT count(*) FROM `room_inventory` WHERE room_no='$a' and ((arrival BETWEEN '2012-05-11' AND '2012-05-13') or (departure BETWEEN '2012-05-11' AND '2012-05-13'))"); //$query=mysql_query("SELECT count(*) FROM `room_inventory` WHERE room_no='$a' and ((arrival<='$arr' AND departure>='$arr')OR(arrival<='$dep' AND departure>='$dep'))"); $quer=sprintf("SELECT count(*) FROM `room_inventory` WHERE room_no='$a' and ((arrival<='%s' AND departure>='%s')OR(arrival<='%s' AND departure>='%s'))",$arr,$arr,$dep,$dep); $query=mysql_query($quer); //$query=mysql_query("SELECT count(*) FROM `room_inventory` WHERE room_no='$a' and ((arrival BETWEEN '$arr' AND '2012-05-13') or (departure BETWEEN '$arr' AND '2012-05-13'))"); $r=mysql_fetch_array($query); $v=$r['count(*)']; // print "$v"; if($v==0) { $count++; // print "$count"; } } echo '<select name="room1" class="ed" id="r1">'; for($i=0;$i<=$count;$i++) { echo '<option>'.$i.'</option>'; } echo '</select>'; mysql_close($con); } // echo "$arrival\n"; // print "$departure\n"; echo "$arr"; echo "$dep"; // echo date_format($arrival, 'Y-m-d'); ?> <input type="hidden" name="result" id="result" /> </form> </div> <div class="clear"></div> </div> <!-- FOOTER --> <div id="footer"> <p><a href="index.php">HOME</a> |<a href="about.php"> ABOUT US </a>|<a href="contact.php"> CONTACTS </a>|<a href="gallery.php"> GALLERY </a>|<a href="rates.php"> ROOM RATES </a></p> </div> </body> </html> Hello i am working on an application where i want to count from a selected date to another date and query all entries my database right now is composed of the following sales_id barcode_id student_id type of lunch date i have created the count per day, but now dont know how to go about to query the results and the count for the month. Code: [Select] $query = 'SELECT COUNT(*) FROM `sales` WHERE `tlunch` = 1 AND DATE(date) = CURDATE()'; $result = mysql_query($query) or die('Sorry, we could not count the number of results: ' . mysql_error()); $free = mysql_result($result, 0); has any one done something similar So I'm trying to put a user selected date into a mysql query, but it seems like no matter what I do I get 0 results even though I already know there's quite a few. The way I have it now 'echo $query;' puts out the expected results, but I'm guessing it's because I'm trying to match a date to a string. I tried strtotime but I'm not sure if I was doing it right.. I also tried sprintf() just in case, but that doesn't seem to have a date feature. The variable $realdate is just to show how I was attempting to use strtotime, it's not an actualy part of the script at this time... $searchdate = $_GET['searchdate']; //$realdate = strtotime($searchdate) //connects to db dbconnect(); $query="SELECT `name`, `date`, SUM(`amount`) as `total_money`, SUM(`bricks`) as `total_bricks` FROM Aces_Donations WHERE `date`= $searchdate ORDER BY `total_money`"; echo $query; $result=mysql_query($query); //Opens the table echo "<table border = '3' width = 40% bgcolor=#A85045><caption><center>Rankings - ".$searchdate.'</center></caption>'; //Loop to run until eof while($row = mysql_fetch_array($result)){ echo "<tr><td>".$rank."</td> <td>".$row['name']. "</td><td>". $row['total_money']."</td><td>".$row['total_bricks'].'</td></tr>'; $rank++; } echo '</table>'; How would I put today date for instance into mysql_query? I just want the date and have the format be year, month, day. The format in the database looks like 2010-04-05. That being used as an example. And I have three drop down menus, which you can select the year, month, and day, but it doesn't seem to be working. What am I doing wrong? Hi I'm having a problem getting a query to work. I have a simple form with user input for start and end date with format: 2009-03-19 (todays date): $Startdate = $_POST['date']; This works well when something is entered into the form, and afterwards using my query: SELECT COUNT(*) as total FROM mydb WHERE Date BETWEEN '$Startdate' AND '$EndDate' ........ Problem is if user submits the form without entering anything in the date input fields, which makes sense. I want to check if inputs has been made, and if not set af default date, but can't make it work: if (isset($_POST['date']) && $_POST['date'] !='') { $Startdate = $_POST['date'];} else { $Startdate = '1980-01-01';} How can I set $Startdate to something that can be used in the query as below doesn't work? Hi,
I can I include a date range criteria to query with in the following code? The date field in the table (t_persons) is IncidentDate.
$criteria = array('FamilyName', 'FirstName', 'OtherNames', 'NRCNo', 'PassportNo', 'Gender', 'IncidenceCountryID', 'Status', 'OffenceKeyword', 'AgencyID', 'CountryID', 'IncidenceCountryID' ); $likes = ""; $url_criteria = ''; foreach ( $criteria AS $criterion ) { if ( ! empty($_POST[$criterion]) ) { $value = ($_POST[$criterion]); $likes .= " AND `$criterion` LIKE '%$value%'"; $url_criteria .= '&'.$criterion.'='.htmlentities($_POST[$criterion]); } elseif ( ! empty($_GET[$criterion]) ) { $value = mysql_real_escape_string($_GET[$criterion]); $likes .= " AND `$criterion` LIKE '%$value%'"; $url_criteria .= '&'.$criterion.'='.htmlentities($_GET[$criterion]); } //var_dump($likes); } $sql = "SELECT * FROM t_persons WHERE PersonID>0" . $likes . " ORDER BY PersonID DESC";Kind regards. I'm getting this error "Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/westiehi/public_html/groupBOS.php on line 36" for this code: Code: [Select] $query_rs_specialty = "SELECT * FROM specialty WHERE Group_Place <> '' and Date>= DATE_SUB(CURDATE(), INTERVAL 6 MONTH) ORDER BY Date DESC"; I've tried everything to get this to take records where the one field is blank and the date is greater than a date 6 months ago but nothing seems to work. Help would sure be appreciated!! Hi. I have an input field where a date is entered, format dd-mm-yy. I need to query the database to see if this date exists. How can I convert the date to yyyymmdd before the query? Thanks Hey, I'm using a script which allows you to click on a calendar to select the date to submit to the database. The date is submitted like this: 2014-02-08 Is there a really simple way to prevent rows showing if the date is in the past? Something like this: if($currentdate < 2014-02-08 || $currentdate == 2014-02-08) { } Thanks very much, Jack I have this loop on a shorturl website i own that selects domains from my website and lists them in a dropdown list where users can select one domain to use as url shortener. The problem is that when a users selects and entry from the dropdown list this created only the [[[main_url]]] entry from the database table bellow can be used. When someone selectes "coolartistname.site.com the submit button cannot be pressed. in other words it's not adding the SELECTED attribute other than the [[[main_url]]] domain. Can anyone see on the code bellow why this would happen?
**Index.php** // get base urls $shortUrlDomains = getShortUrlDomains(); <?php foreach ($shortUrlDomains AS $k => $shortUrlDomain) { // active domains only if (($shortUrlDomain['premium_only'] !== '1') && ($shortUrlDomain['premium_only'] !== $Auth->id)) { continue; } echo '<option value="' . (int)$k . '"'; if (isset($_REQUEST['shortUrlDomain'])) { if ($k == (int)$_REQUEST['shortUrlDomain']) { echo 'SELECTED'; } } echo '>'; echo $shortUrlDomain['domain']; if ($disabled == true) { echo ' (' . safeOutputToScreen(t('unavailable', 'unavailable')) . ')'; } '</option>'; } echo '</optgroup>'; ?> FUNCTIONS.PHP function getShortUrlDomains() { // if we already have it cached if(defined('_SETTINGS_SHORT_URL_DOMAINS')) { return unserialize(_SETTINGS_SHORT_URL_DOMAINS); } // get connection $db = Database::getDatabase(true); // load from database $domains = $db->getRows("SELECT id, domain, premium_only, status FROM url_domain ORDER BY premium_only ASC, id ASC"); // organise and replace site url $rs = array(); foreach($domains AS $domain) { if($domain['domain'] == '[[[main_url]]]') { $domain['domain'] = _CONFIG_SITE_FULL_URL; } $rs[$domain{'id'}] = $domain; } **MYSQL DATABASE** url_domain (id, domain, premium_only, status, date_created, owner) VALUES (1, '[[[main_url]]]', 0, 'enabled', '2019-03-02 08:13:00', 1) (14, 'coolartistname.site.com', 6, 'enabled', '2020-04-18 19:21:59', 6);
|