Scripts and functions that I have written or found useful

Archive for the ‘MYSQL’ Category

mysql delete duplicate rows

Monday, November 5th, 2007 Posted in MYSQL | 2 Comments »

DELETE tablename FROM tablename, (SELECT MAX(uid) AS dupid,COUNT(uid) AS dupcnt FROM tablename GROUP BY id,url HAVING dupcnt>1) AS dups WHERE tablename.uid=dups.dupid;

replace string in a table

Wednesday, October 17th, 2007 Posted in MYSQL | No Comments »

If you want to change certain rows in a database where a query applies ... for example an "if" query finding all entries which contain "samplesearchtext"... then run the following script either via mysql/phpmyadmin/php update mytable set myfield =replace (myfield, 'samplesearchtext', ...

mysql error codes

Monday, September 24th, 2007 Posted in MYSQL | No Comments »

#1046-No database Selected. You are trying to query without choosing a database #1054 - Unknown Column #1109 - Unknown Table #1136 - Column count doesn't match the value count

PHP Get last inserted ID from mysql

Saturday, August 18th, 2007 Posted in MYSQL, PHP | 1 Comment »

$id = mysql_insert_id(); Each person on the website has a different session so if you use the above, it will automatically know which row was inserted last with this session. You do not need to worry about 2 people being on ...

PHP + MySQL Recursive Word Search

Friday, September 8th, 2006 Posted in MYSQL, PHP | No Comments »

This script will allow you totype asmany words as you like into a text box and find instances where all of these words exists in any field. The words entered only need to be seperated by spaces, no commas required! [php] $search ...

Dynamic Date ticker/scroller

Friday, September 8th, 2006 Posted in Javascript, MYSQL | No Comments »

This is useful for displaying dynamic data in a small space, it scrolls the data and pauses at every line. It will also pause on mouseover [javascript] [/javascript]

Quick and simple Mysql connect

Friday, September 8th, 2006 Posted in MYSQL | No Comments »

This is the simplest and neatest way to connect to a MySQL database using php [php]$dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("database_name"); [/php]