Jump to content

Barand

Moderators
  • Posts

    24,614
  • Joined

  • Last visited

  • Days Won

    835

Everything posted by Barand

  1. 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?
  2. 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.
  3. 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.
  4. 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)); }
  5. 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
  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;
  7. 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)
  8. WTF do you think the code I posted in reply #15 is for?
  9. 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
  10. You will have to put your strings inside double quotes or heredoc (to expand variable values) or use concatenation.
  11. 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"; } }
  12. see Jaques1's pseudocode in #4 above
  13. 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
  14. $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"
  15. 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 } ?>
  16. 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
  17. 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";
  18. 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/
  19. 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;
  20. 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); }
  21. http://uk1.php.net/manual/en/language.variables.external.php
  22. Are you invoking magic or do you have a more mundane method of storing and acquiring the username?
  23. 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; }
×
×
  • 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.