ignace
Moderators-
Posts
6,457 -
Joined
-
Last visited
-
Days Won
26
Everything posted by ignace
-
Which have you tried so far?
-
- Your HTML & CSS is invalid. - Your website links alot to files on different servers foresee for these files a page with an iframe where on top is your navigation (in short) and below is the file you are referring to or add target="_blank" I prefer the first method. The reason for this is 1) usability, users want to browse from one to another file 2) users are otherwise lost - The ADD FLYER page redirects the user to a completly different page with no navigation (keep consistency between your pages) - The design is 1998'ish - If an error occurs on the contact form the user is taken to a completely strange place with some technical text with only a back button. Clicking this back button takes him back to an empty form. -> improve form error handling
-
8 dollar is a fair amount. Freelancers start from 36 dollars I don't know about employee rates but surely are < 36 atleast for the most.
-
A Singleton is a design pattern defined by the Gang of Four (GoF) to keep only one instance of an object. class Singleton { private static $_instance = null; private function __construct() {} // disable instantiation private function __clone() {} // disabe cloning public static function getInstance() { if (null === self::$_instance) { self::$_instance = new self(); } return self::$_instance; } } And that's his implementation.
-
Actually there is a much faster way atleast if you are using Firefox just type in your url address bar: php function_name This will point you immediatly to the correct page (well atleast most of the times as this is the same as choosing "I'm feeling lucky" in Google). Another possibility is downloading the PHP manual add-on (https://addons.mozilla.org/nl/firefox/addon/8984).
-
A factory or builder in DD terms
-
include_once($_SERVER['DOCUMENT_ROOT'] . '/nav.php');
-
Ok so basically each to-do recurs by day/week/month/year. Ofcourse I don't know how you want to display this but something that may work: create table task ( id integer not null auto_increment, title varchar(64), description text, due enum('daily', 'weekly', 'monthly', 'yearly'), primary key (id) ); create table user ( id integer not null auto_increment, .. primary key (id) ); create table schedule ( id integer not null auto_increment, user_id integer, task_id integer, completed_on date, key schedule_user_id_fk (user_id), key schedule_task_id_fk (task_id), primary key (id) ); Display all tasks to each user: SELECT * FROM task WHERE id NOT IN(SELECT task_id FROM schedule WHERE user_id = $user_id AND completed_on = now()) ORDER BY due ASC And then roll them out like: Daily ---------------------- ... Weekly ---------------------- ... Monthly ---------------------- ... Yearly ---------------------- ... Edit: I was wrong this does not solve it
-
I would avoid it. http://code.google.com/p/google-singleton-detector/wiki/WhySingletonsAreControversial
-
I already said that: Don't you read my posts?
-
What do you actually mean by control? Are you basically building a to-do list?
-
Hehe cags I have to remember that
-
Another piece of good advice: know your language (and it's library) For example: define("DIRECTORY_SLASH","/"); Is actually already defined as DIRECTORY_SEPARATOR function countDir($directory){ $files = scandir($directory); foreach($files as $file){ if (!($file == ".") && !($file == "..")){ $count++; } } return $count; } Just feels wrong. You could easily read a directory and then just perform a count or the prefered sizeof if ($result = mysqli_query($link,"INSERT INTO files (uid,filename,location,date) VALUES('','$filename','$location','')")){ } Instead just mysqli_query($link,"INSERT INTO files (uid,filename,location,date) VALUES('','$filename','$location','')")); function createZip($mp3path,$filename){ date_default_timezone_set('UTC'); $zip = new ZipArchive; $zipdir = $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['SCRIPT_NAME']) . "/zip/" . date('dm') . "/"; if(!is_dir($zipdir)){mkdir($zipdir);} $res = $zip->open($zipdir . str_replace(".mp3",".zip",$filename), ZipArchive::CREATE); if ($res === true) { $zip->addFile($mp3path,$filename); $zip->setArchiveComment('Downloaded using empeethree.com'); $zip->close(); echo 'ok'; } else { echo 'failed'; } } When you are using echo inside a function then you are missing the point. A function should only return something because you may find you one day using createZip() but are then confronted with it's output that you in this case do not want. Instead use something like: define('F_CREATE_ZIP_SUCCESS', 1); define('F_CREATE_ZIP_FAILURE', 2); function createZip($mp3path,$filename){ date_default_timezone_set('UTC'); $zip = new ZipArchive; $zipdir = $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['SCRIPT_NAME']) . "/zip/" . date('dm') . "/"; if(!is_dir($zipdir)){mkdir($zipdir);} $res = $zip->open($zipdir . str_replace(".mp3",".zip",$filename), ZipArchive::CREATE); if ($res === true) { $zip->addFile($mp3path,$filename); $zip->setArchiveComment('Downloaded using empeethree.com'); $zip->close(); return F_CREATE_ZIP_SUCCESS; } else { return F_CREATE_ZIP_FAILED; } } if (createZip(..) === F_CREATE_ZIP_FAILED) { .. However this is a bad example because you actually only have 2 possibilities where you would then better use return true & return false respectively ok and failed. Also worth noting is that the execution of a function stops after a return so return true; } else { return false; } Can be written as: return true; } return false; (substr($_FILES['userfile']['name'],strlen($_FILES['userfile']['name']) - 4,strlen($_FILES['userfile']['name'])) == ".mp3") This is what I meant by know your library as the same can be written as: ('mp3' == pathinfo($_FILES['userfile']['name'], PATHINFO_EXTENSION)) function randomString($length){ $characters = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",1,2,3,4,5,6,7,8,9,0); for ($i = 0; $i < $length; $i++){ $random_string .= $characters[rand(0,sizeof($characters))]; } return $random_string; } Like Mchl already said should you refactor randomString() I would recommend rewriting it function generateString($length = 16) { $hash = array_merge(range('A', 'Z'), rand('a', 'z'), range(0, 9)); return implode('', array_rand($hash, $length)); } Yes this function does exactly the same. while(countDir($uploaddir) >= 10){ !!HORROR!! $files = scandir($uploaddir); $sizeof = sizeof($files); while ($sizeof >= 10) { .. --$sizeof; } while(countDir($uploaddir) >= 10){ if (is_dir($uploaddir) == true){ if (countDir($uploaddir) >= 10){ $subdirectory++; $uploaddir = $base_path . $mp3directory . $subdirectory . DIRECTORY_SLASH; if(!is_dir($uploaddir)){mkdir($uploaddir);} } } $uploaddir = $base_path . $mp3directory . $subdirectory . DIRECTORY_SLASH; } There are no words for this massacre.. $page = $_GET['page']; //get page number $action = $_GET['action']; if ($action == "list"){ if (!isset($page)){$page = 0;} //if no page number set 0 Instead write: $page = isset($_GET['page']) ? intval($_GET['page']) : null; $action = $_GET['action']; if ('list' == $action) { if ($page) {
-
Simple. I don't. As a programmer you always learn new things and you actually have no use in snippets as by the time you come across the same problem you will be able to write a more efficient solution. Plus having a good memory helps aswell. I for example can look at someone's code see how he did things and apply it a few years later.
-
PHP + MYSQL Categories > Sub Categories | Help!
ignace replied to GFXUniverse's topic in PHP Coding Help
You want to create multi-level categories but you only foresee a 2-level category system (category, subcategory) Instead you need: create table category ( id integer not null auto_increment, parent_id integer, .. key category_parent_id_fk (parent_id), primary key (id)); Now you can go as deep as you want. For example: insert into category values (1, 0, 'parent category'), (2, 1, 'sub category'), (3, 2, 'sub sub category'), (4, 3, 'sub sub sub category'); -
Unit-testing is an automated test to verify that your implementation is correct. You have these for both client- (Selenium) and server-side (PHPUnit). In the end it gives your client a higher quality assurance.
-
To make something and being valid are two separate things. Something can be valid but the application does not work or in your case the application works but your html and css are not valid. If you are unfamiliar with the html and css syntax then pick up a book to familiarize yourself with the syntax for both languages.
-
For free source code you may try Google Code or Sourceforge, no free source code here If you are willing to pay someone then head over to the freelance section and someone may take the job. If you don't that option try something yourself using tutorials and if you get stuck we'll help.
-
So what would you call people who make use of phpunit? Developers
-
Using java to force a downloaded .doc file to open in ms word
ignace replied to wintersilke's topic in Javascript Help
JavaScript != Java -
Baffled by Undefined Index in Simple Array: Please Help!
ignace replied to somedude084's topic in PHP Coding Help
It means Quantity does not exist. And this code is not possible: echo $_POST['Item'][0]['Quantity']; It's: echo $_POST['Item'][0]; //or echo $_POST['Item']['Quantity']; -
No only JavaScript is local aware. You can however upon registration ask your user to tell you what his current time is GMT+..
-
If you want help in writing a script for you head over to the freelance section otherwise try something yourself using tutorials got problems with that then we'll tell you what you did wrong.
-
Yeah mqsdjfmqhstd.my beautiful password not visible at all here.qmlhgqhytmqr very hard indeed..
-
I have no idea what you mean? That proves my point You should have something like: header('Content-Disposition: attachment; filename=' . $filename); See this example at php.net readfile