Jump to content

Juan1989

New Members
  • Posts

    6
  • Joined

  • Last visited

Juan1989's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Okay what I have now is this, if the json_encode is in the while loop it will return all users with xxx-xxx-xxxx phone number, where if it is not within the while loop it will only return the last user in the table with the phone number: PHP page: <?php $con = mysqli_connect('localhost','root','root','mydb'); if (!$con) { die('Could not connect: ' . mysqli_error($con)); } mysqli_select_db($con,"mydb"); $sql = "SELECT * FROM incoming_calls"; $result = mysqli_query($con,$sql); while($row = mysqli_fetch_array($result)) { //$callArray = array('phonenumber' => $row['phone_number'], 'id' => $row['phone_login_id']); if(!empty($row)) { $number = $row['phone_number']; } } $sql="SELECT Username, Password FROM tblUsers WHERE PhoneHome='xxx-xxx-xxxx' OR PhoneCell='xxx-xxx-xxxx' OR PhoneWork='xxx-xxx-xxxx'"; $result = mysqli_query($con,$sql); while($row = mysqli_fetch_array($result)) { $userArray = array("username" => $row['Username'], "password" => $row['Password']); //echo json_encode($userArray); } echo json_encode($userArray); mysqli_close($con); ?> HTML page: <!DOCTYPE html> <html lang="en-US"> <head> <meta charset="utf-8"> <title>Phone calls</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> </head> <body> <script language="javascript" type="text/javascript"> function getCall(){ $.get("phonecall.php", function(data){ var loginInfo = jQuery.parseJSON(data); var user = loginInfo.username; var pass = loginInfo.password; $('#username').html(user); $('#password').html(pass); }); /*$.getJSON("phonecall.php", function(data){ for (var i=0, len=data.length; i < len; i++) { $('#username').html(data); } });*/ } setInterval(getCall,5000); </script> <div id="username"></div> <div id="password"></div> </body> </html> The problem I am having now is that when there are 2 or more users with the same phone number for say like a house phone, depending on where the json_encode is, will either return the last entry in the table, or return nothing at all. If the json_encode is in the while loop, I can check the console, it says the information is being retrieved, but something must not be right with my syntax to allow more than one entry to be displayed. Any ideas?
  2. Anytime new information is inserted into the table.
  3. I'm trying to get a simple javascript popup script going anytime the database is updated in real-time. I'm not sure as to what to do next, because I'm still a newbie with jQuery and ajax, but the following code is what I have right now: PHP MySQL query page: <?php $con = mysqli_connect('localhost','root','root','mydb'); if (!$con) { die('Could not connect: ' . mysqli_error($con)); } mysqli_select_db($con,"mydb"); $sql="SELECT * FROM incoming_calls"; $result = mysqli_query($con,$sql); while($row = mysqli_fetch_array($result)) { $callArray[] = array('phonenumber' => $row['phone_number'], 'id' => $row['phone_login_id']); } if (!empty($callArray)) { //echo json_encode($callArray); for ($i = 0; $i < count($callArray); ++$i) { print $callArray[$i]['id'] . ": " . $callArray[$i]['phonenumber'] . "<br>"; } } mysqli_close($con); ?> MySQL "incoming_calls" db table (I have a node.js script, that draws SMDR data from a phone system and posts it to this table): id phone_number phone_login_id date_created 3 000-000-0000 1225 12/15/2014 14:53 6 000-000-0000 1222 12/15/2014 14:53 9 000-000-0000 1202 12/15/2014 14:53 12 000-000-0000 1201 12/15/2014 14:55 18 000-000-0000 1232 12/15/2014 14:55 21 000-000-0000 1222 12/15/2014 14:57 24 000-000-0000 1222 12/15/2014 14:57 27 000-000-0000 1201 12/15/2014 14:58 30 000-000-0000 1207 12/15/2014 14:58 33 000-000-0000 1212 12/15/2014 14:59 HTML ajax call page: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Phone calls</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> </head> <body> <script language="javascript" type="text/javascript"> function getCall(){ $.get("phonecall.php", function(data){ $("#call").html(data); }); } setInterval(getCall,5000); </script> <div id="call"></div> </body> </html> Any help with this is greatly appreciated! Thanks ahead of time!
  4. Yes, I'm sorry about that. I was actually just thrown into this. This code was written long before I took over, so I'm having trouble thoroughly understanding what I'm doing as well. I apologize for the lack of comments. MySQL is definitely not something I'm proficient at.
  5. 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;
  6. I have an array that has several amounts (based on $$$ sales) attached to a 'name' 'id' and 'goal'. As you can see some of the names, id's, and goals are the same. My goal is to gather a total of amounts and attach each total to whichever 'name', 'id', and 'goal' that made the sale. I'm honestly not sure how to go about this as I'm still learning. Array ( [0] => Array ( [name] => L.Chane [id] => oper-4bceffd1-21e0af5b [goal] => 2014-10-25000 [amount] => 360.00 ) [1] => Array ( [name] => L.Chane [id] => oper-4bceffd1-21e0af5b [goal] => 2014-10-25000 [amount] => 450.00 ) [2] => Array ( [name] => L.Chane [id] => oper-4bceffd1-21e0af5b [goal] => 2014-10-25000 [amount] => 450.00 ) [3] => Array ( [name] => C.James [id] => oper-4c236420-0b11e945 [goal] => 2014-10-25000 [amount] => 370.00 ) [19] => Array ( [name] => C.James [id] => oper-4c236420-0b11e945 [goal] => 2014-10-25000 [amount] => 175.00 ) [20] => Array ( [name] => C.James [id] => oper-4c236420-0b11e945 [goal] => 2014-10-25000 [amount] => 155.00 )[61] => Array ( [name] => K.Crass [id] => oper-4c597644-402490ee [goal] => 2014-10-25000 [amount] => 200.00 ) [62] => Array ( [name] => K.Crass [id] => oper-4c597644-402490ee [goal] => 2014-10-25000 [amount] => 599.00 ) [63] => Array ( [name] => K.Crass [id] => oper-4c597644-402490ee [goal] => 2014-10-25000 [amount] => 50.00 ) [113] => Array ( [name] => R.Cervantes [id] => oper-4f05a90b-03b379f9 [goal] => 2014-10-25000 [amount] => 450.00 ) [114] => Array ( [name] => R.Cervantes [id] => oper-4f05a90b-03b379f9 [goal] => 2014-10-25000 [amount] => 589.00 ) [115] => Array ( [name] => R.Cervantes [id] => oper-4f05a90b-03b379f9 [goal] => 2014-10-25000 [amount] => 350.00 ) [166] => Array ( [name] => A.Gerred [id] => oper-4f30019a-27f27473 [goal] => 2014-10-25000 [amount] => 375.00 ) [167] => Array ( [name] => A.Gerred [id] => oper-4f30019a-27f27473 [goal] => 2014-10-25000 [amount] => 294.50 ) [168] => Array ( [name] => A.Gerred [id] => oper-4f30019a-27f27473 [goal] => 2014-10-25000 [amount] => 440.00 ) [202] => Array ( [name] => G.Whitcher [id] => oper-4f300d33-de9592e3 [goal] => 2014-10-25000 [amount] => 5.00 ) [203] => Array ( [name] => G.Whitcher [id] => oper-4f300d33-de9592e3 [goal] => 2014-10-25000 [amount] => 310.00 ) [204] => Array ( [name] => G.Whitcher [id] => oper-4f300d33-de9592e3 [goal] => 2014-10-25000 [amount] => 349.00 ) [235] => Array ( [name] => K.Lawrence [id] => oper-50f6e4ad-9effbec7 [goal] => 2014-10-25000 [amount] => 499.00 ) [236] => Array ( [name] => K.Lawrence [id] => oper-50f6e4ad-9effbec7 [goal] => 2014-10-25000 [amount] => 187.50 ) [237] => Array ( [name] => K.Lawrence [id] => oper-50f6e4ad-9effbec7 [goal] => 2014-10-25000 [amount] => 170.00 ) [246] => Array ( [name] => K.Chane [id] => oper-52657816-3d6516e2 [goal] => 2014-10-25000 [amount] => 375.00 ) [247] => Array ( [name] => K.Chane [id] => oper-52657816-3d6516e2 [goal] => 2014-10-25000 [amount] => 187.50 ) [248] => Array ( [name] => K.Chane [id] => oper-52657816-3d6516e2 [goal] => 2014-10-25000 [amount] => 229.50 ) [256] => Array ( [name] => J.Stewart [id] => oper-qtgjvw8y-1uqtw058 [goal] => 2014-10-25000 [amount] => 170.00 ) [257] => Array ( [name] => J.Stewart [id] => oper-qtgjvw8y-1uqtw058 [goal] => 2014-10-25000 [amount] => 584.00 ) [258] => Array ( [name] => J.Stewart [id] => oper-qtgjvw8y-1uqtw058 [goal] => 2014-10-25000 [amount] => 249.50 ) ) Here is my code so far (And I know it's not clean, because I'm not using PDO yet, I'm just trying to get it to work): $result = mysql_query("SELECT a.*,u.OperatorName,u.MonthlyGoal FROM tblUserPayments a LEFT JOIN tblOperatorGoals u ON a.OperatorID = u.OperatorID WHERE a.ChargeAmount IS NOT NULL AND a.PaymentStatus='OK' AND a.PaymentDate LIKE '$currentDate%' AND u.MonthlyGoal LIKE '$currentDate%' " ); while ($row = mysql_fetch_assoc($result)) { $operArray[] = array( 'name' => $row['OperatorName'], 'id' => $row['OperatorID'], 'goal' => $row['MonthlyGoal'], 'amount' => $row['ChargeAmount']); } foreach ($operArray as $value) { if($value['id'] == '' || $value['id'] == null) { continue; } if(array_key_exists($value['id'], $operSums)) { $operSums[$value['id']] += $value['amount']; } else { $operSums[$value['id']] = $value['amount']; } } Any help is greatly appreciated. Associative arrays are just not my cup of tea.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.