Jump to content


Photo

Textarea list vs database entries


  • Please log in to reply
5 replies to this topic

#1 triphp

triphp
  • Members
  • Pip
  • Newbie
  • 7 posts
  • LocationCebu, Philippines

Posted 04 October 2006 - 11:08 PM

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 :)
http://www.spokendollars.com/- Let's talk how to earn money online.

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 04 October 2006 - 11:30 PM

I think you can do an array compare against two arrays, that would probably be the way to go... Look at array_diff().

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 triphp

triphp
  • Members
  • Pip
  • Newbie
  • 7 posts
  • LocationCebu, Philippines

Posted 04 October 2006 - 11:33 PM

Can you give an example how to turn the multi line entries in textarea to be an array?
http://www.spokendollars.com/- Let's talk how to earn money online.

#4 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 04 October 2006 - 11:35 PM

$names = $_POST['textarea'];
$names = explode("\r\n",$names);

THink that should do the trick...
follow me on twitter @PHPsycho

#5 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 04 October 2006 - 11:37 PM

You should be able to use explode() for that.

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

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#6 triphp

triphp
  • Members
  • Pip
  • Newbie
  • 7 posts
  • LocationCebu, Philippines

Posted 04 October 2006 - 11:39 PM

OK thanks for the replies. I'll try my best to not ask again :)
http://www.spokendollars.com/- Let's talk how to earn money online.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users