Search the Community
Showing results for tags 'queries'.
-
<?php $con=mysqli_connect("localhost","my_user","","shazz"); $query = mysqli_query($con,"SELECT * from posts2 order by rand() LIMIT 0,4"); $post_title ="shazz"; while ($row=mysqli_fetch_array($query)) { $post_id=$row['post_id']; $post_title=$row['post_title']; $post_date=$row['post_date']; $post_author=$row['post_author']; $post_image=$row['post_image']; $post_keywords=$row['post_keywords']; $post_content=substr($row['post_content'],0,200); } ?> the following are the errors im facing: Warning: mysqli_connect(): (HY000/1044): Access denied for user ''@'localhost' to database 'shazz' inC:\xampp\htdocs\shazz\include\main_content.php on line 3 Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given inC:\xampp\htdocs\shazz\include\main_content.php on line 4 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given inC:\xampp\htdocs\shazz\include\main_content.php on line 6
-
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;
-
So I have a user profile setup where it's linked unique username using $_GET session. That all works. Now here's a bit that I didn't think of. I can't display the same profile that I view to other users; because then the content on the profile page would be relavent to the person logged in. For eg. $get_username = $_GET['user']; if($username === $get_username) { $stmt = $dbh->prepare("SELECT * FROM users WHERE user_id = $userid"); //display user's profile to himself only. } else { //display user's profile to everyone else } My set is like that. The problem with that is, I can't get the same content to show on the the profile that's viewed by other users; because I'm using current logged in user's id to get records from mysql db.
-
Hi, I'm currently setting up some new code for a website I am working on - It is PHP based, and is accessing a MySQL database. I've been looking at the logs on the server, and it seems everytime someone does a search using the site, it actually runs the query twice - Once using the 'LIMIT' command, and once without. If this is the case, then it is surely wasting resources as it should only be running it once. Can anyone spot where this is going wrong, and offer any assistance and guidance ? Here is the code in question (I don't know if you need all the code): <?php require_once('Connections/databaseconnect.php'); ?> <?php require('functionformat.php'); ?> <?php /* The following strips out the use of the % and _ wildcard characters, before running the query. */ $pattern = array('/%/','/_/','/!/','/$/','/^/','/{/','/}/','/,/','/=/','/"/','/|/','/:/','/;/'); $replace = array('',''); $search_name = preg_replace($pattern, $replace, $_POST[search_name]); $search_name = mysql_real_escape_string($search_name); $unconfirmed_header = 0; $confirmed_header = 0; if (strlen($search_name) < "2") { } else { $maxRows_Recordset1 = 1250; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; mysql_select_db($database_stemel, $stemel); $query_Recordset1 = "SELECT company_number, company_name, url, phone_no, mobile_no, home_no, mob2_no, other_info, confirmed FROM contact1 WHERE (confirmed = '0' OR confirmed = '1') AND (company_name LIKE '%$search_name%' OR other_info LIKE '%$search_name%' OR url LIKE '%$search_name%') ORDER BY confirmed DESC, company_name ASC, company_number ASC"; $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $stemel) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = $_GET['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <?php /* This section passes on received values as hidden fields after validating null entries. */ include ('header.php'); ?> <link rel="stylesheet" href="search.css" type="text/css" /> <?php if (($totalRows_Recordset1) > 0) { if ($row_Recordset1['confirmed'] & 1) { ?> <table width="100%" align="center" border="0"> <tr> <td><font size="2"> <div class="seperator"></div> <div class="boardcontainer"> <table cellpadding="4" cellspacing="1" border="0" width="100%"> <tr><td colspan="6" class="catbg" height="18" >Main Database</td></tr> <tr> <td class="windowbg" width="28%" align="center">Company Name</td> <td class="windowbg" width="12%" align="center">Phone No</td> <td class="windowbg" width="12%" align="center">Mobile No</td> <td class="windowbg" width="12%" align="center">Home No</td> <td class="windowbg" width="12%" align="center">Personal Mobile</td> <td class="windowbg" width="24%" align="center">Other Info</td> </tr> <?php $confirmed_header=1; } /* Message that is displayed when no CONFIRMED numbers are returned from the database */ { if ($confirmed_header < 1) { ?> <table width="100%" align="center" border="0"> <tr> <td><font size="2"> <div class="seperator"></div> <div class="boardcontainer"> <table cellpadding="4" cellspacing="1" border="0" width="100%"> <tr><td colspan="6" class="catbg" height="18" >Main Database</td></tr> <tr> <td class="windowbg" width="28%" align="center">Company Name</td> <td class="windowbg" width="12%" align="center">Phone No</td> <td class="windowbg" width="12%" align="center">Mobile No</td> <td class="windowbg" width="12%" align="center">Home No</td> <td class="windowbg" width="12%" align="center">Personal Mobile</td> <td class="windowbg" width="24%" align="center">Other Info</td> </tr> <tr> <td class=windowbg2 colspan="6" align=center BGCOLOR=#FFFFCC><B>No confirmed numbers have been found that match the criteria you entered. One or more have been found in the unconfirmed list, and are listed below.</B></td> </tr> </table> </div> <?php }{} } ?> <?php do { ?> <tr> <?php if ($row_Recordset1['confirmed'] & 1) { if (strlen($row_Recordset1['url']) > "2") { echo '<td class=windowbg2 width=28% align=center BGCOLOR=#FFFFCC><a href=http://www.mywebsite.com/external.php?site='.$row_Recordset1['url'].' target="_blank">'.$row_Recordset1 ['company_name'].'</a></td>'; } else { echo '<td class=windowbg2 width=28% align=center BGCOLOR=#FFFFCC>'.$row_Recordset1['company_name'].'</a></td>'; } echo '<td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC>*'.format_phone($row_Recordset1['phone_no']).'</td>'; echo '<td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC>*'.format_phone($row_Recordset1['mobile_no']).'</td>'; echo '<td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC>*'.format_phone($row_Recordset1['home_no']).'</td>'; echo '<td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC>*'.format_phone($row_Recordset1['mob2_no']).'</td>'; echo '<td class=windowbg2 width=24% align=center BGCOLOR=#FFFFCC>*'.$row_Recordset1['other_info'].'</td></tr>'; } else { if ($unconfirmed_header < 1) { ?> </tr> </table> </div><br /> <table width="100%" align="center" border="0"> <tr><td><font size="2"> <div class="seperator"></div> <div class="boardcontainer"> <table cellpadding="4" cellspacing="1" border="0" width="100%"> <tr><td colspan="6" class="catbg" height="18" >Unconfirmed Numbers</td></tr> <tr> <td class="windowbg" width="28%" align="center">Company Name</td> <td class="windowbg" width="12%" align="center">Phone No</td> <td class="windowbg" width="12%" align="center">Mobile No</td> <td class="windowbg" width="12%" align="center">Home No</td> <td class="windowbg" width="12%" align="center">Personal Mobile</td> <td class="windowbg" width="24%" align="center">Other Info</td> </tr> <?php $unconfirmed_header = 1; } if (strlen($row_Recordset1['url']) > "2") { echo '<td class=windowuv width=28% align=center BGCOLOR=#CCFFFF> '.$row_Recordset1['company_name'].'</td>'; } else { echo '<td class=windowuv width=28% align=center BGCOLOR=#CCFFFF>'.$row_Recordset1['company_name'].'</a></td>'; } echo '<td class=windowuv width=12% align=center BGCOLOR=#CCFFFF>*'.format_phone($row_Recordset1['phone_no']).'</td>'; echo '<td class=windowuv width=12% align=center BGCOLOR=#CCFFFF>*'.format_phone($row_Recordset1['mobile_no']).'</td>'; echo '<td class=windowuv width=12% align=center BGCOLOR=#CCFFFF>*'.format_phone($row_Recordset1['home_no']).'</td>'; echo '<td class=windowuv width=12% align=center BGCOLOR=#CCFFFF>*'.format_phone($row_Recordset1['mob2_no']).'</td>'; echo '<td class=windowuv width=24% align=center BGCOLOR=#CCFFFF>*'.$row_Recordset1['other_info'].'</td></tr>'; } ?> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </tr> </table> </div><br /> <div class="seperator"> <table cellpadding="4" cellspacing="1" border="0" width="100%"> <tr> <td class="titlebg" align="center" colspan="2"> Info Centre </td> </tr> <td class="windowbg2"> <div style="float: left; width: 59%; text-align: left;"> <span class="small">Please update us with any corrections as soon as possible.</span><br /> </div> <div style="float: left; width: 40%; text-align: left;"> <div class="small" style="float: left; width: 49%;"><span style="color: red;"><b>lllll</b></span></div> </div> </td> </tr> </table> </div> </font></td> </tr> </table> <?php } else { ?> <body bgcolor="#FFFFCC"> <tr><td colspan=10> <center><table border=1 bordercolor=navy cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCCFF"><div class=TableTitle> <p align="center"><b><font face="Tahoma">NO RESULTS FOUND</font></b></div></td></tr><tr><td BGCOLOR=#FFFFCC> <div align="center"> <h3> </h3> </div> <div align="center"> <h3><font face="Tahoma" size="3">Your search didn't match any records.</B></font></h3> <h3> </h3> </div> </td></tr></table></center> </td></tr></table><br> <?php } ?> <br> <?php require ('footer.php'); if (($totalRows_Recordset1) > 0) { mysql_free_result($Recordset1); mysql_close(); }else{ } ?> Thanks in advance for any help, Daniel
-
Dear All I have written an application in C++ which generates system logs and then parses those logs and uploads them to MySQL. I have written some basic PHP scripts to present this data but it's going to take too long to get the framework which I need. I am looking for a PHP class to use as a starting point which will provide a method for uses to query the database and present this data to a webpage. Does such a class exist? Many Thanks Nikki
-
I'm trying to merge all these queries into one statement $q = "DELETE FROM ".TBL_USERS." WHERE username = '$session->username'"; $database->query($q); $q = "DELETE FROM ".TBL_BANNED_USERS." WHERE username = '$session->username'"; $database->query($q); $q = "DELETE FROM ".TBL_MAIL." WHERE UserTo = '$session->username'"; $database->query($q); $q = "DELETE FROM ".TBL_MAIL." WHERE UserFrom = '$session->username'"; $database->query($q); $q = "DELETE FROM ".TBL_FRIENDS." WHERE person_id = '$session->username'"; $database->query($q); $q = "DELETE FROM ".TBL_FRIENDS." WHERE friend_id = '$session->username'"; $database->query($q); $q = "DELETE FROM ".TBL_FORUM." WHERE author = '$session->username'"; $database->query($q); I have no idea how to do this I have tried Google and no joy please help - Jamie
-
I'll state that I'm a complete amateur when it comes to programming in case I'm not clear or I say something that doesn't make sense. I have two websites which have evolved over the years with different programmers at different times - www.little-persia.com and www.love-rugs.com. I look after both cosmetically and have worked out various issues with javascript, php etc. over the years by just researching and teaching myself/using common sense/problem solving. However I'm stumped. Little-Persia is really fast when it comes to searches (page changes in under 2 seonds and images load within another second) yet Love-Rugs is unbearably slow (I hit search and the page hangs for about 12 seconds before doing anything). I think I've worked it out as having little to do with page sizes/image load times etc. and more to do with number of queries. Load times are at their worst for a blank search - if I put in a few filters in an advances search the load times become bearable (although still not great or anywhere near the same speed as Little-Persia). The two websites have different tables with Love-Rugs loading information on stock levels/size and price from one and general details from another. Little-Persia is all individual products (don't come in a variety of sizes/prices) so all their info is stored on one table. I'm trying to obviously figure out how to speed it up and/or remove unnecessary queries but to do that I need to find out where they're originating. Is there a way to do this?