Jump to content

Barand

Moderators
  • Posts

    24,602
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. Use a for() loop to create the table body. It's much easier. <?php $today = date("Y-m-d"); for ($i=1; $i<=24; $i++) { echo <<<ROW <tr> <td>$i</td> <td> <input type="text" name="installment[$i]" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date[$i]" class="tcal span4" value="$today" /> </td> </tr>\n ROW; } ?> Note the names of the input fields name="installment[$i]" name="due_date[$i]" This will post the data in an array which can, again, be easily processed in a loop. foreach ($_POST['installment'] as $k => $amount) { $date = $_POST['due_date'][$k]; // insert $amount and $date into table }
  2. The whole point of using SESSION variables is so that the values persist from page to page.
  3. There are several weather api's out there where you can get a weather feed for free, for example http://www.worldweatheronline.com/free-weather.aspx All you need to do is parse the returned data (usually xml or json) and display the appropriate image according to the weather description.
  4. I thought that was your intention.
  5. Sounds more like a Photoshop problem than a PHP one.
  6. You could parse the XML and create the SQL CREATE TABLE queries. Something like this will do it <?php $xml = simplexml_load_file('db.xml'); // use your xml file name here $sql = ""; foreach ($xml->TABLES->TABLE as $t) { $sql .= "CREATE TABLE `{$t['NAME']}` (\n"; foreach ($t->FIELDS->FIELD as $f) { $sql .= "`{$f['NAME']}` "; switch ($f['TYPE']) { case 'int': $sql .= "INT({$f['LENGTH']}) "; break; case 'char': $sql .= "VARCHAR({$f['LENGTH']}) "; break; case 'number': $sql .= "FLOAT(8,4) " ; break; case 'text': $sql .= "TEXT " ; break; } if ($f['UNSIGNED']=='true') { $sql .= "UNSIGNED "; } if ($f['NOTNULL']=='true') { $sql .= "NOT NULL "; } if ($f['SEQUENCE']=='true') { $sql .= "AUTO_INCREMENT "; } else { if ($f['NOTNULL']=='true') { $sql .= "DEFAULT 0 "; } } $sql .= ",\n"; } $sql .= "PRIMARY KEY ({$t->KEYS->KEY['FIELDS']}),\n"; $idx = $t->INDEXES->INDEX; $sql .= "INDEX "; if ($idx['UNIQUE']=='true') { $sql .= "UNIQUE "; } $sql .= "{$idx['NAME']} ({$idx['FIELDS']})\n"; $sql .= ");\n\n"; } ?> <html> <head> <title>XML to SQL sample</title> </head> <body> <pre> <?=$sql?> </pre> </body> </html>
  7. Why the "GROUP BY id"? Don't you mean "ORDER BY id"? Do you want to try recalculating those start record numbers? first 10: 0 - 9 next 10: 10 - 19 next 10: 20 - 29
  8. It looks like you are trying to nest the "selects". I don't see "</select>" after the first set of options and before the next <select>
  9. ???
  10. Having got the array (say, $all_images) of ipg names using glob() you can use array_slice() to get the 30 images. images for page $p would be $images = array_slice($all_images, ($p-1)*30, 30);
  11. Don't ignore the date change, check for it $time1 = new DateTime('22:00'); $time2 = new DateTime('03:00'); $current_time = new DateTime('04:00'); if ($time2 < $time1) { $time1->sub(new DateInterval('P1D')); } if ($current_time > $time1 && $current_time < $time2) { echo "Between"; } else { echo "Outside"; }
  12. My apologies for my shortcomings in the psychic telepathy department
  13. Barand

    SQL query

    I wouldn't. There is no postcode.
  14. Use a single query with JOINs, then you only need a single loop to process the results SELECT a.AreaName , r.responseDate , q.QuestionName , r.userResponse FROM Area a INNER JOIN Question q ON a.idArea = q.fkArea LEFT JOIN Responses r ON q.idQuestion = r.fkQuestion ORDER BY a.AreaName, r.reponseDate, q.QuestionName I used a LEFT JOIN on reponses in case there are questions with no responses.
  15. ... plus the precise error messages
  16. Looks like you missed a comma before "true"
  17. you could save a lot of coding by using arrays. This is just the traditional "scissors,paper,stone" version but you can extend the arrays to include your lizard and spock(???) <?php session_start(); if (!isset($_SESSION['results'])) { $_SESSION['results'] = array( 'Win' => 0, 'Draw' => 0, 'Lose' => 0 ); } $choices = array (1 => 'rock', 'paper', 'scissors'); $outcomes = array ( 'rock' => array ( 'rock' => array ('Draw', ''), 'paper' => array('Lose', 'covered by'), 'scissors' => array('Win', 'blunts') ), 'paper' => array ( 'rock' => array ('Win', 'covers'), 'paper' => array('Draw', ''), 'scissors' => array('Lose', 'cut by') ), 'scissors' => array ( 'rock' => array ('Lose', 'blunted by'), 'paper' => array('Win', 'cuts'), 'scissors' => array('Draw', '') ) ); if (isset($_GET['human'])) { $human = $choices[$_GET['human']]; $computer = $choices[rand(1,3)]; $outcome = $outcomes[$human][$computer]; $_SESSION['results'][$outcome[0]]++; } ?> <html> <head> <title>Scis-Pap-Brick</title> <style type='text/css'> table { /*border-collapse: collapse;*/ width: 400px } th { background-color: #369; color: white; } td { text-align: center; width: 33% } </style> </head> <body> <?php if (isset($_GET['human'])) { ?> <table border='0' cellspacing='1'> <tr> <th>You</th> <td> </td> <th>Computer</th> </tr> <tr> <td><?=$human?></td> <td><?=$outcome[1]?></td> <td><?=$computer?></td> </tr> <tr> <td colspan='3'> </td> </tr> <tr> <td colspan='3'><?="This time you {$outcome[0]}"?></td> </tr> <tr> <?php foreach($_SESSION['results'] as $c=>$r) echo "<th>$c</th>"; ?> </tr> <tr> <?php foreach($_SESSION['results'] as $r) echo "<td>$r</td>"; ?> </tr> </table> <?php } ?> <h3>Choose</h3> <form> <table border='0' cellspacing='1'> <tr> <?php foreach($choices as $k=>$c) echo "<th>$c</th>"; ?> </tr> <tr> <?php foreach($choices as $k=>$c) echo "<td><input type='radio' name='human' value='$k'></td>"; ?> </tr> <tr> <td colspan='3'><br><input type='submit' name='tbnSub' value='Play'></td> </tr> </table> </form> </body> </html>
  18. LeJack, Will you please explain why I get the same results with these two sets of code if it can't be done $db = mysqli_connect(HOST,USERNAME,PASSWORD,DATABASE); $res = $db->query("SELECT COUNT(*) FROM votes"); list($count) = $res->fetch_row(); echo $count; // 182685 $db2 = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); $res = mysqli_query($db2, "SELECT COUNT(*) FROM votes"); list($count) = mysqli_fetch_row($res); echo $count; // 182685
  19. You can. function mysqli_query($conn, $sql) { return $conn->query($sql); }
  20. If no room is specified, don't include a room condition in the WHERE clause
  21. yes <html> <head> <title>Sample</title> <style type="text/css"> .highlight { color: #fff; background-color: #888; } </style> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript"> $().ready(function() { $(".sel").change(function() { var curID = $(this).attr("id"); var chosen = $(this).val(); var curr = $(this).data('curr'); $(".sel").each(function(i,v) { if (v.id != curID) { $(v).children("option[value="+curr+"]").attr("disabled",false).removeClass("highlight"); $(v).children("option[value="+chosen+"]").attr("disabled",true).addClass("highlight"); } }) $(this).data('curr', chosen); }) $("#btnReset").click(function() { $("option").attr("disabled",false).removeClass("highlight"); this.form.reset(); }) }) </script> </head> <body> <form> <?php for ($i=0; $i<5; $i++) { echo "<select class='sel' id='sel$i' name='sel$i' data-curr='0'> <option value=''>---</option>"; for ($j=1; $j<=5; $j++) { echo "<option value='$j'>$j</option>"; } echo "</select> "; } ?> <input type='button' name='btnReset' id='btnReset' value='Reset'> </form> </body> </html>
  22. You don't really want to create that replace array manually every time <?php $str = isset($_GET['str']) ? $_GET['str'] : ''; $kw = isset($_GET['keyword']) ? $_GET['keyword'] : ''; $decode = isset($_GET['decode']) ? 1 : 0; $str2 = $str ? translate($str, $kw, $decode) : $str; function translate($str, $kw, $decode=0) { $str = strtoupper($str); $alpha = range('A','Z'); $karr = keyArray($kw, $alpha); $trans = $decode ? array_combine($karr, $alpha) : array_combine($alpha, $karr); return strtr($str,$trans); } function keyArray($keyword, &$alpha) { // create translation array from given keyword $kw = array_unique(str_split(strtoupper($keyword))); $diff = array_diff($alpha, $kw); return array_merge($kw, $diff); } ?> <html> <head> <title>Encoder</title> </head> <body> <form> Input text/Translation<br> <textarea name="str" rows="5" cols="50"><?=$str2?></textarea> <br> Keyword <input type="text" name="keyword" value="<?=$kw?>"> Decode <input type='checkbox' name='decode' value='1'> <br> <input type="submit" name="btnSub" value="Translate"> </form> </body> </html>
  23. Are you sure you posted the query that is giving that result? mysql> SELECT name -> , date_paid -> , expiry_date -> , DATEDIFF(expiry_date, date_paid) as diff -> FROM test_chidi; +------+------------+-------------+------+ | name | date_paid | expiry_date | diff | +------+------------+-------------+------+ | John | 2014-11-07 | 2014-12-01 | 24 | | Doe | 2014-11-07 | 2014-11-10 | 3 | +------+------------+-------------+------+ edit: where does next_due come from - you don't mention that in your data?
  24. Then you need to put $title, $publishdate etc into form input fields, not just in table cells
×
×
  • 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.