PHP - A Little Help With Queries And Dates.
Hi, I am trying two compare to dates but have not been successful.
A row is filled in Mysql database called htime with $check=mktime(17,0,0,04,10,2011); My first question is that in the mktime function I have entered 17 which is hours. I would like to know if thats like the 17th hour of the given day or thats not how it works? My second question is it a valid query to use <= or >= or < in a mysql query for example. $query="SELECT * FROM hdb WHERE htime <='".time()."'"; Thirdly I want to know if a row is filled with mktime(17,0,0,04,10,2011); for example How can I only extract the day from the database based on the time has passed? This is because my own query doesnt seem to be working which is the query above I have no errors but the results dont seem to be right. Any help is much appreciated thanks. Similar TutorialsHi 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 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 Hey guys - me again! I have a discount box, where i wish to check two "if" queries. These are i) the 'uniquecode' and ii) the 'uses' - so a code can only be used a set amount of times. 1) How do i state that question in php, bearing in mind the "if uses > 0" needs to relate to the same row as the unique code entered? 2) Also, i have stored the session price in $_SESSION['sessionprice'] - is this the best way to do this, and if not how should i store the current price. 3) Lastly, and how do I do the php mathematics of "$_SESSION['sessionprice'] minus the discount" - again bearing in mind the "discount" needs to relate to the same row as the unique code entered? (as different codes will have different discounts). This is how far i've gotten: Code: [Select] <?php //connection settings bla bla bla $uniquecode = $_POST['discountcode']; mysql_connect($localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $discountcodecheck = mysql_query("SELECT uniquecode FROM discounttable WHERE uniquecode = '".$uniquecode."'"); $remainingusescheck = mysql_query("SELECT uses FROM discounttable WHERE uniquecode = '".$uniquecode."'"); if (mysql_num_rows($discountcodecheck) > 0) and if (mysql_num_rows($remainingusescheck) > 0) // <-- this "and if" doesn't work { // discount calculation: // session price minus the unique code's corresponding discount // update $_session['discountammount'] } else { ?><script type="text/javascript"> alert("Discount Code Entered Is Either Not Valid Or Has Been Previously Used."); history.back(); </script><?php } // rest of code and close connection ?> Any help or comments will, as always be politely welcomed and appreciated Cheers, Tom. noob question: I have following two queries I'd like to combined into one - how is this done? $temp = @mysql_query("SELECT * FROM purchased_leads WHERE leadID = '{$_REQUEST[leadid]}'"); "SELECT refundNotes FROM leads WHERE leadID = '{$_REQUEST[leadid]}'" ive had these queries working okay until i checked on it today, it's not working anymore.. these are the errors::: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\arrastre\add.php on line 105 Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\arrastre\add.php on line 117 if(isset($_POST['add'])){ if($billnmbr=="" or $orno=="" or $payor=="" or $arrastre=="" or $wharfage=="" or $total=="" or $date=="" or $tcl==""){ echo "At least one field was left blank."; } else{ $query = mysql_query("select * from `arrastre` WHERE `billnmbr`='$billnmbr'"); /*****************this is my line 105************/ $count = mysql_num_rows($query); if($count==1){ echo "This billnumber is already in the database."; } else{ $bll = strtoupper($billnmbr); $payr = strtoupper($payor); $query="insert into `arrastre` (`billnmbr`, `orno`, `payor`, `arrastre`, `wharfage`, `total`, `date`, `tcl`) values ('$bll', '$orno', '$payr', '$arrastre', '$wharfage', '$total', '$date', '$tcl')"; $result=mysql_query($query); $query = mysql_query("select * from `arrastre` where `billnmbr`= '$billnmbr'", $link); /************and this is my line 117*************/ $count = mysql_num_rows($query); if($count==1){ echo "last bill number added: ".$billnmbr; } } Thank you very much for your time and have a nice day. Hello all, I've tried several ways to calculate a commission in the multi level marketing script, but it all ended up with nothing, recursive functions, nested sets nothing worked, and i'm running out of time to keep trying I've made multiple queries on the same table, and it's working, but only the first 3 queries, not more, I tried to perform it 4 times (although I need the queries to be performed 13 times) but still only 3 times example: A recruited B and C, and B recruited D, and D recruited E.... what's supposed to happen is A takes a commission on B, C, D, and E but now it only takes commission on the first three, and no commission for anyone comes after that, and the same for B, C, D, and E each takes commission on only 3 members down the line, and no more here is the queries Code: [Select] <? $result = mysql_query("SELECT * FROM users"); echo "<table width='589' border='1'> <tr> <th>ID</th> <th>Name</th> <th>National ID</th> <th>Commission</th> </tr>"; while($row = mysql_fetch_array($result)) { $query = mysql_query("SELECT * from users where recruiteris = '".$row['id']."'"); $num_rows=mysql_num_rows($query); $id1 = $row['id']; $commission = $num_rows; $_SESSION['id1'] = $id1; echo "<tr>"; while ($roww = mysql_fetch_array($query)) { $querry=mysql_query("select * from users where recruiteris = '".$roww['id']."'"); $num_rowss = mysql_num_rows($querry); while ($rowws= mysql_fetch_array($querry)) { $var3= '10'; $querrys=mysql_query("select * from users where recruiteris = '".$rowws['id']."'"); $num_rowsss = mysql_num_rows($querrys); while ($rowwss= mysql_fetch_array($querrys)) { $querryss=mysql_query("select * from users where recruiteris = '".$rowwss['id']."'"); $num_rowssss = mysql_num_rows($querryss); while ($rowwsss= mysql_fetch_array($querryss)) { $querryr=mysql_query("select * from users where recruiteris = '".$rowwsss['id']."'"); $num_rowssr = mysql_num_rows($querryr); } } } } $total= ($commission + $num_rowws + $num_rowwss + $num_rowwsss + $num_rowss + $num_rowssr) * $var3; echo "<td><a href=\"user.php?id=".$row['id']."\">".$row['id']."</a></td>"; echo "<td>" . $row['fname'] .''. $row['lname'] ." </td>"; echo"<td> ". $row['nid'] ." </td>"; echo "<td>".$total."</td> </tr>"; } echo "</table>"; ?> Good day everyone. I go by the nickname Sbosh and I am a newbie in PHP. I am currently learning php using video tutorials. I need help with regards to php queries. I have the following code: "SELECT 'food', 'calories' FROM 'diet' ORDER BY 'id'" which is supposed to display content from a table inside phpmyadmin which i created manually using phpmyadmin. But It gives an error saying i must check the MariaDB version on how to right this query, something like that. Please assist on the proper way of writing this code. Again I am a newbie in PHP and just starting to learn, so your help will be highly appreciated. whats the differance between mysql_query("UPDATE banned SET time and doing $safe4 = "UPDATE banned SET time mysql_query($safe4); is there a reason as to why do it the 2nd way i mentioned? if someone could please explain it to me so i wont be in confusion on this anymore The whole code is below, followed by the part that isn't producing. It all works extremely well until the last part, and I have two instances of setting a variable to mysql_fetch_assoc that work. Not sure why the third attempt doesn't. I'm just trying to have a separate area that outputs 'msg'. Code: [Select] $sql = "SELECT * FROM players as p INNER JOIN schools as s WHERE p.tid = s.id ORDER BY status, playerLast"; $results = mysql_query($sql); echo '<div class="roster">'; $team = mysql_fetch_assoc($results); echo '<div class="team_info"> <div class="school">' . $team['school'] . '</div> <div class="coach">Coach ' .$team['coachFirst'] . ' ' . $team['coachLast'] .'</div> <div>Sectional: ' . $team['sectional'] . '</div> <div>Class: ' . $team['class'] . 'A</div> '; echo '</div>'; $currentStatus = false; //Flag to detect change in status while($player = mysql_fetch_assoc($results)) { if($currentStatus != $player['status']) { //Status has changed, display status header $currentStatus = $player['status']; echo '<br><b>'; if ($currentStatus == '1') {echo 'Returning Starters';} elseif ($currentStatus == '2') {echo 'Key Returners';} elseif ($currentStatus == '3') {echo 'Varsity Newcomers';} elseif ($currentStatus == '4') {echo 'Key Freshmen';} echo '</b><br>'; // echo "<div><b>{$currentStatus}</b></div>\n"; } //Display player info echo $player['playerFirst'] . ' ' . $player['playerLast'] . ', ' . $player['feet'] . '\'' . $player['inches'] . '",' . $player['position'] . ', ' . $player['year'] . ';<br>'; } //Player comments echo '<hr>'; echo '<div class="coach_comments"><span class="player_name">hello'; while($comments = mysql_fetch_assoc($results)) { echo $comments['playerFisrt'] . ' ' . $comments['playerLast'] . ': </span>' . $comments['msg']; } echo '</div>'; echo '</div>'; It's all working until what's below. All I get out of it is the "hello", which is just a test to make sure it wasn't a CSS issue. Quote //Player comments echo '<hr>'; echo '<div class="coach_comments"><span class="player_name">hello'; while($comments = mysql_fetch_assoc($results)) { echo $comments['playerFisrt'] . ' ' . $comments['playerLast'] . ': </span>' . $comments['msg']; } echo '</div>'; echo '</div>'; The first query goes through but the second does not just seeing if I'm missing something. <?php // Include the database page require ('../inc/dbconfig.php'); if (isset($_POST['submittitle'])) { $titlename = mysqli_real_escape_string($dbc, $_POST['titlename']); $titleshortname = mysqli_real_escape_string($dbc, $_POST['titleshortname']); $titlestyle = mysqli_real_escape_string($dbc, $_POST['titlestyle']); $titlestatus = mysqli_real_escape_string($dbc, $_POST['titlestatus']); $query = "INSERT INTO `titles` (titlename, titleshortname, style_id, status_id, creator_id, datecreated) VALUES ('$titlename','$titleshortname','$titlestyle','$titlestatus', 1, NOW())"; mysqli_query($dbc, $query); $query_id = mysqli_insert_id($dbc); $query1 = "INSERT INTO `champions` (title_id) VALUES ('$query_id')"; mysqli_query($dbc, $query1); } ?> UPDATE: If I remove lastedit = NOW() from the query, and just leave SET content = $var, it works. :/ If already double checked to see if a user would make it to this point in the code, and they do. And the variable $pid IS assigned a value. I've also done a quick check and changed the UPDATE queries to SELECT queries, and then echoed out the number of rows and it returned a successful result. Yet, people still can't seem to have their posts updated...why? My code: //if it's a thread, update the thread, if it's a post, update the post if($type == 2) { //update thread mysql_query("UPDATE threads SET lastedit = NOW() AND content = '{$content}' WHERE id = {$id}") or die(mysql_error()); //send them to their post redirect('viewthread.php?forum='. $forum_id .'&id='. $id .'&page='. $page); } else { //update post mysql_query("UPDATE posts SET lastedit = NOW() AND content = '{$content}' WHERE id = {$pid}") or die(mysql_error()); //send them to their post redirect('viewthread.php?forum='. $forum_id .'&id='. $id .'&page='. $page .'&post='. $post); } Ive just implemented a function which shows how many queries have been run on the specific page. Since the result returned 38 queries on the index page alone i need a way of listing all of these queries. I could just go through the code and find them all but there are several pages to go through. so does anyone know of a function which will list all the queries that have been run? This must be easy enough, but I'm a noob so go easy on me, please :-)
I have two pieces of code and they're working well on their own. All I need is to put these two conditions into one query.
The first one:
<?php function childtheme_cat_limited_blog( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'events_categories', 'mycategory1' ); } } add_action( 'pre_get_posts', 'childtheme_cat_limited_blog' ); ?>And the second: <?php function childtheme_cat_limited_blog( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'category_name', 'mycategory2' ); } } add_action( 'pre_get_posts', 'childtheme_cat_limited_blog' ); ?>I'm sure it's a piece a cake for you guys, but I can't figure it out for the life of me, so any help would be greatly appreciated! Thank you! (My goal is here to display posts from two categories on a homepage of a Wordpress site, but to complicate things the two categories are from two different post types.) I'm trying to figure out how to combine these queries, to decrease server load and load time, but I'm not so good with MySQL queries. Does anyone have any ideas, any help is greatly appreciated, I've been tinkering with this for days now.
$Actv = 0; $ActvCount = -1; $ActvUpgrade = 0; $ActvRenewal = 0; $ActvVehicleAdds = 0; $result2 = mysql_query("SELECT * FROM tblOperators WHERE OperatorLocale = 'USA' and OperatorStatus = 'ACTIVE' and Team = 'RENEWALS'"); while($row2 = mysql_fetch_array($result2)) { $operID = $row2['OperatorID']; $result = mysql_query("SELECT * FROM tblUserPayments WHERE OperatorID = '$operID' AND PaymentStatus='OK' AND PaymentDate LIKE '$currentDate%'"); while($row = mysql_fetch_array($result)) { if($row['PaymentReason'] == 'ACTIVATION'){ ++$ActvCount; //if($row['PaymentMethod'] == 'CREDITCARD'){ $ActvUpgrade += $row['ChargeAmount']; //} } elseif($row['PaymentReason'] == 'UPGRADE'){ $userid = $row['UserID']; $paymentdate = $row['PaymentDate']; $result1 = mysql_query("SELECT * FROM tblRenewalInvoices WHERE UserID='$userid' AND ('$paymentdate' >= DATE_SUB(DueDate, INTERVAL 90 DAY) AND '$paymentdate' < DATE_ADD(DueDate, INTERVAL 15 DAY)) AND ParentInvoiceID IS NULL ORDER BY InvoiceNum DESC LIMIT 1"); if( $row1 = mysql_fetch_array($result1)) { $packageid = $row['PackageID']; $pack = mysql_query("SELECT * FROM tblUserPackages WHERE PackageID='$packageid';"); if($pack1 = mysql_fetch_array($pack)){ $expDate = $pack1['ExpirationDate']; $dueDate = $row1['DueDate']; $days = mysql_fetch_row(mysql_query("SELECT TO_DAYS('$expDate')-TO_DAYS('$dueDate');")); $months = (int)( ((int)$days + 14) / 30.4); $years = (int) ( ((int)$days + 182) / 365); $Intervals = 0; if($years > 0){ $Intervals = $years; } if(($pack1['Package'] or 'GPS-SVL') or ($pack1['Package'] == 'GPS-1') or ($pack1['Package'] == 'GPS-1PLUS')){ if($Intervals > 1){ //if($row['PaymentMethod'] == 'CREDITCARD'){ $Actv += $row['ChargeAmount']; //} } else{ //if($row['PaymentMethod'] == 'CREDITCARD'){ $ActvRenewal += $row['ChargeAmount']; //} } } else{ $Actv += $row['ChargeAmount']; } } else{ } } else{ //if($row['PaymentMethod'] == 'CREDITCARD') $ActvUpgrade += $row['ChargeAmount']; } } elseif($row['PaymentReason'] == 'ADDVEHICLE'){ //if($row['PaymentMethod'] == 'CREDITCARD') $ActvVehicleAdds += $row['ChargeAmount']; } } $result = mysql_query("SELECT * FROM tblRenewalCalls WHERE OperatorID = '$operID' AND PayStatus='OK' AND DateSubmitted LIKE '$currentDate%'"); while( $row = mysql_fetch_array($result) ) { if($row['Charged']){ if ((int)$row['RenewYears'] > 1) { $Actv += $row['RenewTotal']; } else{ $ActvRenewal += $row['RenewTotal']; } } } } $total = $Actv+$ActvRenewal+$ActvUpgrade+$ActvVehicleAdds; $ActvRenewal = $total - ($ActvVehicleAdds + $ActvUpgrade); $upgradeEarned = $ActvUpgrade; $renewalEarned = $ActvRenewal; Hi all I have a site with 4 SQL queries that I need to paginate so that it returns 10 hits per page maximum. Basically there will be varying values of adverts in each SQL table. Here's my code: Code: [Select] <!-- Get Trader premium adverts --> <?php $gettraderads = mysql_query("SELECT * FROM `trade-adverts` WHERE type = 'premium' AND paid = 1 AND categoryid = 1 AND live = 1 AND approved = 1 AND dateexpired >= '".$todaysdate."' ORDER BY id DESC "); $numtraderads = mysql_num_rows($gettraderads); while ($showtraderads = mysql_fetch_array($gettraderads)) { include('trader-ad-cell.php'); } ?> <!-- Get Trader standard adverts --> <?php $gettraderads = mysql_query("SELECT * FROM `trade-adverts` WHERE type = 'standard' AND categoryid = 1 AND live = 1 AND approved = 1 AND dateexpired >= '".$todaysdate."' ORDER BY id DESC "); $numtraderads = mysql_num_rows($gettraderads); while ($showtraderads = mysql_fetch_array($gettraderads)) { include('trader-ad-cell.php'); } ?> <!-- Get premium adverts --> <?php $getads = mysql_query("SELECT * FROM `adverts` WHERE categoryid = 1 AND type = 'premium' AND paid = 1 AND live = 1 AND approved = 1 AND dateexpired >= '".$todaysdate."' ORDER BY id DESC "); while ($showads = mysql_fetch_array($getads)) { include('ad-cell.php'); } ?> <!-- Get standard adverts --> <?php $getads = mysql_query("SELECT * FROM `adverts` WHERE categoryid = 1 AND type = 'standard' AND live = 1 AND approved = 1 AND dateexpired >= '".$todaysdate."' ORDER BY id DESC "); while ($showads = mysql_fetch_array($getads)) { include('standard-ad-cell.php'); } ?> Many thanks for your help Pete I have two seperate piece of code. One which sorts description and one which sorts price. However, I am looking to almalgamate them into one. I have tried the following however I appear to be way off. I want to select a product description with one link and then select a price range. However, I want the price range to read the description. <?phpif( isset($_GET['description' ; 'price' ])) $description = $_GET['description' ; 'price']; $query = "SELECT * FROM productfeed WHERE description like '%$description%' LIMIT 0, 10"; $query = "SELECT * FROM productfeed WHERE price like '%$price%' LIMIT 0, 10"; $fetchdata = mysql_query($query) or die("query: $query<br> This has an error: " . mysql_error() . '<br>');while($row = mysql_fetch_array($fetchdata)) { $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; <?phpif( isset($_GET['description'])) $description = $_GET['description']; $query = "SELECT * FROM productfeed WHERE description like '%$description%' LIMIT 0, 10"; $fetchdata = mysql_query($query) or die("query: $query<br> This has an error: " . mysql_error() . '<br>');while($row = mysql_fetch_array($fetchdata)) { $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; <?phpif( isset($_GET['price'])) $price = $_GET['price']; $query = "SELECT * FROM productfeed WHERE price like '%$price%' LIMIT 0, 10"; $fetchdata = mysql_query($query) or die("query: $query<br> This has an error: " . mysql_error() . '<br>');while($row = mysql_fetch_array($fetchdata)) { $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=319917.0 Hi all, I've built a few amateur sites in the past but am keen to utilize php combined with mysql for my current project. However, I have little knowledge of php and am just picking it up as I go (same way I've done for all my computer knowledge) What I'm looking for may sound simple, but I really don't know where to start and I'm hoping there are some kind souls here that will lend a hand. I've got some fantastic help here before and am hoping I'll get lucky again. SQL Database meetingid venue 001 new york 002 chicago 003 new york 004 new york 005 new york 006 texas 007 texas 008 chicago 009 new york 010 new york Question If I hard code everything around it, I'm just looking for the code I would need to have it display as follows: (hard coded text in blue) "New York has been used * times." (Where * would count the number of times "New York" appears in the venue column of the database.) "The most consecutive times New York has been used is % ." (Where % would count the maximum number of consecutive times "New York" appears in the venue column of the database.) Giving the output: New York has been used 6 times. The most consecutive times New York has been used is 3. |