[SOLVED] LIKE %

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
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

[SOLVED] LIKE %

Post 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>';
}
Last edited by ol4pr0 on Thu Jun 24, 2004 4:44 am, edited 1 time in total.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Why are you stuck?

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

Etc etc etc

Mark
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Re: LIKE %

Post 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..
Last edited by feyd on Thu Jun 24, 2004 3:52 am, edited 2 times in total.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Doesnt work at all.. msyql_assoc error...

right database tho.. connection is made aswell.

Should that work according to u ?
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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
Post Reply