Jump to content

btherl

Staff Alumni
  • Posts

    3,893
  • Joined

  • Last visited

Everything posted by btherl

  1. http://geography.about.com/cs/daylightsavings/a/dst.htm The issue is that not all days have 24 hours in a timezone with daylight savings. Some have 23 and some have 25. So you can't rely on adding 24 hours to get to the next day.
  2. Yes you would create a new table. Each table is for one type of "thing". Table "comments" stores comments, table "pages" stores pages. Other common tables would be "users" to store users and "orders" to store orders (for online transactions). Each table has just one auto_increment id, and that id number uniquely identifies a row in that table. You might want to do a tutorial on MySQL before continuing with the site you're making now.
  3. I doubt you'll see any significant difference, unless it's a very large table, and fld1 and fld2 can be fetched in some faster way such as from an index. So the short answer is in most cases, there's no significant difference. If you want to benchmark them, I would run each query at least 1000 times and measure the total time, using php's microtime(). You might want to run each query once before you benchmark, to make sure everything is cached for both runs. And if you're serious about optimizing queries, you would want to learn about and use "EXPLAIN": http://dev.mysql.com/doc/refman/5.0/en/explain.html
  4. The page id is something that you make up yourself. Or you let the database make it for you. The number itself is meaningless, as long as there's one id for each page and it never changes. Usually with mysql you use this feature: http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html That will create a unique id for each item you add to the table. So you would create the page table with an auto increment id column, and then insert each page into the table. You would end up with something like this: id name 1 main 2 national news 3 local news If you then added another entry "sports news", mysql will assign id number 4 to it. The next entry will get id number 5.
  5. If you're going to have a comment system with comments on each pages, I would have a structure like this: Table pages: Column id Column name And any other columns you might want. You could put columns for access control (such as "only admin can view this page") in here if you wanted. For a CMS you could store who is allowed to edit the page. And so on. But for static pages just id and name is enough. Table comments Column id (this is the comment id) Column page_id (this links each comment to a specific page) Column full_name (don't call this "message", it'll be confusing) Column message (This column is what you called "message2" before) Good naming of columns is important, or you'll regret it later Now all you have to do to link to the page is look at the page id when you get the most recent 5 comments. And you might need to look up the page name from the page id as well, which can be done from the pages table.
  6. How do you know (from your database) which page a comment was made on? The same information tells you which page to link to. I'm wondering if your comments table is supposed to have another column to say which page that comment is for?
  7. Yes, replacing '\s+' with ' ' will convert any number of whitespace (which includes spaces and some other characters) with one space, which is usually good enough. ' +' will match spaces only.
  8. Good to hear that mwobobia, please start a new thread for your question, and say what part of it is not working.
  9. if($selectalbum3[tweet] == "0" && $selectalbum3[lasttw] >= '$timeondd') Instead of this, try: if($selectalbum3[tweet] == "0" && $selectalbum3[lasttw] >= $timeondd)
  10. What I mean is like this: $sql = "UPDATE advert Set ad_Type = ' Fill Wanted ' WHERE id = 78 "; Can you please also post the code you use to execute the query, and the table definition.
  11. That code looks ok to me. What happens if you set just one column?
  12. It probably means "If we were given a callback, call the callback on $i before inserting it into the html, otherwise insert $i directly". It's allowing the use of a callback as a kind of filter for data going into the HTML. So if $callback is set to a function name it calls that function on $i. Otherwise it just uses $i.
  13. Do you need to remove triple spaces as well? Because that code will only remove double spaces. If the last line is specifically to replace spaces with commas you can use str_replace() instead.
  14. You can use the value in $_SERVER['HTTP_USER_AGENT']. And google for "mobile user agent detection"
  15. I think QuickOldCar meant this: if ( !$r) About those messages you're seeing, those are harmless - they say that the "?op=reg" was not present when your script looked for it. It's saying it can't find index "op" in the $_GET array. This is one of the most annoying and unnecessary "notices" in php, and never should have been included in E_ALL.
  16. The short answer is that you can't tell. Otherwise spammers would abuse this to find valid email addresses. You can check if an email looks valid, and you can try sending an email to that address and see what happens. If you really need valid email addresses, send an activation email with a unique link and ask the owner to follow the link.
  17. I'm guessing you installed a php4 dll but your php is version 5. See if you can find a php_mbstring.dll matching the version of php you have installed.
  18. If you store a timestamp (mysql datetime data type, I believe) for each entry, and create an index on that column, then you can do a query like this: SELECT * FROM posts ORDER BY created_timestamp DESC LIMIT 10 The index will allow Mysql to find the entries quickly.
  19. I would try removing your input filter. It appears to strip "low" and "high" characters, which probably form part of your windows-1256 character set. In general you should perform encoding on output. You should do mysql encoding if storing to a mysql database, and HTML encoding if displaying on an HTML page. mysql_real_escape_string() and htmlspecialchars() are common functions to do those.
  20. btherl

    php poll

    I think you need poll2.php as the action of the form in poll.php. And check that the name of the input element is the name you are looking for in $_REQUEST, which in this case is "album", not "vote".
  21. Is it because $field->name is deallocated after the reference is created? Therefore reverting $parameters[] to a normal variable with refcount 0. Sample script to demonstrate: <?php $foo[0] = 1; $bar[0] = &$foo[0]; var_dump($bar); unset($foo); var_dump($bar); ?> Once $foo is deallocated, $bar[0] is no longer a reference, even though it was previously made to be a reference. Definitely not what I would expect, and another reason to avoid references unless you really need them (and you do need them here it seems). The mistake though was referencing something that doesn't really belong to you - $field->name isn't really yours. If you only reference variables you created and you know the history and future use of, then all should be fine.
  22. btherl

    php poll

    One of those is a cats/dogs poll and the other is a yes/no poll. How do you want them to communicate?
  23. Please post your code, and explain how you are checking that the form sends empty characters.
  24. I also don't understand why this happens. Can you do a var_dump() of $parameters before it's passed to bind_result()? If it says they're not references then presumably they're not references, and perhaps php wasn't able to make them references.
  25. I also can't think of any situation where I'd use a reference within a data structure. It would drive me crazy debugging, even if it is useful. Another example of memory saving with references in php's "standard library" is mysql_fetch_array(), which creates the integer and named indexes as references to the same data. So even though the data appears twice when you dump the contents, it is only stored once.
×
×
  • 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.