Jump to content

Barand

Moderators
  • Posts

    24,573
  • Joined

  • Last visited

  • Days Won

    824

Everything posted by Barand

  1. If you want to use the current code (some DateTime stuff requires PHP5.3) then just change this line echo "$remainingDay days, $remainingHour hours, $remainingMinutes minutes, $remainingSeconds seconds";
  2. Why don't you use DateTime object like I showed you in your other post? http://forums.phpfreaks.com/topic/298299-string-to-array-and-date/?do=findComment&comment=1521469 It saves you a shedload of code $targetDate = new DateTime('2015-12-25 12:00:00'); $remaining = $targetDate->diff(new DateTime()); echo $remaining->format('%a D - %H:%I:%S'); //--> 86 D - 19:44:24
  3. So he has! Shouldn't it be "Anaemic Administrator" now?
  4. Your solution shows another flaw, apart from the lack of validation, in your site. You should never put user input directly into a query. Always sanitize it against SQL injection first, or (better) use a prepared query. Although changing to prepared queries id probably a problem given your wp library. I had prepared a small working script for you so I may as well post it to demonstrate this <?php $mysqli = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); $gemeente = isset($_GET['gemeente']) ? $_GET['gemeente'] : ''; $top10 = ''; /****************************************************************************** *** *** GET LOCATION SELECT OPTIONS FOR MENU *** *******************************************************************************/ $sql = "SELECT DISTINCT value FROM wp_rg_lead_detail WHERE field_number = 11 ORDER BY value "; $loc_options = ''; $res = $mysqli->query($sql); while (list($locname) = $res->fetch_row()) { $sel = ($locname==$gemeente) ? 'selected="selected"' : ''; // select current gemeente $loc_options .= "<option $sel>$locname</option>\n"; } /****************************************************************************** *** *** CREATE TOP10 LIST FOR CHOSEN LOCATION *** *******************************************************************************/ if ($gemeente) { $gemeente = $mysqli->real_escape_string($gemeente); // sanitize user input $sql = "SELECT location , value , COUNT(*) as total FROM wp_rg_lead_detail INNER JOIN ( SELECT lead_id , value as location FROM wp_rg_lead_detail WHERE field_number = 11 ) loc USING (lead_id) WHERE field_number IN (8,16,20) AND value <> 'Selecteer uw lied!' AND location = '$gemeente' GROUP BY location, value ORDER BY location, total DESC LIMIT 10"; $top10 = "<ol>\n"; $res = $mysqli->query($sql); while (list($loc, $song, $total) = $res->fetch_row()) { $top10 .= "<li>$song ($total)</li>\n"; } $top10 .= "</ol>\n"; } ?> <html> <head> <meta name="generator" content="PhpED 14.0 (Build 14039, 64bit)"> <title>Example</title> <meta name="author" content="Barand"> <meta name="creation-date" content="09/29/2015"> </head> <body> <h1>Top 10</h1> <form method='get' action=''> Select location <select name="gemeente"> <option value=''> - location -</option> <?=$loc_options?> </select> <input type="submit" name="btnSubmit" value="Submit"> </form> <hr> <?=$top10?> </body> </html>
  5. To close it, click the "Best Answer" button in the most helpful reply
  6. Hi Newbie, If you are writing "Selecteer uw lied!" to the database then your validation is poor. For the location you need a subquery to pull the "11" records. I am assuming the field "Lead_id" is the one that groups the 8,11,16,20 records together. SELECT location , value , COUNT(*) as total FROM wp_rg_lead_detail INNER JOIN ( SELECT lead_id -- subquery to find location for the song choices , value as location FROM wp_rg_lead_detail WHERE field_number = 11 ) loc USING (lead_id) WHERE field_number IN (8,16,20) AND value <> 'Selecteer uw lied!' AND location = 'Zoetermeer ' -- remove this line for all locations GROUP BY location, value -- and remove location from ORDER and GROUP ORDER BY location, total DESC LIMIT 10
  7. Instead of echoing "problem", try echoing something informative while you are debugging, like echo $stmt->error;
  8. Can you give us some sample data, an example of the what the user might enter and the expected result? [EDIT] Beaten to the post, again.
  9. you could try SELECT value , COUNT(*) as total FROM FROM wp_rg_lead_detail WHERE field_number=8 or field_number=16 or field_number=20 GROUP BY value ORDER BY total DESC LIMIT 10
  10. 1. Do not hijack old threads. I have moved your post to a new topic. 2. Use code tags around your code (use the <> button in the toolbar) I cannot see from your code how you know what answer the user gave, so that you can see if it is correct or not. In fact, with its confusing mix of html and php, lack of indentation plus repetitive code, it's not easy to see anything. What is the significance of "correct_answer" having the value "group"? And finally, what is your question?
  11. DISTINCT is not a function that you can apply to a single field - it applies to the whole row. You haven't defined the join condition for the tables team_details and team_players. You haven't given us your table structure.
  12. In this instance, $deletedCat = 1 UPDATE mytable SET cat = cat - 1 WHERE cat > $deletedCat But, as Mac_Gyver said, in a production environment, don't.
  13. you age conditions should be if (trim($ageFrom) != '') { $where[] = sprintf ("(age >= '%s')", $mysqli->real_escape_string($ageFrom)); } if (trim($ageTo) != '') { $where[] = sprintf ("(age <= '%s')", $mysqli->real_escape_string($ageTo)); }
  14. PHP does not require compiling. If it isn't already, put the directory containing php.exe in your path directive. At the command prompt, change to the directory containing your "index.php" invoke php.exe and pass it your arguments, which will be index.php, a, b, and c For example, to solve x^2 - 5x + 6 >php index.php 1 -5 6
  15. I use something like this $where = array(); $whereclause = ''; if (trim($gender) != '') { $where[] = sprintf ("(gender = '%s')", $mysqli->real_escape_string($gender)); } if (trim($mother_tongue) != '') { $where[] = sprintf ("(mother_tongue = '%s')", $mysqli->real_escape_string($mother_tongue)); } // etc if (count($where) > 0) { $whereclause = 'WHERE ' . join(' AND ', $where); } $sql = "SELECT * FROM tbluser " . $whereclause;
  16. If the user doesn't specify a value then leave that condition out of the WHERE clause. So if no value is supplied for "mother_tongue" then the WHERE clause will be WHERE gender='male' AND religion_id='3' AND caste_id='374' AND (age BETWEEN 50 AND 70)
  17. WTF do you think the code I posted in reply #15 is for?
  18. The use of curly braces for accessing a character of a string still works $str = 'abc'; echo $str{0}; //--> a However, I haven't seen that notation used since PHP 3, last century, and nowadays it is usual to use normal array notation $str = 'abc'; echo $str[0]; //-> a
  19. You will have to put your strings inside double quotes or heredoc (to expand variable values) or use concatenation.
  20. here's an example $sql = "SELECT category_id, name, parent FROM category"; $children = []; $res = $db->query($sql); while (list($cid, $name, $pid) = $res->fetch_row()) { $children[$pid][$cid] = $name; } display_category_level($children); function display_category_level(&$children, $parent=-1) { if (isset($children[$parent])) { echo "<ul>\n"; foreach ($children[$parent] as $id=>$name) { echo "<li>$name</li>\n"; display_category_level($children, $id); } echo "</ul>\n"; } }
  21. see Jaques1's pseudocode in #4 above
  22. something like this if ($argc < 4) { exit("USAGE: >index.php a b c\n"); } list(,$a,$b,$c) = $argv; if ($a != 0) { //after assigning variables you can calculate your equation $d = $b*$b - (4*$a*$c); $x1 = (-$b + sqrt($d)) / (2 * $a); $x2 = (-$b - sqrt($d)) / (2 * $a); echo "x1 = {$x1} and x2 = {$x2}"; } else echo "'a' cannot be zero"; example usage >index.php 1 -5 6 outputs : x1 = 3 and x2 = 2
  23. $title needs to be in single quotes otherwise SQL is looking for a column called "addtext" You need to specify the record to be updated otherwise all records will get the same update "update product set sale=CONCAT(sale, '$title') WHERE product_id = $whatever"
×
×
  • 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.