Forum Moderators: coopster
SELECT *
FROM table
WHERE cat_y LIKE '%".$catid."%' ¦¦ cat_x LIKE '%".$catid."%' ¦¦ cat_z LIKE '%".$catid."%'
But the browser turn of by it self if I run the query. What am doing wrong?
Thanks
Seems like you have a fatal error. Would you mind posting some of the code? Also, adding error_reporting [us2.php.net](E_ALL); at the top of your script may shed some light.
$catid = $_POST['catid'];
$subcatid = $_POST['subcatid'];
/* Set current, prev and next page */
$page = (!isset($_GET['page']))? 1 : $_GET['page'];
$prev = ($page - 1);
$next = ($page + 1);
/* Max results per page */
$max_results = 8;
/* Calculate the offset */
$from = (($page * $max_results) - $max_results);
SELECT *
FROM table
WHERE cat_y LIKE '%".$catid."%' ¦¦ cat_x LIKE '%".$catid."%' ¦¦ cat_z LIKE '%".$catid."%'
AND subcat_a LIKE '%".$subcatid."%'
</quote>
Not to much of code, just that for the pagination. An then I runt the same query to get the rows information.
If I remove this part: ¦¦ cat_x LIKE '%".$catid."%' ¦¦ cat_z LIKE '%".$catid."%'
All is working OK, but I had to add a couple of fields for my program.
Thank you for your help.
$catid = mysql_real_escape_string($catid);
$subcatid = mysql_real_escape_string($subcatid);
$query = "SELECT * FROM table WHERE cat_y LIKE '%".$catid."%' ¦¦ cat_x LIKE '%".$catid."%' ¦¦ cat_z LIKE '%".$catid."%' AND subcat_a LIKE '%".$subcatid."%'";
$result = mysql_query($query) or die([url=http://us2.php.net/manual/en/function.mysql-error.php]mysql_error[/url]());
Make sure that one, setting error_reporting to E_ALL doesn't return any errors. Two, that your query actually works. Try your query in the command line if you need validation. mysql_error() will also tell you if anything is wrong with the query.
I hope this has helped some!
It keeps dieing (my browser), but if I change:
From: cat_y LIKE '%".$catid."%' ¦¦ cat_x LIKE '%".$catid."%' ¦¦ cat_z LIKE '%".$catid."%'
To: WHERE (cat_y ¦¦ cat_x ¦¦ cat_z) LIKE '%".$catid."%'
The browser doesn't die, but I get this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '¦¦ cat_x ¦¦ cat_z) LIKE '%1%'
AND subcat_a LIKE '%1%'
AND zip LIKE '%91401%'
' at line 3
Thank you!
Is there any other way you think I can compare these 3 fields to my variable?
$query = "SELECT * FROM table WHERE ((cat_y = '".$catid."') ¦¦ (cat_x = '".$catid."') ¦¦ (cat_z = '".$catid."')) AND subcat_a = '".$subcatid."'";
By the looks of it, you want to check for equality using '=', not LIKE with wildcards, however this is just an assumption.
[added]Make sure you replace the pipe character(¦)if you are going to copy and paste. WebmasterWorld breaks these![/added]
[edited by: eelixduppy at 3:20 am (utc) on Sep. 26, 2006]