Having Problem Creating SQL From Textarea

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
silenceechoes
Forum Newbie
Posts: 1
Joined: Thu Jul 08, 2004 2:14 am

Having Problem Creating SQL From Textarea

Post by silenceechoes »

hi,

i have made a search system ,...its like that

i have one table name 'student'

-ID
-Name
-Class

i have textarea where user can search for multiple ids now the problem is how am i going to create a search page..

how to construct the select query....so that it returens results from all the record inserted int the textare.

like this site
http://track.tcs.com.pk/



thanks in advance....!
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Split the data in the textarea, by white-spaces or new lines maybe. Then search the database for them:

Code: Select all

$data = explode("<br>", nl2br($_POST['data']));
$sql = "SELECT blah FROM blah WHERE something = 'this'";
foreach($data as $q){
   $sql .= " AND name = '$q'";
}
mysql_query($sql);
Post Reply