Jump to content

Barand

Moderators
  • Posts

    24,609
  • Joined

  • Last visited

  • Days Won

    832

Everything posted by Barand

  1. 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)); }
  2. 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
  3. 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;
  4. 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)
  5. WTF do you think the code I posted in reply #15 is for?
  6. 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
  7. You will have to put your strings inside double quotes or heredoc (to expand variable values) or use concatenation.
  8. 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"; } }
  9. see Jaques1's pseudocode in #4 above
  10. 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
  11. $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"
  12. 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 } ?>
  13. 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
  14. 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";
  15. 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/
  16. 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;
  17. 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); }
  18. http://uk1.php.net/manual/en/language.variables.external.php
  19. Are you invoking magic or do you have a more mundane method of storing and acquiring the username?
  20. 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; }
  21. Alternatively (where $hours is 1, 6 or 12), INSERT INTO mytable (date_added, expire_date) VALUES (NOW(), NOW()+INTERVAL $hours HOUR);
  22. First thing you should do is turn on error reporting so you don't try running code with syntax errors
  23. Just correcting a typo. mysql_set_charset() should be mysqli_set_charset()
  24. I think I see what you want now. You need to find the highest id associated with each topic and sort on that. $sql = "SELECT topic , description , topid FROM news INNER JOIN ( SELECT topic , MAX(id) as topid FROM news GROUP BY topic ) tid USING (topic) ORDER BY topid DESC, id ASC"; $res = $db->query($sql); $prevtopid = ''; while ($row = $res->fetch_assoc()) { if ($prevtopid != $row['topid']) { echo "<b>{$row['topic']}</b><br>"; $prevtopid = $row['topid']; } echo " - {$row['description']}<br>"; } Results barand - test - test 2 jogom - naaaaa moo - meee Hahaha - ???? Test Heading - Test - Hmmmm 100%!!! - Test description
×
×
  • 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.