Reputation: 37
( I don't know if this is correct i am just asking if possible and how )
So what i want to do is when page is index.php select something, and when jobs.php select something else if possible.
I am trying to execute this SQL statement, but that does not work.
$sql_q;
$path=$_SERVER['PHP_SELF'];
$page=basename($path);
switch("$page")
{
case 'index.php':
$sql_q = 'SELECT * FROM jobs WHERE title LIKE '%news%'" ';
break;
case 'jobs.php':
$sql_q = 'SELECT * FROM jobs WHERE title LIKE '%jobs%'" ';
break;
}
And here:
$getquery = mysql_query("$sql_q LIMIT $p_num, $per_page");
Is that possible somehow ?
Thanks.
Upvotes: 0
Views: 59
Reputation: 4025
You can do it like this:
switch ($page) {
case 'index.php':
$toSelect = '%news%';
break;
case 'jobs.php':
$toSelect = '%jobs%';
break;
}
$query = sprintf(
'SELECT * FROM `jobs` WHERE `title` LIKE "%s" LIMIT %s, %s',
$toSelect,
$p_num,
$per_page
);
Also, consider using mysqli* functions, as mysql* are deprecated.
Upvotes: 1