In response to [this thread](https://www.daniweb.com/programming/web-development/threads/499762/jquery-for-dropdown-textbox) I've decided to paste the linked example as a code snippet (updated to html5/jQuery2).

Member Avatar
Member Avatar
+2 forum 1

For a report I had to show a list of items (ID's). Instead of showing them all, they wanted to show consecutive items separated by a dash. Just like the way you would use print pages in Word for example. In the print dialog you can say 1-5, 8 to indicate pages 1, 2, 3, 4, 5, 8. The code shows how you can do this with Linq in a single (but long) line. I've created the `ConsecutiveGroup` class for it, because both the standard `KeyValuePair` and `Tuple` classes I wanted to use at first have read-only properties. Feel free …

Member Avatar
Member Avatar
+0 forum 1

A while ago I explained how you could tag articles (see [this thread](http://www.daniweb.com/web-development/php/threads/387961/php-code-to-show-related-posts-on-a-blog)). Now you get a full working example. This code and the SQL script is also available on GitHub. The attached MySQL dump needs to be imported into your database, and you must update the credentials in the code below. I think the code is short enough to be read without comments. If this is not the case, feel free to ask questions.

Member Avatar
Member Avatar
+2 forum 1

The following snippet shows how you can use binding in your queries when using MySQLi. For starters, here's the table structure I've used: CREATE TABLE `mytable` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) DEFAULT NULL, `email` varchar(255) DEFAULT NULL, `dob` date DEFAULT NULL, `level` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; The snippet shows how to use binding for an INSERT and an UPDATE query. The same method can be used for a SELECT. Note that you can only use it to bind values to a query, you cannot use this to dynamically insert …

Member Avatar
Member Avatar
+3 forum 2

The following snippet shows how you can use binding in your queries when using PDO. For starters, here's the table structure I've used: CREATE TABLE `mytable` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) DEFAULT NULL, `email` varchar(255) DEFAULT NULL, `dob` date DEFAULT NULL, `level` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; The snippet shows how to use binding for an INSERT and an UPDATE query. The same method can be used for a SELECT. Note that you can only use it to bind values to a query, you cannot use this to dynamically insert …

Member Avatar
+3 forum 0

The following code snippet shows how you can parse a DSN (Data Source Name). Why is it useful? You can now pass a single DSN parameter to your database wrapper class' constructor (instead of five separate parameters), and tear it apart into the components you need. The password and port are considered optional. You may need to tweak the regex if you use other characters than letters, digits or underscores. Questions? Ask!

Member Avatar
+1 forum 0

This snippet shows how you can get the headers for an URL, for example to detect a redirect. I had to use the ANSI functions to ensure correctly returned headers. Manual entry for [HttpQueryInfo](http://msdn.microsoft.com/en-us/library/windows/desktop/aa385373(v=vs.85).aspx). Let me know if you have any questions/remarks.

Member Avatar
Member Avatar
+1 forum 1

Attached is the code for my RSS dashboard, using the DaniWeb API. It's an improved version of the mashup I posted earlier, using jQuery to get all feeds asynchronously. The part which initially loads the forums is shown below. It creates an API object, and a Parser object. The first gets the forums list in JSON format, the second the extracts all forums to create the initial empty div's. A static method to a decorator function is passed, which adds the actual markup. The Parser and Decorator classes are in the zip file, so I won't discuss those here. If …

Member Avatar
Member Avatar
+1 forum 9

Here's my base class and class for the unauthenticated DaniWeb API calls. Not every method has all features implemented yet, and it's not been fully tested either. Here's how to start using it: include 'DwApiBase.class.php'; include 'DwApiOpen.class.php'; $dwapi = new DwApiOpen(); $result = $dwapi->GetMemberActivityPoints(94719); $result = $dwapi->GetMemberEndorsements(94719); $result = $dwapi->GetMemberReputationComments(94719); $result = $dwapi->SearchArticles('daniweb-api'); $result = $dwapi->SearchMembers('pritaeas'); Open to suggestions, questions, etc.

Member Avatar
Member Avatar
+2 forum 3

## RSS Class ## The code snippet is a PHP class for retrieving RSS feeds from the DaniWeb website. There are two exposed methods, one for retrieving the list of predefined article types, and another to get a specific RSS feed. If you pass parameters to this method, there is a basic check to see if the forum ID is an integer and greater than zero. The article type will be checked against the predefined list. ## To do ## I want to combine this class later with the DaniWeb API, so it can retrieve a valid list of forum …

Member Avatar
Member Avatar
+1 forum 11

## API Mashup ## This example is a mashup of [diafol's class](http://www.daniweb.com/web-development/php/code/451428/daniweb-api-class-for-getting-forums), [Dani's parsing code](http://www.daniweb.com/api/documentation) and [my class](http://www.daniweb.com/web-development/php/code/451390/daniweb-api-rss-class). It uses diafol's dwAPI class to retrieve a list of all forums, loops through them, and uses my Rss class to get the respective RSS feeds. It will show each forum in a separate div (with Dani's code) with it's title and no more than the five latest posts. The div will be omitted if there are no posts. (@Dani: some feeds give a parse error, and that's shown instead.) You can try it yourself. Note that looping through all the forums …

Member Avatar
Member Avatar
+0 forum 3

The following snippet will show, how you can pass a data array to a function, and generate a table with N columns. `$data` contains some dummy data, which can come from any data source. Then you call `createHtmlTable` passing the data, the number of columns you want, and a function, which will be called for each row, where you can specify the exact layout of each cell. I hope the comments speak for themselves. If not, please reply and let me know.

Member Avatar
Member Avatar
+3 forum 7

Below is a documented code example showing how to use the SQLite3 class to connect and query your database (and check for errors). IMHO using PDO is a better alternative, as this extension uses mixed technology in a non-standard way (objects, arrays and exceptions). If there are any questions let me know.

Member Avatar
+2 forum 0

Below is a documented code example showing how to use the SQLite functions to connect and query your database (and check for errors). Please note that using the SQLite extension is NOT RECOMMENDED. This extension is no longer available in PHP 5.4.0. If you want your scripts to be future proof it is better to switch to PDO. If there are any questions let me know.

Member Avatar
+2 forum 0

This demo will show a PHP script using a Smarty template. It assumes basic installation. In the folder where you copy the script, there should be a smarty folder containing the Smarty files. You should create a writable `cache` and `templates_c` folder, and a folder called `templates` where the `.tpl` file should be. For example: /smarty-demo/ smarty/ templates/ arrayTemplate.tpl templates_c/ cache/ using-smarty.php The code below shows both files, so make sure you split them. The demo is using arrays and array notation in the template. It is possible to use objects and object notation as well, but I've excluded that …

Member Avatar
Member Avatar
+2 forum 4

Below is a documented code example showing how to use the [PDO](http://php.net/pdo) classes/objects to connect and query your database (and check for errors). If there are any questions, or you want to see different features, let me know. UPDATE: I've encountered a problem with PDO and bit fields (MySQL). If you experience any problems with those I suggest changing the column type to TINYINT(1).

Member Avatar
Member Avatar
+2 forum 1

Below is a documented code example showing how to use the [MySQLi](http://php.net/manual/en/book.mysqli.php) (MySQL improved) classes/objects to connect and query your database (and check for errors). If there are any questions, or you want to see different features, let me know.

Member Avatar
+5 forum 0

Below is a documented code example showing how to use the [MySQL functions](http://php.net/manual/en/book.mysql.php) to connect and query your database (and check for errors). Please note that using the MySQL extension is **NOT RECOMMENDED**. This extension is no longer maintained and will be deprecated soon. If you want your scripts to be future proof it is better to switch to [MySQLi](http://www.daniweb.com/web-development/php/code/434480/using-phpmysqli-with-error-checking) or [PDO](http://www.daniweb.com/web-development/php/code/435142/using-phppdo-with-error-checking). If there are any questions, or you want to see different features, let me know.

Member Avatar
+3 forum 0

In addition to [my post in this thread](http://www.daniweb.com/web-development/php/threads/429740/php-best-practice#post1841569) I've decided to post an extended example, which also implements functions for inserts and updates. I hope the code is straightforward enough. If not, reply and let me know. The table structure I've used for my test is the following: CREATE TABLE `contacts` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(64) NOT NULL, `password` varchar(64) NOT NULL, `first_name` varchar(64) DEFAULT NULL, `last_name` varchar(64) DEFAULT NULL, `email` varchar(64) NOT NULL, PRIMARY KEY (`id`) ) And finally, here is how to use it: <?php # Definition of my table structure $tableConfig = array …

Member Avatar
Member Avatar
+4 forum 1

The `ReplaceStrings` function replaces all strings in `APatterns` found in `ASubject` with the value in `AReplacement`. As an example, I added the `RemoveStrings` function which replaces everthing with an empty string, thus deleting all strings found. Usage examples are in the XMLDoc comments. A good test will be to rewrite this function to accept regular expression patterns, or write one that accepts an array of replacements, so each sub -string can be replaced with a different value.

Member Avatar
Member Avatar
+0 forum 2

The End.