13 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for Dani

Sometimes you need to delete duplicate rows in a database :) In the future, set UNIQUE keys when you need them :) In the example below, we have a table appropriately named `TABLE_NAME` and there are multiple rows that have the same value for the `duplicate_field` field. In this example, …

Member Avatar for Usamatamimi
4
4K
Member Avatar for Dani

I recently had to mass insert a really large text file of strings into MySQL. Here's how I did it.

Member Avatar for PARDEEP_2
1
1K
Member Avatar for niranjanjee
Member Avatar for metalix

first create the table [CODE] create table images ( image_id serial, filename varchar(255) not null, mime_type varchar(255) not null, file_size int not null, file_data longblob not null, primary key (image_id), index (filename) ); [/CODE] the file to output the images to the browser [B]picsrc.php[/B] [CODE]<?PHP //detect if image is called …

Member Avatar for guruparthi
0
1K
Member Avatar for Isaac_4

Here is a simple way to insert into a database that isn't much harder than using string concatenation - which we all know is very dangerous due to SQL injection attacks. Put the code snippet into `database.php`. Now, in a script handling a form post, such as `post_reply.php`: <?php require_once("database.php"); …

Member Avatar for diafol
4
498
Member Avatar for Szabi Zsoldos

Raffle function to generate unique numbers for each player, related to the same table with a recursive aproach. I had to do a simple raffle system for a contest that I was working on and tried many things and the most simple and the most effective one to generate unique …

Member Avatar for diafol
0
893
Member Avatar for pritaeas

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 …

Member Avatar for aufche
2
906
Member Avatar for Gewalop

Hi, - Why use paging? It's not really cool to print out all 2000 rows you have in a table to the page, so it'd be nice to page them. Special cases? Yeah, if you have 1000 rows.. and you've set the maximum row per page to 20, well.. you're …

Member Avatar for diafol
6
2K
Member Avatar for pritaeas

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 …

3
858
Member Avatar for mb01a

I found an old thread that had never been answered here - [url]http://www.daniweb.com/software-development/vbnet/threads/330981[/url] Basically, the guy was asking how to retrieve database names and/or table names from a MySql database with vb.net. Here's my answer to that. Yes, I still use vb6 because vb.net is not much better and I …

0
950
Member Avatar for metalix

View the full tutorial at [URL="http://www.effectivewebdesign.co.nz/tutorial.php"]http://www.effectivewebdesign.co.nz/tutorial.php[/URL] I have tested this many times and it works fine. Please don't complain unless you really can't get it working, Just PM me and I'll fill in the blanks Happy Coding :)

Member Avatar for Rogueit
0
844
Member Avatar for Brianbc

[CODE]<?php /* +-----------------+------------------------------------------------------------+ | Class | setup | | Author | Brian Onang'o | | Version | 1.0 | | Last Modified | 10:16 AM 10/2/2010 GMT+3 | +-----------------+------------------------------------------------------------+ | This program is free software; you can redistribute it and/or | | modify it under the terms of the GNU …

Member Avatar for Brianbc
0
238
Member Avatar for metalix

To view this tutorial with notes at [URL="http://www.effectivewebdesign.co.nz/tutorial.php"]http://www.effectivewebdesign.co.nz/tutorial.php[/URL] yes I am aware this is more php than mysql. howerver I get asked how to do it so often I thought I'd post it here aswell :)

0
693

The End.