-
Posts
24,599 -
Joined
-
Last visited
-
Days Won
829
Everything posted by Barand
-
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.
-
Not a coder needs help with formatting to send email message
Barand replied to caliray's topic in PHP Coding Help
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 .... "; -
Not a coder needs help with formatting to send email message
Barand replied to caliray's topic in PHP Coding Help
Your single quotes and commas need to be inside the double quotes, not outside. -
It's a check to ensure you don't output a footer before the first header (when $group is still null)
-
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
-
Prepared Delete Statement with Subquery in mysql table
Barand replied to BuildMyWeb's topic in PHP Coding Help
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)'); -
You may want to read up on clustered indexes http://lmgtfy.com/?q=mysql+clustered+index
-
Keeping randomly generated numbers and checking the sum
Barand replied to cenalt's topic in PHP Coding Help
Sorry, my fault. Missing " at the end of echo "<form name = \"myfirstform\" action = \"formprocess.php\" method = \"POST\">"; -
Keeping randomly generated numbers and checking the sum
Barand replied to cenalt's topic in PHP Coding Help
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>"; -
echo substr('Local/567@context-0000461d;1', 6, 3); //--> 567
-
Combine results from multiple members who have like categories using OR
Barand replied to HalRau's topic in PHP Coding Help
Use ... WHERE %d IN (BizCat1, BixCat2, BizCat3) AND LiveOnWeb = 1 ... -
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;
-
need to Amendment the Code: it Duplicate records
Barand replied to x-man1's topic in PHP Coding Help
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 -
Help with pulling/displaying data from table?
Barand replied to Sherlocked's topic in PHP Coding Help
The "ENT_Quotes" constant should be uppercase - ENT_QUOTES -
in which case ... and (keywords like '%$skey%' or bname like '%skey%') and category like '%Mycategory%'";
-
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"
-
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 | +--------+------------+-----------+
-
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.
-
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
-
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
-
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;
-
Define a total variable, say $total_points then accumulate the points values into that. $total_points += $points;