Jump to content

Barand

Moderators
  • Posts

    24,606
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. 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)
  2. WTF do you think the code I posted in reply #15 is for?
  3. 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
  4. You will have to put your strings inside double quotes or heredoc (to expand variable values) or use concatenation.
  5. 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"; } }
  6. see Jaques1's pseudocode in #4 above
  7. 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
  8. $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"
  9. 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 } ?>
  10. 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
  11. 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";
  12. 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/
  13. 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;
  14. 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); }
  15. http://uk1.php.net/manual/en/language.variables.external.php
  16. Are you invoking magic or do you have a more mundane method of storing and acquiring the username?
  17. 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; }
  18. Alternatively (where $hours is 1, 6 or 12), INSERT INTO mytable (date_added, expire_date) VALUES (NOW(), NOW()+INTERVAL $hours HOUR);
  19. First thing you should do is turn on error reporting so you don't try running code with syntax errors
  20. Just correcting a typo. mysql_set_charset() should be mysqli_set_charset()
  21. 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
  22. Exactly.
  23. Advanced Member, do it like this $show = "SELECT FirstName, LastName FROM Members"; $result2 = mysqli_query($Garydb,$show) or die("Could not show record"); echo "<table>"; if (mysqli_num_rows($result2) > 0) { while ($row = mysqli_fetch_assoc($result2) ) { echo "<tr><td>" . $row['FirstName']. " " . $row['LastName'] . "</td></tr>"; } } else { echo "<tr><td>No display record</td></tr></table>"; } echo "<table>"; After 40+ posts you should have found the code tags by now.
  24. ORDER BY topic, id DESC or, if you want topics descending too, ORDER BY topic DESC, id DESC
  25. You connect to the mysql database server, not to PHPMyAdmin. The error you are getting is nothing to do with the db connection. Either the file does not not exist at all or it is not in the same folder as your script. You need to specify the correct path. The second error is because output was sent by the first error message and headers can only be sent before any output is sent to the browser.
×
×
  • 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.