Jump to content

Barand

Moderators
  • Posts

    24,602
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. $query = "SELECT * FROM asterisk_cdr WHERE calldate BETWEEN '$calldate' AND '$calldate2' AND clid LIKE '%$clid%'"; if (!empty($_GET['channel'])) { $channel = $mysqli->real_escape_string($_GET['channel']); $query .= " AND channel LIKE '%$channel%' "; }
  2. store the data in arrays as you process the query results expense[year][month] = exp_total income[year][month] = inc_total Then it's a matter of looping through the arrays to output. Because you want Apr as month 0 and March as month 11 then the month index in the arrays will be (month + 8 ) % 12 and you will have to check the month to see if it goes in this year or the next
  3. Try $location = DB::getInstance()->query("SELECT country, COUNT(country) as countCountry FROM users GROUP BY country ORDER BY count DESC"); while ($locations = $location->fetch_object()) { echo "<tr><td>"; echo $locations->country; echo "</td><td>"; echo $locations->countCountry; echo "</td></tr>"; } edit : Plus what Ch0cU3r said.
  4. Precisely that. EG $message_m ="'" . $_POST['fname'] . "', with RefCode '" . $RefC . "', and .... "; Alternatively, don't use concatenation if it's confusing you $message_m = "'{$_POST['fname']}', with RefCode '$RefC', and .... ";
  5. Your single quotes and commas need to be inside the double quotes, not outside.
  6. It's a check to ensure you don't output a footer before the first header (when $group is still null)
  7. Like this $rowKitCharges = [ [ 'SubCategory' => 'A', 'HireID' => 123 ], [ 'SubCategory' => 'A', 'HireID' => 124 ], [ 'SubCategory' => 'B', 'HireID' => 125 ], [ 'SubCategory' => 'C', 'HireID' => 126 ], [ 'SubCategory' => 'C', 'HireID' => 127 ], [ 'SubCategory' => 'C', 'HireID' => 128 ] ]; $group = null; $count = 0; for($i=0;$i<count($rowKitCharges);$i++){ if($rowKitCharges[$i]['SubCategory'] != $group) { if ($group) { echo "<b>TOTAL ITEMS: $count</b><br><br>"; // FOOTER } //echo the group header echo "<br><b>" . $rowKitCharges[$i]['SubCategory'] . "</b><br>"; $group = $rowKitCharges[$i]['SubCategory']; $count = 0; } echo $rowKitCharges[$i]['HireID'] . " " . $rowKitCharges[$i]['SubCategory']; ++$count; echo "<br>"; } // OUTPUT FINAL FOOTER echo "<b>TOTAL ITEMS: $count</b><br><br>"; // FOOTER
  8. As you aren't using a variable you don't need a prepared statement $db_connect->query('DELETE FROM table WHERE owner=0 AND owner NOT IN (SELECT owner FROM table ORDER BY dob DESC LIMIT 10)');
  9. You may want to read up on clustered indexes http://lmgtfy.com/?q=mysql+clustered+index
  10. Sorry, my fault. Missing " at the end of echo "<form name = \"myfirstform\" action = \"formprocess.php\" method = \"POST\">";
  11. First, store the random numbers that you generate echo "<html><head><title>calculation game!</title></head><body>"; $n1 = rand(100, 450); $n2 = rand(100, 5000); echo "<h1>first number is</h1>"; echo $n1; echo "<h1>and the next number is</h1>"; echo $n2; Then put those values in hidden form fields so they get sent with the sum echo "<form name = \"myfirstform\" action = \"formprocess.php\" method = \"POST\"> echo "Enter data<br>"; echo "<input type = \"text\" name = \"firstdata\">"; echo "<input type='hidden' name='n1' value='$n1'>"; // hidden form field echo "<input type='hidden' name='n2' value='$n2'>";; // hidden form field echo "<br> <input type= \"submit\" value = \"Let's check!\">"; echo "</form>";
  12. echo substr('Local/567@context-0000461d;1', 6, 3); //--> 567
  13. I suppose that somewhere in there a query is being executed to get the records for John but no way to see what it is and, therefore, no way to know how to change it. All I can do then is point you towards Sql SUM() function and GROUP BY clauses
  14. Use ... WHERE %d IN (BizCat1, BixCat2, BizCat3) AND LiveOnWeb = 1 ...
  15. You should be normalizing your data and not storing data in db tables as you would in a spreadsheet.
  16. If you are that curious, why don't you time how long it takes to get a few hundred items from your array. Then convert the array to a string and time how long it takes doing it that way. $t1 = microtime(true); // perform the data extraction here $t2 = microtime(true); $timeTaken = $t2 - $t1;
  17. Here is how I would do it $sql = "SELECT ID_student , name , Age , Grade , ID_infractions , infractions_text , ID_Actions , Actions_text FROM view1 ORDER BY ID_student,ID_infractions,ID_Actions"; $res = $db->query($sql); $currid = 0; $currName = $currAge = $currGrade = ''; $data = array(); $heads = "<tr><th>Name</th><th>Age</th><th>Grade</th><th>Infractions</th><th>Actions</th></tr>"; $tdata = ''; while (list($sid,$name,$age,$grd,$infid,$inftxt,$actid,$acttxt) = $res->fetch_row()) { // CHECK FOR CHANGE IN ID if ($sid != $currid) { if ($currid) { // OUTPUT DATA FOR STUDENT WHEN WE GET A NEW ID $tdata .= "<tr valign='top'><td>$currName</td><td>$currAge</td><td>$currGrade</td><td>"; foreach ($data['infracts'] as $k=>$v) { $tdata .= "$k $v<br>"; } $tdata .= "</td><td>"; foreach ($data['actions'] as $k=>$v) { $tdata .= "$k $v<br>"; } $tdata .= "</td></tr>\n"; } // STORE DATA FOR CURRENT STUDENT $currid = $sid; $currName = $name; $currAge = $age; $currGrade = $grd; $data = array(); } // STORE INFRACTION AND ACTION DATA $data['actions'][$actid] = $acttxt; $data['infracts'][$infid] = $inftxt; } // DON'T FORGET TO OUTPUT THE LAST STUDENT // THAT IS STORED IN THE DATA $tdata .= "<tr><td>$currName</td><td>$currAge</td><td>$currGrade</td><td>"; foreach ($data['infracts'] as $k=>$v) { $tdata .= "$k $v<br>"; } $tdata .= "</td><td>"; foreach ($data['actions'] as $k=>$v) { $tdata .= "$k $v<br>"; } $tdata .= "</td></tr>\n"; ?> <html> <body> <table border='1'> <?= $heads?> <?= $tdata?> </table> </body> </html> Giving
  18. The "ENT_Quotes" constant should be uppercase - ENT_QUOTES
  19. in which case ... and (keywords like '%$skey%' or bname like '%skey%') and category like '%Mycategory%'";
  20. Makes no difference. If I search php.net manual for "mysqli_query" I get the page shown below. Same goes for a search for "mysqli::query"
  21. Or you can do it in the query mysql> SELECT * FROM user; +--------+------------+-----------+ | iduser | first_name | last_name | +--------+------------+-----------+ | 1 | Stella | NULL | | 2 | Amanda | Brown | | 3 | Kevin | Green | | 4 | John | Wilson | | 5 | Helen | NULL | | 6 | Pete | Doone | +--------+------------+-----------+ mysql> SELECT iduser -> , first_name -> , IFNULL(last_name, '(No data)') as lastname -> FROM user; +--------+------------+-----------+ | iduser | first_name | lastname | +--------+------------+-----------+ | 1 | Stella | (No data) | | 2 | Amanda | Brown | | 3 | Kevin | Green | | 4 | John | Wilson | | 5 | Helen | (No data) | | 6 | Pete | Doone | +--------+------------+-----------+
  22. As you have it now the name would be in $info[0], uom in $info[1] and description in $info[2]. I'd do it something like this function items($item_id) { $details = array(); $result = mysql_query("select name, uom, description from items where item_id=".$item_id."") or die (mysql_error()); while($row = mysql_fetch_assoc($result)) { $details[] = $row; } return $details; } $info = items($id); echo $info['name']; echo $info['uom']; echo $info['description']; If you are having to stripslashes then your handling of inputs to the database is wrong.
  23. It is there in the php manual http://php.net/manual/en/mysqli.query.php Search for "mysqli" then click on the links for the individual methods. As to why a search for "mysqli_query" doesn't work is an issue you would have to take up with php.net
  24. So what is the query you are actually executing? $query = mysql_query($query) or die (mysql_error()); echo $query; // what does this output?
  25. I suggest you read the pseudocode again (reply #9) Setting the total to zero is done before the loop begins. Inside the loop calculate the value for the points accumulate into the total After the loop echo the accumulated total
×
×
  • 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.