What I'm trying to do currently is have a search function on my site that will look into a local MySQL db, in 1 column. The issue is the end-user could paste 1 item or they could paste 50 for example. And, without creating 50 textbox's I was wondering if it would be possible to make say a large textbox, that would search for a new field based on a space between them, or linebreak. Currently I have two search boxes, one where data is pasted, and the second null(I have null because when I left it blank it search for all(*).
Here is my page.
form action="" method="get">
Paste your ZZZs here: <br>
<input type="text" name="item" id="textbox" maxlength="10" size="10"><br>
<input type="text" name="item2" id="textbox2" value="null" maxlength="10" size="10"><script>document.getElementById('textbox').focus()</script><br />
<input type="submit" value="Submit"/>
</form>
<?php
if (!empty($_REQUEST['item'])) {
$item = mysql_real_escape_string($_REQUEST['item']);
$item2 = mysql_real_escape_string($_REQUEST['item2']);
$sql = "select fcsku, fnsku from oak3_zzz_to_boo WHERE fcsku like '%".$item."%' or fcsku like '%".$item2."%'";
$r_query = mysql_query($sql);
echo "<table border=1>";
echo "<tr><td><b>FcSKU</td><td><b>FnSKU</td></tr>";
while ($row = mysql_fetch_array($r_query)) {
echo "<tr><td>".$row['fcsku']."</td><td>".$row['fnsku']."</td></tr>";
}
}
echo "</table>";
mysql_close();
My Table structure only has 2 columns, FnSKU, and FcSKU
Thanks to the contributors here is the working code!
<form action="" method="get">
Paste your ZZZs here: <br>
<textarea name="item" id="textbox"></textarea>
<script>document.getElementById('textbox').focus()</script><br />
<input type="submit" value="Submit"/>
</form>
<?php
if (!empty($_REQUEST['item'])) {
$search = "\"" . strip_tags(preg_replace("/[\n\r ]/","\", \"",$_REQUEST["item"])) . "\""; // for space as delimiter
##$search = "\"" . strip_tags(str_replace(" ","\", \"",$_REQUEST["item"])) . "\""; // for space as delimiter
$query = "SELECT fcsku, fnsku FROM oak3_zzz_to_boo WHERE fcsku IN ($search)";
$r_query = mysql_query($query);
echo "<table border=1>";
echo "<tr><td><b>FcSKU</td><td><b>FnSKU</td></tr>";
while ($row = mysql_fetch_array($r_query)){
echo "<tr><td>".$row['fcsku']."</td><td>".$row['fnsku']."</td></tr>";
}
}
echo "</table>";
mysql_close();