Jump to content

btherl

Staff Alumni
  • Posts

    3,893
  • Joined

  • Last visited

Everything posted by btherl

  1. Try sending another \r\n after the headers.
  2. If your mail software allows it, you can encode the recipient's email address in the return address. Then when the bounce arrives you know where it was sent because if the address it was returned to. The encoding can be a mapping of ids stored in a database, for example.
  3. Does another simpler query work? Such as one with no condition on Admin_Level? If yes then you can be confident that your PDO usage is correct, and focus on the query itself.
  4. Make sure you clear $image between each check, if there's a possibility that there is no data in the db for specific coordinates.
  5. The code is simpler if you use multiple queries. First make a function: get_subcats($parent) { $query = "SELECT * FROM cats WHERE parent = '" . mysql_real_escape_string($parent) . "'"; $result = mysql_query($query) or die("Error in $query: " . mysql_error()); while ($var = mysql_fetch_array($result)) { echo $var['name']; get_subcats($var['id']); } } I'm assuming your parent column is an id number. Also the exact code depends on what value your top level nodes have for the parent column - is this null, 0 or some other value?
  6. It would look like this: $last_tile_size = null; while ($r = mysql_fetch_array($sql)) { # New code if ($last_tile_size === null || $last_tile_size != $r['Size']) { echo "<h4>Welcome to tile size {$r['Size']}!</h4>"; } $last_tile_size = $r['Size']; # Existing code goes here } This will print a header before the data for the first tile (which is why it checks for null), and for any tile where the previous tile was a different size.
  7. Yep you're very close there. The problem now is the middle query returns 4 columns, but the outer query asks for only one. SELECT * FROM Exceptions WHERE id NOT IN ( SELECT id FROM Exceptions WHERE (cal_id, date, created) IN ( SELECT cal_id, date, MAX(created) FROM Exceptions GROUP BY cal_id, date)) The first select wants to see 1 column come from the second select, and the second wants to see 3 columns from the third select. Algorithmically, this query is doing this: 1. Find the highest (most recent) created column value for each cal_id and date combination 2. Look up the unique ids for each cal_id, date and MAX(created) combination 3. Select all data except for those unique ids (this step can then be changed to delete, once you've verified the results are correct).
  8. Let me have another go at that, having read mjdamato's post. He's fixed the logic as well as the syntax: <?php elseif (!preg_match('~^[a-z0-9.-]+\.(com|org|net|edu|co.uk)~i', $Website) || ($Website == '' && $Tickbox == "True")) { die("<div class=\"form\">You completed the website field incorrectly, please try again</div>"); } ?>
  9. There's a few problems there: <?php elseif ($Website == '' or (!preg_match("~^[a-z0-9.-]+\.(com|org|net|edu|co.uk)~i", $Website))) or $Tickbox == ("!True"); { die("<div class=\"form\">You completed the website field incorrectly, please try again</div>"); } ?> First is you should be using "||" instead of "or", unless you have a good reason to use "or" and know why you're using it. Second is your brackets are not matching, and that's what's causing the error. Third is you have a ";" at the end of the first line - this should be removed. Fourth is you should use single quotes around the regex in preg_replace(), otherwise you'll match more than you expect. The reason is the "\." will get rewritten to just ".", which matches any charater at all, not just a dot. <?php elseif ($Website == '' || (!preg_match('~^[a-z0-9.-]+\.(com|org|net|edu|co.uk)~i', $Website)) || $Tickbox == "!True"); { die("<div class=\"form\">You completed the website field incorrectly, please try again</div>"); } ?>
  10. You can have your script remember the size of the last tile, and only print a header when the size changes, or if it's the first tile. I assume you would want to order the results by size as well in your SQL.
  11. It should look like this: $d = str_replace("%STATEINSERT%", $stateinsert, $d); $d = str_replace("%CITYINSERT%", $cityinsert, $d); echo $d; You can add as many of the str_replace() lines as you want.
  12. You can do this: SELECT id, cal_id, date, created FROM Exceptions WHERE (cal_id, date, created) IN (SELECT cal_id, date, MAX(created) FROM Exceptions GROUP BY cal_id, date) The problem with adding the id directly is that MySQL will give you a randomly selected id instead of the one with the most recent created time. This is a "feature" of MySQL that often causes even more trouble. But this query will do the grouping first and THEN fetch the matching id numbers, and that will work. But none of this will work if you expect to have rows with the same cal_id, same date and same created time. Is that possible? And in that case would you choose the entry with the highest id number?
  13. jcbones explained it well. If both scripts are on the same server you could consider using sessions or include() instead of file_get_contents(). Sessions allow you to share data between scripts, and include() will allow leftcopy.php to access the variables you have set in your script. The reason is that include() runs in the same copy of php, but file_get_contents() starts a new copy of php to run leftcopy.php in, and it doesn't know about the variables you set.
  14. How did you end up with an id number on the keep_me table? The keep_me table only has date, cal_id and created. If you try to modify the query to store the id number as well it won't work. THere's a few options for the temporary table. You can create it when you need it and delete it afterwards. Or you can leave it around, and clear the contents (DELETE FROM keep_me) when you are finished with it.
  15. $d = str_replace("%STATEINSERT%", $stateinsert, $d); And then in your external html you would use %STATEINSERT% instead of <?php echo $stateinsert; ?>
  16. Ok, instead you can use a temporary table: CREATE TABLE keep_me AS SELECT DATE, cal_id, MAX( created ) FROM Exceptions GROUP BY DATE, cal_id DELETE FROM Exceptions WHERE (date, cal_id, created) NOT IN (SELECT date, cal_id, max FROM keep_me) There's a race condition here - if new entries are created between these two queries then those new entries could get deleted. So if that's a possibility you should lock the table first.
  17. The right approach depends on what you are doing. Are you trying to display the entire category tree in a single page? If so you will need recursion. A good start would be to write a function called "get_subcats($id)" which recursively calls itself to get subcats of subcats.
  18. Those echo statements will be executed on the external page, not in your script. So all the echoed variables are blank when the echo executes. Instead you might want to make them placeholders like "%STATEINSERT%" and do a str_replace() on $d after file_get_contents().
  19. Step 1 - Find which records to keep SELECT date, group, MAX(created) FROM table GROUP BY date, group Step 2 - Delete all records which are not being kept DELETE FROM table WHERE (date, group, created) NOT IN (SELECT date, group, MAX(created) FROM table GROUP BY date, group) This is untested - first run the query as a select instead of a delete to make sure it's getting the right rows. Sorry that this isn't a php solution - for me it's easier to express in SQL.
  20. That looks like the same column indexed by both name and number. If you refer to it by name consistently you should have no problems.
  21. It's certainly possible. But I don't know the details of how. The general concept is called AJAX, and specifically it sounds like you want Flash to make a request back to your php script.
  22. Arrays are indexed from 0 by default, making your array indexed from 0 - 6, but date('N') returns a number in the range 1-7. <?php $dayNames = array("Nedelja", "Ponedeljak", "Utorak", "Srijeda", "Četvrtak", "Petak", "Subota"); $dan = $dayNames[date('N')-1]; # <-- Subtract 1 from the result of date('N') echo $dan.", ".date('d.m.Y.') ; ?> Edit: Sorry, you may need to re-order your array to make that work. The "Subota" will need to go to the start, everything else would be in the same position.
  23. You can create anonymous functions (aka lambda functions) with create_function(). These are often used as sorting callbacks, and can be passed around to other functions.
  24. The problem is that ".+" will match anything, including the date string. If you make the date string optional, the ".+" will eat up the date string, because it knows it doesn't need the date string in order to match the expression. One possible solution is to use two regexp, one with a compulsory date and a second one with no date. First you try to match the full expression with compulsory date string. If that fails, then try matching without the date string.
  25. Do you have a login page where users log in to your site?
×
×
  • 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.