Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. This is not the code in which this error occurs. You are passing somewhere a function name where it expects the name of the function as a string, you prolly called it directly without the parenthesis.
  2. How would you do it otherwise? Now you just keep a table that matches a postal code to its neighbouring postal codes if you don't then how would you know how far or how close postal code 3400 lies from 3500?
  3. Wrong. It's: TRUNCATE TABLE tableName Wrong. Both ways are acceptable (give you're using MySQL) Then I'm right as the question was: delete will not entirely clear the table truncate does.
  4. So you must have a record of their starting score somewhere, right? You prolly associate (max) health with the characters level, right? Thus: CREATE TABLE levels ( levels_id SMALLINT NOT NULL AUTO_INCREMENT, levels_max_health SMALLINT, PRIMARY KEY (levels_id) ); Use the value of levels_max_health to rejuvenate it.
  5. Query: SELECT * FROM sporthalls WHERE sporthalls_postcodes_id = 3400 OR sporthalls_postcodes_id IN ( SELECT postcodes_neighbours_neighbour FROM postcodes_neighbours WHERE postcodes_neighbours_postcode = 3400 ); DB Structure: CREATE TABLE IF NOT EXISTS `postcodes` ( `postcodes_id` smallint(6) NOT NULL, PRIMARY KEY (`postcodes_id`) ); INSERT INTO `postcodes` (`postcodes_id`) VALUES (3400), (3401), (3402), (3403), (3404), (3500), (3501), (3502), (3503), (3504); CREATE TABLE IF NOT EXISTS `postcodes_neighbours` ( `postcodes_neighbours_postcode` smallint(6) NOT NULL, `postcodes_neighbours_neighbour` smallint(6) NOT NULL, PRIMARY KEY (`postcodes_neighbours_postcode`,`postcodes_neighbours_neighbour`) ); INSERT INTO `postcodes_neighbours` (`postcodes_neighbours_postcode`, `postcodes_neighbours_neighbour`) VALUES (3400, 3401), (3400, 3402), (3400, 3403), (3400, 3404), (3500, 3501), (3500, 3502), (3500, 3503), (3500, 3504); CREATE TABLE IF NOT EXISTS `sporthalls` ( `sporthalls_id` smallint(6) NOT NULL auto_increment, `sporthalls_postcodes_id` smallint(6) default NULL, `sporthalls_title` varchar(32) default NULL, PRIMARY KEY (`sporthalls_id`) ); INSERT INTO `sporthalls` (`sporthalls_id`, `sporthalls_postcodes_id`, `sporthalls_title`) VALUES (1, 3400, '#1 Location 3400'), (2, 3401, '#1 Location 3401'), (3, 3402, '#1 Location 3402'), (4, 3403, '#1 Location 3403'), (5, 3404, '#1 Location 3404'), (6, 3500, '#1 Location 3500'), (7, 3501, '#1 Location 3501'), (8, 3502, '#1 Location 3502'), (9, 3503, '#1 Location 3503'), (10, 3504, '#1 Location 3504'); Result: sporthalls_id sporthalls_postcodes_id sporthalls_title 1 3400 #1 Location 3400 2 3401 #1 Location 3401 3 3402 #1 Location 3402 4 3403 #1 Location 3403 5 3404 #1 Location 3404
  6. Something like (incomplete): CREATE TABLE postcodes ( postcodes_id SMALLINT NOT NULL, #range -32k to 32k PRIMARY KEY (postcodes_id) ); CREATE TABLE sporthalls ( sporthalls_id SMALLINT NOT NULL AUTO_INCREMENT, #range -32k to 32k sporthalls_postcodes_id SMALLINT, sporthalls_title VARCHAR(32), PRIMARY KEY (sporthalls_id) ); CREATE TABLE postcodes_neighbours ( postcodes_neighbours_postcode SMALLINT NOT NULL, postcodes_neighbours_neighbour SMALLINT NOT NULL, PRIMARY KEY (postcodes_neighbours_postcode, postcodes_neighbours_neighbour) );
  7. Sure I can think of atleast one other: Store all postcodes in a table (or those that matter), store all sport halls (again those that matter). Give each sport hall it's postcode through a reference table (a table with the fields: postcodes_id and sporthalls_id) create a secondary reference table which tells which other postcodes is a neighbour of a specific postcode. When you select the sport halls use it's postcode and all neighbouring postcodes and show these sport halls.
  8. If you are executing from the command-line then use this as a quick fix: defined('__DIR__') or define('__DIR__', dirname(__FILE__));//PHP<5.3.0 chdir(__DIR__); This will change the directory from your php executable to the directory in which your files reside.
  9. if (!empty($_POST)) { $rollNo = abs((int) $_POST['RollNo']); $query = "SELECT * FROM stdresults WHERE RollNo = $rollNo"; //.. }
  10. Depends on what you know about Graph Theory you can find an example at: http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm On this page you will find under Pseudocode a shorter version which would solve what you are after.
  11. That would have been my advice if their even were a query in your code example.
  12. No that doesn't work, too bad You'll need an algorithm one like Dijkstra wrote.
  13. I already guessed that these wouldn't work. Then the normal way I guess: $lasttime = strtotime($row['time']); $diff = time() - $lasttime; $days = floor($diff / 86400); $hours = floor(($diff % 86400) / 3600); $minutes = floor((($diff % 86400) % 3600) / 60)); $seconds = floor(((($diff % 86400) % 3600) % 60)));
  14. Yes. I think you can't use a number as an alias.
  15. <select name="multifield"> <option value="option1">Option #1</option> <option value="option2">Option #2</option> </select>
  16. Windows Server 2003? Only 2008 can run PHP on IIS so 2003 would use Apache won't it?
  17. SELECT latitude, longitude FROM postcodes WHERE postcode BETWEEN '$start' AND '$finish' LIMIT 5 Won't work?
  18. if ('/' === $_SERVER['REQUEST_URI']) { print '<img src="root.jpg">'; }
  19. $defaultLanguage = 'en'; $language = !empty($_GET['language']) && language_is_valid($_GET['language']) ? $_GET['language'] : $defaultLanguage; language_load($language); $languageDirectory = 'path/to/lang/dir'; function language_get_file($language) { global $languageDirectory; return implode(DIRECTORY_SEPARATOR, array($languageDirectory, $language . '.lang.php')); } function language_is_valid($language) { $fullpath = language_get_file($language); return file_exists($fullpath); } function language_load($language) { $fullpath = language_get_file($language); include_once($fullpath); }
  20. $showRegistrationForm = true display's it false doesn't Take a look at http://www.phpfreaks.com/forums/index.php/topic,266890.msg1258749.html#msg1258749 What also may help is: unset($_POST) not sure though (I even have my doubts about this one as post data is send trough the request headers).
  21. $_POST['multifield'] is just the name of a field (name="multifield") option1 and option2 refer to: "i have different link which will execute different action"
  22. Then we are talking about a different story and is something like: if (!empty($_POST)) {//make sure that _POST contains something if (!empty($_POST['multifield'])) {//this should be set and should contain something if ('option1' === $_POST['multifield']) { //handle option1 } else if ('option2' === $_POST['multifield']) { //handle option2 } } } However whenever you process forms you should use something like: $requiredFields = array('..'); if (!empty($_POST) && hasRequiredFields($requiredFields, $_POST)) { //something was posted and all required fields are present. } function hasRequiredFields($requiredFields, $array) { $isValid = true; foreach ($requiredFields as $field) { if (!isset($array[$field])) { $isValid = false; break; } } return $isValid; }
  23. $diff = time() - $lasttime; print strftime('%e days %H hours %M minutes %S seconds', $diff);
  24. Yeah but IMO using if (isset($_POST['submit'])) is bad practice as your code won't be portable. Imagine I have a new project I have the existing PHP code (which I copy-paste to the new project) but the front-end (html) is made by someone else or like irkevin submit my form using an a-element instead of the normal submit button like I used in my previous project.
×
×
  • 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.