mysql - PHP Search Multiple Database -
i trying results of search 2 different database tables.
i getting errors , have no thought why, first time have used union
not sure if syntax
correct, help appreciated.
$raw_results = mysql_query("select * vectors (`name` '%".$query."%') or (`tags` '%".$query."%') or (`image` '%".$query."%') union select * photos (`photo_alt` '%".$query."%')")
the initial error parse error: syntax error, unexpected t_if on line 98
thanks lot
you need able break things downwards can figure out 1 problem @ time.
if using xampp
or have server can utilize phpmyadmin
check whether query works.
first might want split query test each select
separately know both working. after if still have problem union
.
unions
need columns returned equal, if first select
returns 2 columns, sec 1 must homecoming 2.
$raw_results = mysql_query("select `col1a`,`col2a` vectors (`name` '%".$query."%') or (`tags` '%".$query."%') or (`image` '%".$query."%') union select `col1b`,`col2b` photos (`photo_alt` '%".$query."%')")
if vectors
has 3 columns , photos
has 2 columns, want select 3 columns vectors
within bring together can create 3rd column photos
:
select `col1b`,`col2b`,null photos (`photo_alt` '%".$query."%')")
important: stop using mysql. deprecated, , way using unsafe , open sql injection
. utilize pdo
.
php mysql search
No comments:
Post a Comment