Jump to content

Archived

This topic is now archived and is closed to further replies.

triphp

Textarea list vs database entries

Recommended Posts

I have a textarea wherein users can input a string, i.e. names for example, line by line. And in my database I have a table that store the names.

I want to compare the names (one name per line) he entered in the textarea versus the names in the database. If the names he entered in the textarea is not yet in the database, it will be echoed back.

Does anyone know how to do the comparison? Is there a built-in function in PHP to do this? Any help or examples give is greatly appreciated :)

Share this post


Link to post
Share on other sites
I think you can do an array compare against two arrays, that would probably be the way to go... Look at [url=http://uk.php.net/manual/en/function.array-diff.php]array_diff()[/url].

Get both sets of data into an array, this should be pretty simple, if you're not sure, give us a shout back.

Regards
Huggie

Share this post


Link to post
Share on other sites
Can you give an example how to turn the multi line entries in textarea to be an array?

Share this post


Link to post
Share on other sites
$names = $_POST['textarea'];
$names = explode("\r\n",$names);

THink that should do the trick...

Share this post


Link to post
Share on other sites
You should be able to use [url=http://uk.php.net/manual/en/function.explode.php]explode()[/url] for that.

[code]
<?php
$array = explode("\n", $_GET['name_textarea']);
?>
[/code]

Regards
Huggie

Share this post


Link to post
Share on other sites
OK thanks for the replies. I'll try my best to not ask again :)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.