Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Yes, you are, but only if $_GET['id'] is set
  2. It also works if you change them individually $xml = new SimpleXMLElement($_xml_string); $xml->EmbeddedDoc[0] = '##FILE##' ; $xml->EmbeddedDoc[1] = '##FILE##' ; $newxml = $xml->asXML(); echo '<pre>' . htmlentities($newxml) . '<pre>';
  3. 1. Store selected language in a session variable and use the "selected" attribute to select the stored language 2. Use <optgroup> to group the subcats into categories session_start(); if (isset($_GET['lang'])) { $_SESSION['lang'] = $_GET['lang']; // store newly selected lang } if (!isset($_SESSION['lang'])) { $_SESSION['lang'] = 'Esp'; // set default if not yet set } // LANGUAGE OPTIONS $langs = array( "Esp" => "Espanyol", "Eng" => "English", "Cat" => "Catalan", "Bas" => "Euskal", "Gal" => "Galego", ); $langOpts = ''; foreach ($langs as $k => $l) { $sel = ($k == $_SESSION['lang']) ? 'selected="selected"' : ''; $langOpts .= "<option value='$k' $sel> $l</option>\n"; } // CATEGORY OPTIONS $cats = array ( "A" => array ("b", "c"), "D" => array ("e", "f") ); $catOpts = ''; foreach ($cats as $c => $subs) { $catOpts .= "<optgroup label='$c'>\n"; foreach ($subs as $sc) { $catOpts .= "<option value='$sc'> $sc</option>\n"; #$catOpts .= "<option value='$sc'> $sc</option>\n"; } $catOpts .= "</optgroup>\n"; } ?> <html> <head> <style type="text/css"> option.subcat { padding-left: 25px; } </style> </head> </html> <form> Language <select name="lang" onchange="javascript:change_langs(this.form)"> <?= $langOpts ?> </select> <br> Category <select name="category"> <option value=''>Select ...</option> <?= $catOpts ?> </select> <input type="submit" name="btnSub" value="Submit"> </form>
  4. start values again mysql> SELECT * FROM city; +----+------+------+------------+ | id | xpos | ypos | cityname | +----+------+------+------------+ | 1 | 40 | 60 | Manchester | | 2 | 80 | 60 | Leeds | | 3 | 90 | 160 | Leicester | +----+------+------+------------+ Now this code, where id=2 and ypos left blank $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); if (isset($_POST['id'])) { $id = $_POST['id']; // 2 $ypos = empty($_POST['ypos']) ? null : $_POST['ypos']; // empty $sql = "UPDATE city SET ypos = ? WHERE id = ?"; $stmt = $db->prepare($sql); $stmt->bind_param('ii', $ypos, $id); $stmt->execute(); } Tables values after running code mysql> SELECT * FROM city; +----+------+------+------------+ | id | xpos | ypos | cityname | +----+------+------+------------+ | 1 | 40 | 60 | Manchester | | 2 | 80 | NULL | Leeds | | 3 | 90 | 160 | Leicester | +----+------+------+------------+
  5. Doh! So it is. As it works, what was your problem then?
  6. Example: mysql> SELECT * FROM city; +----+------+------+------------+ | id | xpos | ypos | cityname | +----+------+------+------------+ | 1 | 40 | 60 | Manchester | | 2 | 80 | 60 | Leeds | | 3 | 90 | 160 | Leicester | +----+------+------+------------+ mysql> UPDATE city SET cityname=NULL WHERE id = 2; mysql> SELECT * FROM city; +----+------+------+------------+ | id | xpos | ypos | cityname | +----+------+------+------------+ | 1 | 40 | 60 | Manchester | | 2 | 80 | 60 | NULL | | 3 | 90 | 160 | Leicester | +----+------+------+------------+
  7. or <?php $str = "/index.php?g1=111&g2=222&g3=333"; $bits = parse_url($str); parse_str($bits['query'], $vals); echo '<pre>',print_r($vals, true),'</pre>'; ?> gives Array ( [g1] => 111 [g2] => 222 [g3] => 333 )
  8. I do not know if it works with PDO but prepared statements with MySQLi will write NULL to a field if the bound parameter has a null value
  9. If you are going to normalize as ginerjm recommended then do it properly and not have multiple values in a single field. "AuthorA2000a" is 3 separate fields viz. | Name | Year | Sequence | You would store publications in separate table from the Author table and store the authorID as a foreign key author +----------+-------------------+ | authorID | name | +----------+-------------------+ | 1 | AuthorA | | 2 | AuthorB | +----------+-------------------+ | | +-------------------------------------+ | publication | +---------+-------+----------+------------+ | pubID | year | authorID | pubname | +---------+-------+----------+------------+ | 1 | 2000 | 1 | pub 1 | | 2 | 2000 | 1 | pub 2 | | 3 | 2001 | 1 | pub 3 | | 4 | 2000 | 2 | pub 4 | | 5 | 2001 | 2 | pub 5 | | 6 | 2002 | 2 | pub 6 | | 7 | 2002 | 2 | pub 7 | +---------+-------+----------+------------+
  10. ginerjm's code relies on your having an array of filenames ($files_ar), which he didn't show. This could be hard-coded as in my example below or you could read the list into an array from a text file. <?php $files_ar = array ( 1 => 'Lesson1.html', 'Lesson2.html', 'Lesson3.html', 'Lesson4.html', 'Lesson5.html', ); if (isset($_GET['file']) && $_GET['file']<>'') { $file = strtolower($_GET['file']); if (array_key_exists($file,$files_ar)) $include_name = $files_ar[$file]; else die("Invalid url value"); include('header.php'); include($include_name); include('footer.php'); exit(); } else die("Missing url value"); exit(); ?> You would then call the page with thissite.com/index.php?file=1 etc
  11. Use "=" instead of "LIKE" WHERE registration = '$searchq'
  12. What about the firefox array and the others that do not work? If you have a 30 element array then array_slice($array, 5, -24) leaves a single element $a = range(1,30); $array = array_slice($a, 5, -24, 1); echo '<pre>',print_r($array, true),'</pre>'; /* results ************** Array ( [5] => 6 ) ****************************/ So if that 1 element doesn't contain what you are looking for then it won't work. Why use array_slice() here anyway?
  13. SELECT .... FROM tablename WHERE datetimefield > NOW() - INTERVAL 24 HOUR SELECT .... FROM tablename WHERE datetimefield > NOW() - INTERVAL 7 DAY SELECT .... FROM tablename WHERE datetimefield > NOW() - INTERVAL 1 MONTH SELECT .... FROM tablename WHERE datetimefield > NOW() - INTERVAL 12 HOUR
  14. Can you show us the output from print_r($array) I'd do it myself but array_slice won't work on the images you so thoughtfully provided
  15. That is the reason we use forms rather then one big text area; so the order and type of information can be controlled.
  16. We used to have a PC filter where I worked, so messages containing words like "tart" or "Scunthorpe" (town in UK) were flagged for moderation. The recipient was notified they had received a message with banned content and, after reviewing, an administrator might, or not, release the message.
  17. As soon you see the words "For simplicity..." then you know this isn't a copy of the actual code being executed. Spending any time on what is posted is, therefore, just a waste of effort. Just my 0.02 worth.
  18. CAUTION when add time periods to dates at the end of the month $dateToUse = '2015-01-31'; $plus1month = date('Y-m-d', strtotime("$dateToUse +1 months")); echo $plus1month; //--> 2015-03-03 !!! [edit] I don't know how sqlserver handles it but MySQL gives a more natural result mysql> SELECT '2015-01-30' + INTERVAL 1 MONTH; +---------------------------------+ | '2015-01-31' + INTERVAL 1 MONTH | +---------------------------------+ | 2015-02-28 | +---------------------------------+
  19. I'm going to pass on that because when I run your code to build the array I get <select name="birthyear" class="date"> <option value="-2">Please choose</option> <option value="-1">N/A</option> <option value="1997">1997</option> <option value="1996">1996</option> <option value="1995">1995</option> <option value="1994">1994</option> <option value="1993">1993</option> <option value="1992">1992</option> <option value="1991">1991</option> <option value="1990">1990</option> <option value="1989">1989</option> <option value="1988">1988</option> <option value="1987">1987</option> <option value="1986">1986</option> <option value="1985">1985</option> <option value="1984">1984</option> <option value="1983">1983</option> <option value="1982">1982</option> <option value="1981">1981</option> <option value="1980">1980</option> <option value="1979">1979</option> <option value="1978">1978</option> <option value="1977">1977</option> <option value="1976">1976</option> <option value="1975">1975</option> <option value="1974">1974</option> <option value="1973">1973</option> <option value="1972">1972</option> <option value="1971">1971</option> <option value="1970">1970</option> <option value="1969">1969</option> <option value="1968">1968</option> <option value="1967">1967</option> <option value="1966">1966</option> <option value="1965">1965</option> <option value="1964">1964</option> <option value="1963">1963</option> <option value="1962">1962</option> <option value="1961">1961</option> <option value="1960">1960</option> <option value="1959">1959</option> <option value="1958">1958</option> <option value="1957">1957</option> <option value="1956">1956</option> <option value="1955">1955</option> <option value="1954">1954</option> <option value="1953">1953</option> <option value="1952">1952</option> <option value="1951">1951</option> <option value="1950">1950</option> <option value="1949">1949</option> <option value="1948">1948</option> <option value="1947">1947</option> <option value="1946">1946</option> <option value="1945">1945</option> <option value="1944">1944</option> <option value="1943">1943</option> <option value="1942">1942</option> <option value="1941">1941</option> </select> The code I used <?php define("_VARS_USER_CHOOSE_", -2); define("_VARS_USER_NONE_", -1); define("_VARS_USER_UNDEF_", 'N/A'); $vars['user-birthdate-years'] = array(_VARS_USER_CHOOSE_ => "Please choose", _VARS_USER_NONE_ => _VARS_USER_UNDEF_); for ($i = date('Y') - 18; $i > date('Y') - 75; --$i) { $vars['user-birthdate-years'][$i] = "$i"; } $opts = ''; foreach ($vars['user-birthdate-years'] as $k=>$yr) { $opts .= "<option value='$k'>$yr</option>\n"; } ?> <select name="birthyear" class="date"> <?=$opts?> </select>
  20. When you write to your JS in PHP (on the server) you write whatever is in $year and $balance at the time. Later (on the client) the JS loops using those single values. You need an array of years and values. I would use AJAX from your JS to get a JSON array and then use that for the chart. BTW, I am getting many errors flagged regarding incorrect nesting of tags EG <p>Would you like to see the calculations? <a href="#" class="show_hide" rel="#slidingDiv"> Show Me</span></p> </a>
  21. What happened to the code tags?
  22. Show us the whole code, not isolated snippets, so we can see the logic flow. Use code tags or the <> button in the toolbar
  23. Example of the above mysql> SELECT * FROM rate; +---------+------------+------------+--------+--------+-----------+ | rate_id | from_date | to_date | season | rate | wepremium | +---------+------------+------------+--------+--------+-----------+ | 1 | 2016-01-08 | 2016-02-28 | LOW | 100.00 | 25.00 | | 2 | 2016-02-29 | 2016-03-20 | MID | 110.00 | 25.00 | | 3 | 2016-03-21 | 2016-04-10 | EASTER | 150.00 | 50.00 | +---------+------------+------------+--------+--------+-----------+ mysql> SELECT * FROM booking_days; +------------+------------+ | booking_id | date | +------------+------------+ | 1234 | 2016-02-27 | | 1234 | 2016-02-28 | | 1234 | 2016-02-29 | | 1234 | 2016-03-01 | | 1234 | 2016-03-02 | | 1234 | 2016-03-03 | | 1234 | 2016-03-04 | | 1235 | 2016-03-19 | | 1235 | 2016-03-20 | | 1235 | 2016-03-21 | | 1235 | 2016-03-22 | | 1235 | 2016-03-23 | +------------+------------+ SELECT booking_id , DATE_FORMAT(date, '%a %D %b %Y') as date , season , SUM(r.rate + CASE WHEN DAYOFWEEK(b.date) IN (1,6,7) THEN r.wepremium ELSE 0 END) as price FROM booking_days b JOIN rate r ON b.date BETWEEN r.from_date and r.to_date GROUP BY booking_id, date WITH ROLLUP; +------------+-------------------+--------+---------+ | booking_id | date | season | price | +------------+-------------------+--------+---------+ | 1234 | Sat 27th Feb 2016 | LOW | 125.00 | | 1234 | Sun 28th Feb 2016 | LOW | 125.00 | | 1234 | Mon 29th Feb 2016 | MID | 110.00 | | 1234 | Tue 1st Mar 2016 | MID | 110.00 | | 1234 | Wed 2nd Mar 2016 | MID | 110.00 | | 1234 | Thu 3rd Mar 2016 | MID | 110.00 | | 1234 | Fri 4th Mar 2016 | MID | 135.00 | +------------+-------------------+--------+---------+ | 1234 | 825.00 | +------------+-------------------+--------+---------+ | 1235 | Sat 19th Mar 2016 | MID | 135.00 | | 1235 | Sun 20th Mar 2016 | MID | 135.00 | | 1235 | Mon 21st Mar 2016 | EASTER | 150.00 | | 1235 | Tue 22nd Mar 2016 | EASTER | 150.00 | | 1235 | Wed 23rd Mar 2016 | EASTER | 150.00 | +------------+-------------------+--------+---------+ | 1235 | 720.00 | +------------+-------------------+--------+---------+ | TOTAL | 1545.00 | +------------+-------------------+--------+---------+
  24. I'd have a single table with contiguous dates and also include a column for midweek price and another for the additional weekend premium. Also, when making a booking I would generate a booking record for each day of the stay. Then it's easy to "JOIN ON booking.date BETWEEN price.startdate AND price.enddate" and pick up the rate, applying the premium for dates that fall on weekend
  25. What happens for those days that fall between the dates in your season table, the date bands are not contiguous?
×
×
  • 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.