-
Posts
24,573 -
Joined
-
Last visited
-
Days Won
824
Everything posted by Barand
-
Php only countdown with action to follow when countdown time reach 0
Barand replied to cobusbo's topic in PHP Coding Help
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"; -
Php only countdown with action to follow when countdown time reach 0
Barand replied to cobusbo's topic in PHP Coding Help
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 -
How to send Mail from Wampserver ( localhost )
Barand replied to cadamuro's topic in PHP Coding Help
So he has! Shouldn't it be "Anaemic Administrator" now? -
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>
-
To close it, click the "Best Answer" button in the most helpful reply
-
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
-
Trouble with Joining Tables in prepared select statement
Barand replied to BuildMyWeb's topic in MySQL Help
Instead of echoing "problem", try echoing something informative while you are debugging, like echo $stmt->error; -
Return single row based on comparison of two values
Barand replied to imkesaurus's topic in PHP Coding Help
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. -
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
-
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?
- 1 reply
-
- 1
-
PHP and MYSQL join tables and select users id in both tables.
Barand replied to blmg2009's topic in PHP Coding Help
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. -
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.
-
what is the difference between php web and php command line?
Barand replied to lobster's topic in PHP Coding Help
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 -
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;
-
what is the difference between php web and php command line?
Barand replied to lobster's topic in PHP Coding Help
WTF do you think the code I posted in reply #15 is for? -
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
-
Submit multiple table rows with input elements to database
Barand replied to EnochHaruna's topic in PHP Coding Help
You will have to put your strings inside double quotes or heredoc (to expand variable values) or use concatenation. -
help, php drop down menu using hierarchical database
Barand replied to kslakhani's topic in PHP Coding Help
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"; } } -
help, php drop down menu using hierarchical database
Barand replied to kslakhani's topic in PHP Coding Help
see Jaques1's pseudocode in #4 above -
what is the difference between php web and php command line?
Barand replied to lobster's topic in PHP Coding Help
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 -
$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"