
ignace
Moderators-
Posts
6,457 -
Joined
-
Last visited
-
Days Won
26
Everything posted by ignace
-
What is the technical term used for this feature?
ignace replied to usman07's topic in PHP Coding Help
You can make this as simple/straightforward as: function get_detached_houses($mysql) { $sql = 'SELECT * FROM real_estate WHERE type_id = 5'; // 5 = Detached House $rows = mysql_fetch_all($sql, $mysql, MYSQL_ASSOC); return $rows; } You can check what the user asked for by creating URL's like: estate.php?type=semi-detached estate.php?type=detached .. In your code you would use the type to display the correct properties: $mysql = mysql_connect(/*...*/); if (get('type') === 'detached') { $estate = get_detached_houses($mysql); } else if (get('type') === 'semi-detached') { // .. } else { $estate = get_houses(); } mysql_fetch_all and get are custom functions: function get($name, $default = null) { return array_key_exists($name, $_GET) ? $_GET[$name] : $default; } // executes a query and returns a result set function mysql_fetch_all($sql, $mysql, $mode = MYSQL_BOTH) { $rows = array(); $res = mysql_query($sql, $mysql); if ($res && mysql_num_rows($res)) { while ($row = mysql_fetch_array($res, $mode)) { $rows[] = $row; } } return $rows; } -
It should be noted though that these will not be unique. As an example I already had a duplicate after generating 960 serials. I hope this was just an exercise and you didn't wanted to use these for software licensing or something?
-
One line of code (without indentiation) to create the serial. print implode('-', // concatenate each group with '-' str_split( // split them into lenghts of 4 implode('', // concatenate them to a string array_rand( // pick out 12 elements array_flip( // array_rand reads keys, not values array_merge( // merge ranges range(0, 9), // 0 - 9 range('A', 'Z') // A - Z ) ), 12) ), 4) );
-
How Does PHPFreaks Feel About the Hate PHP Often Gets as a Language?
ignace replied to Masna's topic in Miscellaneous
You underestimate us! We can be really neutral on these subjects... For we are enlightened. -
What do you have so far?
-
I second that. There is no such thing as /home/users on Windows.
-
How Does PHPFreaks Feel About the Hate PHP Often Gets as a Language?
ignace replied to Masna's topic in Miscellaneous
Try Scheme. -
How Does PHPFreaks Feel About the Hate PHP Often Gets as a Language?
ignace replied to Masna's topic in Miscellaneous
The fun part about PHPWTF is that the website is written in PHP. Makes me think the owner is like: Choice of language is just that.. You don't like it, move on! Go program Java, boy! That said you shouldn't be limiting yourself to one language anyway. -
There really is no need to create your own Time object as PHP has a built-in equivalent DateTime
-
The solution to your problem can be found here!
-
It's humor, Jim. But not as we know it!
-
$query_handle->bindParam($i, $value[$i]); should be: $query_handle->bindParam($i, $binds[$i]); The reason you are not getting any errors is because you don't have error reporting set to On (at the very least you would have gotten something like `Undefined index` since $value is empty) or display errors have been turned Off. error_reporting(E_ALL); ini_set('display_errors', 1); For best effect these should be turned on in your php.ini
-
And you shouldn't. At the very least export these rows to an archive table.
-
Without having some demo data it's hard to write this query off the top of my head, but could something like this work? ( -- invoice_numbers marked as inactive should be considered for re-use SELECT invoice_number AS `Missing From`, invoice_number AS `To` FROM payments WHERE active=0 ) UNION ( -- find unused invoice_numbers -- Source: http://www.artfulsoftware.com/infotree/queries.php#71 SELECT a.invoice_number + 1 AS `Missing From`, MIN(b.invoice_number) - 1 AS `To` FROM payments a, payments b WHERE a.invoice_number < b.invoice_number GROUP BY a.invoice_number HAVING `Missing From` < MIN(b.invoice_number) )
-
OOP - Recommended Template/Theme/Page Design Structure
ignace replied to Bladescope's topic in PHP Coding Help
your centos server should be fine. -
1) The while is unnecessary. while ( $a = mysql_fetch_assoc($r) ) { global $siteName, $siteMotto, $siteIco; $siteName = $a['site_name']; $siteMotto = $a['site_motto']; $siteIco = $a['site_ico']; } Instead just write: $a = mysql_fetch_assoc($r); global $siteName, $siteMotto, $siteIco; $siteName = $a['site_name']; $siteMotto = $a['site_motto']; $siteIco = $a['site_ico']; 2) PHP has a built-in data-access layer called PHP Data Objects (PDO), use it! There are plans to ditch the mysql extension in favor of mysqli, so avoid it, if possible or use PDO. That said use PDO using the mysqli driver. 3) Create classes to group related functionality. abstract class DataStoreService { private $pdo; public function __construct(PDO $pdo) { $this->pdo = $pdo; } protected function query($sql) { $stmt = $this->pdo->query($sql); if (false === $stmt) { throw new ErrorException($this->pdo->errorInfo(), $this->pdo->errorCode()); } return $stmt; } } class Site {/*represents the site*/} class SiteSettings extends DataStoreService { public function getSiteData() { $stmt = $this->query('SELECT * FROM siteSettings ORDER BY id DESC LIMIT 1'); if ($stmt->rowCount()) { return $stmt->fetchObject( 'Site' ); } return null; // no site data available! bad? throw an exception if it is. } } class Article {/*represents an article*/} class Articles extends DataStoreService { public function getLatest() { $stmt = $this->query('SELECT * FROM testDB ORDER BY created DESC LIMIT 4'); if ($stmt->rowCount()) { return $stmt->fetchAll( PDO::FETCH_CLASS, 'Article' ); } return array(); // nothing here! } 4) Avoid the use of the global keyword. You don't need it! Read up on Depedency Injection and Service Containers
-
OOP - Recommended Template/Theme/Page Design Structure
ignace replied to Bladescope's topic in PHP Coding Help
There aren't that many IDE's out there that fully support the new v5.4 features like traits. -
OOP - Recommended Template/Theme/Page Design Structure
ignace replied to Bladescope's topic in PHP Coding Help
Yup. Hands down the best IDE out there for PHP development. The current beta (EAP) version fully supports PHP v5.4 and almost all of Subversion 1.7. They recently added support for {@inheritDoc} and they show code coverage for all lines in your files. And that's just scratching the surface. When I looked at all the supported features, my first thought was: IT'S OVER 9000!!! -
Something like this? http://www.jankoatwarpspeed.com/post/2008/05/22/CSS-Message-Boxes-for-different-message-types.aspx
-
Euhm.. must have been quite late when I posted this. I meant: use the user-agent strings within the robots.txt file and match them with the HTTP_USER_AGENT string (some are missing of course: all the legit once, you should add these too). Obviously just putting a simple robots.txt in your root would do nothing. But you'll never be 100% sure to count only real user views and not bot views since they could use the User-Agent string of say Chrome or Firefox.. I think the main reason Google uses JS is to make sure it does not count crawlers (use a clever <noscript> to count those that have JS disabled?). IMO that's the way to go.
-
Check out robots.txt @ http://browsers.garykeith.com/downloads Could be a good starting point.
-
Yup. Here are a few resources to study what design patterns: http://martinfowler.com/eaaCatalog/ http://www.slideshare.net/spriebsch/basic-php-design-patterns-presentation http://www.ibm.com/developerworks/library/os-php-designptrns/ http://www.fluffycat.com/PHP-Design-Patterns/ My favourite is to use SlideShare.net to learn/understand new stuff.
-
How can I achieve this in OOP PHP the right way?
ignace replied to mds1256's topic in Application Design
@thorpe I really like how Proem has evolved. Any word on an expected release candidate? -
How can I achieve this in OOP PHP the right way?
ignace replied to mds1256's topic in Application Design
OT: And by that we mean ALL globals! Even superglobals like _GET and _POST unless the class has been specifically written to deal with them like a HttpRequest class. There are better alternatives than using the 'global' keyword AND not having to pass the db instance with every instantiation, it's called: Dependency Injection and you can find a few good packages on github, I favor those by Fabien Potencier but there are others. Basically they allow you to get an instance of an object without having to worry about passing all the required arguments, something like this (from my earlier example): $smarty = $container['smarty']; $articles = $container['newsarticles']; $smarty->assign('articles', $articles->listLatest()); $smarty->render('template.tpl'); -
I had to google 'mike hunt' before I understood what the joke was about.. LOL.