Jump to content

trq

Staff Alumni
  • Posts

    30,999
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by trq

  1. The only way (I know of) to achieve this within your database would be to use a better database design in the first place.
  2. Images and Javascript need to be referenced relative to the url they are called from. These are not filesystem paths like what PHP uses, but urls. Placing directories or files on your include_path means that you can access them without the complete path. eg; You may have a file at: /usr/share/php/foo.php Now, if /usr/share/php is on your include path you only ever need to use: include 'foo.php'; to get this file. This makes things even easier when your using OOP and PHP's auto loading capabilities. See __autoload & spl_autoload.
  3. This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=342824.0
  4. They are random enough to not make sense. 1) To pass an array to a method is no different to any other variable. eg; function foo($arr) { foreach ($arr as $val) { echo $val; } } foo(array('a', 'b', 'c')); // or $a = array('a', 'b', 'c'); foo($a); 2) Functions (or methods within a class) have there own scope. Variables created outside of functions do not exist within a function. Same goes for classes. This is why the features are useful. 3) I missed in your code.
  5. Your code doesn't make allot of sense. Your __construct expects a single argument, you pass it 3. From there, you don't actually use any of the arguments within the __construct. Your acceleration() method then goes on to try and echo a variable ($distance) which has not been defined and also tries to access indexes within the $this->speed array which don't appear to have been set anywhere within any code you have posted.
  6. Firstly, why are you storing comma separated data in a database? This would be allot simpler if your data was normalised. Anyway, implode your string into arrays then use array_interest.
  7. Are you asking how to pass an array to a function? It's no different to passing any other variable.
  8. Nope. You might have better luck finding a database of postcodes.
  9. trq

    Array Help

    That wasn't necessary and also not the issue.
  10. I should probably post an example: $sql = " SELECT category, COUNT(category) AS cnt, name FROM postlisting LEFT JOIN categories ON (postlisting.category = categories.id) GROUP BY category "; This assumes a new categories table that holds both an id (relating to postlisting) and a name.
  11. I would seriously consider creating a categories table then simply joining on that to get your category names. It would be simple, easier to add new categories and practically zero overhead on your query.
  12. Any data outside of the web server root can not be accessed via the web. Hell, you can even place passwords etc etc inside a php script within the web root and they can't be read unless your script echoing the variables back to the client. This can fall over however if somehow your server becomes misconfigured and starts server php as plain text. All files and directories only need to be read by the web server. Of course, you yourself may need write access to be able to edit the application though this should really be done on a separate dev server and then your application installed into production. Keep in mind that some directories may also need to be writable by the web server if you wish users to be able to upload files etc etc. Most of what I'm covering here is probably a bit over the top for general web sites, and allot of hosts won't even grant you the ability to do allot of what I've mentioned, but I figure your asking the questions so.....
  13. I haven't looked at the code but put simply you would need to insert the required data into the database query.
  14. You can use jsonp if the api provides it. The one your using doesn't appear to.
  15. Any suggestions? You haven't exactly asked a question. Where are you stuck?
  16. From memory this was only ever a netscape issue anyway, so unless your users really are dinosaurs I wouldn't bother.
  17. I think your still misunderstanding what the web root is. My typical structure is (simplified) something like: [pre] project htdocs assets js css imgs .htaccess index.php lib MyFramework [/pre] Where the htdocs directory is configured to be my web servers document root. My framework would then sit within a lib directory completely outside of a position where it is at all accessible via the web. In fact my framework will most often sit in /usr/share/php or some other globally accesible location and I will just add it to my include_path in order to use it. Point being, your php code does not need to be within your web root (only the index.php file which bootstraps the application). That's not to say you have to do it this way, and in fact most people don't or can't because they simply do not have the ability to do so because of there hosting.
  18. This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=342739.0
  19. trq

    Array Help

    function filter_words($text, $data) { foreach($data->words->word as $w) { $text = str_replace(strtolower($w), '[!]', strtolower($text)); } return strtoupper($text); }
  20. $sql = "SELECT category, COUNT(category) AS cnt FROM postlisting GROUP BY category"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { echo "There are {$row['cnt']} items in {$row['category']}<br />"; } } }
  21. Sorry, but that is probably some of the worst code I have ever seen. You can use one query and simply GROUP BY category.
  22. There is only a single call to mail() in the code you have posted.
  23. trq

    Array Help

    Put return after the loop.
  24. trq

    Array Help

    return exits a function when it is executed, so your loop will only execute once, then exit.
  25. This is not a coding issue but a configuration issue. I would speak to whomever maintains the mail server.
×
×
  • 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.