Page 1 of 1

[SOLVED] LIKE %

Posted: Thu Jun 24, 2004 3:48 am
by ol4pr0
I am trying to make a search form.. with the following query..

however i am kinda stuck on how i can do this..

Code: Select all

// form.. 

if (isset($_POST['submit']))
{
echo '<table><tr>';
require_once('inc/db.inc');
$result = mysql_query('SELECT * FROM table WHERE item1 LIKE '.$_POST['item1'].'% item2 LIKE '.$_POST['item3'].'% item4 LIKE '.$_POST['item4'].'%');
while($row = mysql_fetch_assoc($result)) {
echo '<td><a href="http://'.$_SERVER['HTTP_HOST'].'/index.php">'.$row['something'].'</a></td>';
}
echo '</tr></td></table>';
}

Posted: Thu Jun 24, 2004 3:50 am
by JayBird
Why are you stuck?

Does your query work at all? If so is it returning unexpected results?

Etc etc etc

Mark

Re: LIKE %

Posted: Thu Jun 24, 2004 3:50 am
by feyd
a bit more like:

Code: Select all

// form.. 

if (isset($_POST['submit']))
{
echo '<table><tr>';
require_once('inc/db.inc');
$result = mysql_query('SELECT * FROM table WHERE item1 LIKE '''.$_POST['item1'].'%'' OR item2 LIKE '''.$_POST['item3'].'%'' OR item4 LIKE '''.$_POST['item4'].'%''') or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {
echo '<td><a href="http://'.$_SERVER['HTTP_HOST'].'/index.php">'.$row['something'].'</a></td>';
}
echo '</tr></td></table>';
}
may do it..

Posted: Thu Jun 24, 2004 3:51 am
by ol4pr0
Doesnt work at all.. msyql_assoc error...

right database tho.. connection is made aswell.

Should that work according to u ?

Posted: Thu Jun 24, 2004 3:52 am
by ol4pr0
Feyd i see u used the backslashes.. may i ask why ?

EDIT: coudl i use AND LIKE instead of OR LIKE? to make a what selecter query..

Posted: Thu Jun 24, 2004 3:53 am
by feyd
because I was putting single quote marks into your strings.. you were missing comparison stuff between the item # and the previous like too..

Posted: Thu Jun 24, 2004 4:41 am
by ol4pr0
i figured it out.. tho

Code: Select all

"'.$_POST&#1111;'item'].'%"
Tried yours , either i typed it wrongly over.. or it just didnt work.. after messing around with query from within mysql and trying to get it into the php... i got that as above..

Thanks anyway