Jump to content

Barand

Moderators
  • Posts

    24,599
  • Joined

  • Last visited

  • Days Won

    829

Everything posted by Barand

  1. 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.
  2. 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 .... ";
  3. Your single quotes and commas need to be inside the double quotes, not outside.
  4. It's a check to ensure you don't output a footer before the first header (when $group is still null)
  5. 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
  6. 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)');
  7. You may want to read up on clustered indexes http://lmgtfy.com/?q=mysql+clustered+index
  8. Sorry, my fault. Missing " at the end of echo "<form name = \"myfirstform\" action = \"formprocess.php\" method = \"POST\">";
  9. 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>";
  10. echo substr('Local/567@context-0000461d;1', 6, 3); //--> 567
  11. 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
  12. Use ... WHERE %d IN (BizCat1, BixCat2, BizCat3) AND LiveOnWeb = 1 ...
  13. You should be normalizing your data and not storing data in db tables as you would in a spreadsheet.
  14. 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;
  15. 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
  16. The "ENT_Quotes" constant should be uppercase - ENT_QUOTES
  17. in which case ... and (keywords like '%$skey%' or bname like '%skey%') and category like '%Mycategory%'";
  18. 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"
  19. 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 | +--------+------------+-----------+
  20. 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.
  21. 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
  22. So what is the query you are actually executing? $query = mysql_query($query) or die (mysql_error()); echo $query; // what does this output?
  23. 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
  24. pseudocode version: $total_points = 0; // DEFINE the variable begin loop $points = whatever; // get points value $total_points += $points; // accumulate points total endloop echo $total_points;
  25. Define a total variable, say $total_points then accumulate the points values into that. $total_points += $points;
×
×
  • 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.