A
Anonymous
Guest
edited
<?php
if (isset($_POST['submit'])) {
$db = mysql_connect("localhost", "login", "pass");
mysql_select_db("dbasdf",$db);
$sql = "INSERT INTO itemsearch (name,url,picurl,str,sta,dex,agi,wis,int,cha,effone,efftwo,effthree) VALUES ('" . $_POST['name'] . "','" . $_POST['url'] . "','" . $_POST['picurl'] . "','" . $_POST['str'] . "','" . $_POST['sta'] . "','" . $_POST['dex'] . "','" . $_POST['agi'] . "','" . $_POST['wis'] . "','" . $_POST['int'] . "','" . $_POST['cha'] . "','" . $_POST['effone'] . "','" . $_POST['efftwo'] . "','" . $_POST['effthree'] . "')";
}
?>
$SQL = "SELECT * FROM itemsearch WHERE itemname LIKE \"%$user_input%\"";
$SQL = "SELECT * FROM itemsearch WHERE itemname LIKE '%$user_input%' AND itemname1 LIKE '%$user_input1%' OR itemname1 LIKE '%$user_input1%'";
$SQL = "SELECT itemname, itemname1 FROM itemsearch WHERE itemname2 LIKE '%$user_input2%'";
$yoursearch = $_POST['fieldname'];
//now break the items separated by " "
$searchlist = explode (" ", $yoursearch);
now u build the query
foreach ($searchlist as $key => $value) {
$sqlsearch .= " like \"%$value%\" or";
}
now your query should be something like this....
$sql = "selelct .... where fieldname $sqlsearch";
//be sure you remove the last OR from the query statement...
//i supose that should suffice your problem....!
...
<input name="inputs[effthree]">
...
<?php
// if submit
if(array_key_exists('submit', $_POST) && !empty($_POST['submit'])){
$inc = 0;
$sqlsearch = '';
// count your array -> form input´s
$count = count($_POST['inputs']);
/* Will create that part of the query with $key(or table field name) in it. E.g: name LIKE 'John' OR ...*/
foreach ($_POST['inputs'] as $key => $value) {
$inc ++;
if($inc == $count){
$sqlsearch .= $key . " LIKE '%$value%'";
}else{
$sqlsearch .= $key . " LIKE '%$value%' OR ";
}
}
// Your query
$sql = "SELECT something FROM table WHERE $sqlsearch";
}
?>