0

Hello ppl...

How to insert a list of lines to sql through php and create a id for each line

example....i have

flames
flintones
flames1
....
....
so on

after submitting these lines i need a short id for these lines like (short id can be anything)

1232
1546
1578
..
..
so on

hope i m clear to u...

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by seslie
0

You can create the table with this SQL:

CREATE TABLE `lines` (
  `id` int(4) unsigned NOT NULL AUTO_INCREMENT,
  `line` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2000 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

Start the auto_increment at any value or delete that parameter to start at 1

Change the varchar and int lengths to whatever you need.

then just add the lines - assume that your lines of text are in an array called $lines:

$values = "('" . implode("'),(NULL,'",$lines) . "')";
$q = mysql_query("INSERT INTO `lines` (`id`,`line`) VALUES $values");

Edited by diafol

0

Hello Flames1,

I assume you are trying to insert into a database table through php. Am i right?

First you need to create a trigger. That trigger is where you specify the form of the short ids. You can make it random, or decide to increment by 1 or whatever you prefer.

And write ur code in a way that includes the trigger.

Regards,

Seslie.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.