-
Posts
24,614 -
Joined
-
Last visited
-
Days Won
835
Everything posted by Barand
-
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"
-
Submit multiple table rows with input elements to database
Barand replied to EnochHaruna's topic in PHP Coding Help
Instead of using names with suffixes like name="inc_amt".$pam use names like name="inc_amt[$pam]" That way your inputs are posted in arrays which can easily loop through. <?php foreach ($_POST['item_name'] as $pam => $name) { $inc_desc = $_POST['inc_desc'][$pam]; $inc_amt = $_POST['inc_amt'][$pam]; // process $pam, $name, $inc_desc, $inc_amt } ?> -
or <?php function randColor() { $r = rand(0,255); $g = rand(0,255); $b = rand(0,255); return sprintf('%02X%02X%02X', $r, $g, $b); } $tdata=''; for ($i=0; $i<10; $i++) { $tdata .= "<tr>"; for ($j=0; $j<10; $j++) { $c = randColor(); $tdata .= "<td style='background-color:#$c'>$c<br><span class='wtext'>$c</span></td>"; } $tdata .= '</tr>'; } ?> <html> <head> <style type='text/css'> table { border-collapse: collapse; } td { width: 60px; height: 60px; font-family: sans-serif; font-size: 8pt; text-align: center; } .wtext { color: white; } </style> </head> <body> <table border='1'> <?=$tdata?> </table> </body> </html> example output
-
Fetch columns of the mysql database table into a selectbox
Barand replied to heartsblack's topic in MySQL Help
try $sql = "SHOW COLUMNS FROM tablename"; $res = $mysqli->query($sql); echo "<select name='column_names'>"; while ($row = $res->fetch_row()) { echo "<option>{$row[0]}</option>"; } echo "</select>\n"; -
Fetch columns of the mysql database table into a selectbox
Barand replied to heartsblack's topic in MySQL Help
So what? I want to win the lottery. Why don't you stop posting your "wish list" and try asking a question, preferably with some detail and current code. You have a very similar post here http://forums.phpfreaks.com/topic/298261-transfer-data-from-one-select-box-to-another/ -
try $str = "en,ZA,1991-01-30,Male,1"; $items = explode(',', $str); $date = new DateTime($items[2]); $age = $date->diff(new DateTime())->y; echo $age;
-
try foreach($xml->current_observation as $item){ $current = (string)$item->weather; $temperature = (string)$item->temp_c; $time = (string)$item->local_time_rfc822; $wind = (string)$item->wind_string; $humidity = (string)$item->relative_humidity; $output[] = array($time, $temperature, $current, $wind); }
-
http://uk1.php.net/manual/en/language.variables.external.php
-
Are you invoking magic or do you have a more mundane method of storing and acquiring the username?
-
if ($link == '1'){ include ('page.php'); } elseif ($link == '1-1'){ include ('page.php'); } elseif ($link == '1-2'){ include ('page.php'); } else { include ('home.php'); } // alternatively switch ($link) { case '1': include ('page.php'); break; case '1-1': include ('page.php'); break; case '1-2': include ('page.php'); break; default: include ('home.php'); break; }