triphp Posted October 4, 2006 Share Posted October 4, 2006 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 :) Quote Link to comment https://forums.phpfreaks.com/topic/23029-textarea-list-vs-database-entries/ Share on other sites More sharing options...
HuggieBear Posted October 4, 2006 Share Posted October 4, 2006 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.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23029-textarea-list-vs-database-entries/#findComment-104023 Share on other sites More sharing options...
triphp Posted October 4, 2006 Author Share Posted October 4, 2006 Can you give an example how to turn the multi line entries in textarea to be an array? Quote Link to comment https://forums.phpfreaks.com/topic/23029-textarea-list-vs-database-entries/#findComment-104024 Share on other sites More sharing options...
ToonMariner Posted October 4, 2006 Share Posted October 4, 2006 $names = $_POST['textarea'];$names = explode("\r\n",$names);THink that should do the trick... Quote Link to comment https://forums.phpfreaks.com/topic/23029-textarea-list-vs-database-entries/#findComment-104028 Share on other sites More sharing options...
HuggieBear Posted October 4, 2006 Share Posted October 4, 2006 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]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23029-textarea-list-vs-database-entries/#findComment-104030 Share on other sites More sharing options...
triphp Posted October 4, 2006 Author Share Posted October 4, 2006 OK thanks for the replies. I'll try my best to not ask again :) Quote Link to comment https://forums.phpfreaks.com/topic/23029-textarea-list-vs-database-entries/#findComment-104033 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.