473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

textarea selection

Hey all,

I'm trying to create a php tool for local use where I put a
list of words (one on each line) in to a textbox and it takes each word
and creates an entry in an sql table.

So I'd put

hey
ho
whats
up
yes
no
maybe

and it'd go through each word and create a seperate entry so 1 for hey,
1 for ho, and so on.

Is there a way to

a) get how many rows there are in to php?
b) select each row and grab it's contents?

Thanks for your time.

Oct 12 '06 #1
4 1412
Lucas Byers wrote:
Hey all,

I'm trying to create a php tool for local use where I put a
list of words (one on each line) in to a textbox and it takes each word
and creates an entry in an sql table.

So I'd put

hey
ho
whats
up
yes
no
maybe

and it'd go through each word and create a seperate entry so 1 for hey,
1 for ho, and so on.

Is there a way to

a) get how many rows there are in to php?
b) select each row and grab it's contents?

Thanks for your time.
I assume you are looking for something like this:

function readFileToDB($file)
{
if(!$fp=@file($file)) //$fp is an array of each line in $file
{
echo "FAILED-LEVEL-1";
exit;
}
for($i=0; $i<count($fp); $i++)
{
if(!$dp=sqlOperationInsert($fp[$i])
{
echo "FAILED-LEVEL-2";
exit;
}
}
echo "SUCCESS";
}

function sqlOperationInsert($data)
{
// insert into database.
}
Oct 12 '06 #2
Lucas Byers wrote:
Hey all,

I'm trying to create a php tool for local use where I put a
list of words (one on each line) in to a textbox and it takes each word
and creates an entry in an sql table.

So I'd put

hey
ho
whats
up
yes
no
maybe

and it'd go through each word and create a seperate entry so 1 for hey,
1 for ho, and so on.

Is there a way to

a) get how many rows there are in to php?
b) select each row and grab it's contents?

Thanks for your time.
I assume you are looking for something like this:
function readFileToDB($file)
{
if(!$fp=@file($file)) //$fp is an array of each line in $file
{
echo "FAILED-LEVEL-1";
exit;
}
for($i=0; $i<count($fp); $i++)
{
if(!$dp=sqlOperationInsert($fp[$i])
{
echo "FAILED-LEVEL-2";
exit;
}
}
$count = count($fp);
echo "SUCCESS, ENTRY COUNT WAS: $count\n";
}

function sqlOperationInsert($data)
{
// insert into database.
}
Oct 12 '06 #3

Lucas Byers wrote:
Hey all,

I'm trying to create a php tool for local use where I put a
list of words (one on each line) in to a textbox and it takes each word
and creates an entry in an sql table.

So I'd put

hey
ho
whats
up
yes
no
maybe

and it'd go through each word and create a seperate entry so 1 for hey,
1 for ho, and so on.

Is there a way to

a) get how many rows there are in to php?
b) select each row and grab it's contents?

Thanks for your time.
Simply do an explode on newlines to get the lines into an array, then
process the array into sql however you see fit.

$myArray = explode("\n",$_POST['myTextArea']);

foreach($myArray as $line){
$line = trim($line);
//do some sql stuff here
}

Oct 12 '06 #4
May be simple to you guys, but I'm new @ this. ;) Thanks for the help.
:D

Oct 12 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Krzysztof Kujawski | last post by:
Hi Is there posibility to (and how to do this): a) add a string in the current cursor position? b) add string before and after selection in textarea e.g. selection c) if I put with...
2
by: Mark Szlazak | last post by:
The following code fails in Firefox to get at selected text in the right-side textarea. Any help would be appreciated. <html> <head> <script> var agt = navigator.userAgent.toLowerCase();...
5
by: aqualizard | last post by:
I have searched and searched and searched... Can someone please tell me how (or "if" it is even possible) to change selected text in a textarea? Specifically, say a user has highlighted "ppl"...
1
by: Gernot Frisch | last post by:
Hi, I want to be able to select 3 rows of a textarea, and when pressing "Tab/shift Tab" indent the source code edited. Can I do this with JavaScript? -- -Gernot int main(int argc, char**...
4
by: Keith Bentrup | last post by:
Hi all, I wrote a simple search function to find text in a textarea where not all the text is visible (ie. the text box displays 10 lines but there may be more than 1000 lines to search). I can...
4
by: jim | last post by:
Hi, I have a form that accepts free text from users in a single textarea field. I would like for a select list of words (15 or so) to autopopulate as the user types. For example, instead of...
2
by: dennis.sprengers | last post by:
Ik ben bezig met een eigen UBB editor. Als iemand aan het typen is, zorgt CTRL-B voor een \-tag en nogmaals CTRL-B voor een \ tag. Als je eerst een selectie maakt en dan CTRL-B drukt, wordt de...
3
kendall
by: kendall | last post by:
I'm currently working on a PHP CMS for my school that uses simple forms to update the pages and database. To get it out in use, it will have to be usable by people who don't know that is bold, and...
1
by: beary | last post by:
I need to populate a textarea from drop down box. There are a few "solutions" out there, but they seem to remove the first choice from the textarea when a second selection is made. So I need... 1)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.