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...

Member Avatar for diafol

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");

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.