PHP - Queries Don't Seem To Work
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); } Similar TutorialsI can't seem to figure this out. The queries seem to need to be in the foreach loop. The queries will then work but they update every blog post in my table. I only want it to update the 1 that has the button associated with it. So for instance... only delete the blog post where post_id = ${post['id']} Do I make the queries be outside of the foreach? If I do that then MySQL fails because my foreach is using the $post variable. Code: [Select] <?php if (isset($_POST['approve'])) { $sql = " UPDATE `blog_posts` SET `approved` = 1 WHERE `post_id` = '${post['id']}' "; mysql_query($sql) or die(mysql_error()); } else if (isset($_POST['deny'])) { $sql = " UPDATE `blog_posts` SET `approved` = -1 WHERE `post_id` = '${post['id']}' "; } else if (isset($_POST['delete'])) { mysql_query("DELETE FROM `blog_posts` WHERE `post_id` = {$post['id']}") or die(mysql_error()); } foreach ($posts as $post) { ?> <div class="post" id="post<?php echo $post['id']; ?>"> <form action="blog.php" method="post" id="blogform" class="man"> <fieldset class="mvs buttonfield"> <span class="button"> <label> <input type="submit" id="starttop" name="approve" class="invis dark_grey" value="Approve" /> </label> </span> <span id="smarktop" class="button disabled"> <label> <input type="button" id="marktop" name="deny" class="invis dark_grey" value="Deny" disabled="disabled" /> </label> </span> <span id="sdeletetop" class="button disabled"> <label> <input type="submit" id="deletetop" name="delete" class="invis dark_grey" value="Delete" disabled="disabled" /> </label> </span> </fieldset> </form> </div> <?php } ?> 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. 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. 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. 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]}'" 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; Hello I have this query and it is working well: Code: [Select] $data = mysql_query(" SELECT `title`, `body`, 'condoms_en' as REF FROM `condoms_en` UNION SELECT `title`, `body`, 'discr_en' as REF FROM `discr_en` UNION SELECT `title`, `body`, 'diseases_en' as REF FROM `diseases_en` UNION SELECT `title`, `body`, 'express_en' as REF FROM `express_en` UNION SELECT `title`, `body`, 'gender_en' as REF FROM `gender_en` UNION SELECT `title`, `body`, 'get_informed_en' as REF FROM `get_informed_en` UNION SELECT `title`, `body`, 'get_tested_en' as REF FROM `get_tested_en` UNION SELECT `title`, `body`, 'newly_en' as REF FROM `newly_en` UNION SELECT `title`, `body`, 'news_hiv_en' as REF FROM `news_hiv_en` UNION SELECT `title`, `body`, 'nutrition_en' as REF FROM `nutrition_en` UNION SELECT `title`, `body`, 'phdp_en' as REF FROM `phdp_en` UNION SELECT `title`, `body`, 'press' as REF FROM `press` UNION SELECT `title`, `body`, 'r_o_en' as REF FROM `r_o_en` UNION SELECT `title`, `body`, 'stats_en' as REF FROM `stats_en` UNION SELECT `title`, `body`, 'stigma_en' as REF FROM `stigma_en` UNION SELECT `title`, `body`, 'think_news_en' as REF FROM `think_news_en` UNION SELECT `title`, `body`, 'think_reports' as REF FROM `think_reports` UNION SELECT `title`, `body`, 'treatment_en' as REF FROM `treatment_en` where`title` like '%$kw%' OR `body` like '%$kw%'") or die(mysql_error()); $rows = mysql_num_rows($data); I need to add to the same query this part: Code: [Select] SELECT `cont`, 'about_us_en' as REF FROM `about_us_en` UNION SELECT `que`,`ans`, 'faq_en' as REF FROM `faq_en` UNION SELECT `orga`, `lnk`, 'links_en' as REF FROM `links_en` UNION SELECT `title`, `desc`, 'publications' as REF FROM `publications` IF I add this part as is, I get an error saying that the select has different columns. Please Help and how do I modify the where if they are combined?! Thank you I was wondering if it is possible to perform the following query. Say I have a list of names each with an id number ranging from 1 to 10. Is it possible to perform a query where you list all of these records while repeating one records. For example could I do a query that lists record number 6 then 10, 9, 8, 7, 6 etc. Or another example would be listing record number 10, then 10, 9, 8, 7, 6 etc? Thanks for any help. I need two queries cause I don't know how to put them into one. Problem here is I need to know the field Liters from the database in the first query to subtract it from the second query to be able to calculate the average fuel consumption of the chosen range.
This is my code, hope you can help
function getContent() { include 'connection.php'; $dx = date('m', strtotime('today - 30 days')); if (!isset($_POST["month_select"])) { $month = $dx; $year = "2014"; } else { $month = $_POST["month_select"]; $year = $_POST["year_select"]; } //last fuel fill value $query2 = "SELECT d.liter as FirstFill FROM members AS m LEFT OUTER JOIN diesel AS d ON d.userid = m.id WHERE YEAR(dato) = $year AND MONTH(dato) = $month AND d.liter > 0 ORDER BY d.id ASC LIMIT 1"; $sql2=$oDB->prepare($query2); $sql2->execute(); $row2 = $sql2->fetchAll(); return $row2; $FirstFill = $row2['FirstFill']; $query = "SELECT m.username, m.id, 10 * (SUM(d.liter) - $FirstFill) / (MAX(d.km) - MIN(d.km)) as AvgFuel FROM members AS m LEFT OUTER JOIN diesel AS d ON d.userid = m.id WHERE YEAR(dato) = $year AND MONTH(dato) = $month AND d.liter > 0 GROUP BY m.id ORDER BY AvgFuel ASC"; $sql=$oDB->prepare($query); $sql->execute(); $row = $sql->fetchAll(); return $row; } Edited by Aero77, 23 May 2014 - 12:39 PM. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=331128.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. 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? how can i join the two queries so that they function as one. for example, if $keywords or $username is empty then the result will be null.
$query1 = "SELECT * FROM forums WHERE MATCH (topics) AGAINST ('$keywords' IN BOOLEAN MODE)"; $query2 = "SELECT * FROM users WHERE username='$username"; 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've been playing around with PDO lately, and I've been trying to get use to the basic functions as I've mentioned in some of my other posts/questions. Recently I switched to the ? bind/token (can't remember it's called), so I reformatted my processQuery. I've also tried to add in a fetching option in the method, but I can't seem to get anything to work. I've looked up several internet tutorials but it seems like I'm doing everything the same. Yet, the query doesn't seem to run. :/ $database->processQuery2("INSERT INTO test (test, testa) VALUES (?, ?)", array('noob', 'newb2'), false); Now for my method: public function processQuery2($query, array $binds, $fetch) { $query_handle = $this->dbc->prepare($query); if(count($binds) > 0) { $i = 1; $value = array(); foreach($binds as $bind) { $query_handle->bindParam($i, $value[$i]); $value[$i] = $bind; $i++; } } $query_handle->execute(); //if($fetch == true) //{ //return $query_handle->fetchAll(); //} } Any reasons to why it's not working? No errors are outputted, either. 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. Hi everyone I have the following PHP code $sql.= "INSERT INTO `data` (`info`, `write`, `date`) VALUES"; $sql.= "("; for ($c=0; $c < $num; $c++) { $sql.= '"'.str_replace('"', "", $data[$c]).'",'; } $sql.= "'".date('Y-m-d')."');"; If I print $sql; I get Code: [Select] INSERT INTO `data` (`info`, `write`, `date`) VALUES("data99","n",'2010-10-05'); INSERT INTO `data` (`info`, `write`, `date`) VALUES("data101","y",'2010-10-05'); INSERT INTO `data` (`info`, `write`, `date`) VALUES("data876","n",'2010-10-05'); what would I need to do to my PHP code in order for it to process each QUERY either all at once or one at a time Whatever I try, it either inserts nothing, or just does the first INSERT Any ideas? Thanks |