Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Thu Jun 24, 2004 3:48 am
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.
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Thu Jun 24, 2004 3:50 am
Why are you stuck?
Does your query work at all? If so is it returning unexpected results?
Etc etc etc
Mark
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jun 24, 2004 3:50 am
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.
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Thu Jun 24, 2004 3:51 am
Doesnt work at all.. msyql_assoc error...
right database tho.. connection is made aswell.
Should that work according to u ?
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Thu Jun 24, 2004 3:52 am
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..
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jun 24, 2004 3:53 am
because I was putting single quote marks into your strings.. you were missing comparison stuff between the item # and the previous like too..
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Thu Jun 24, 2004 4:41 am
i figured it out.. tho
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