Sunday, 15 February 2015

php - SQL switch statement -



php - SQL switch statement -

( don't know if right asking if possible , how )

so want when page index.php select something, , when jobs.php select else if possible.

i trying execute sql statement, not work.

$sql_q; $path=$_server['php_self']; $page=basename($path); switch("$page") { case 'index.php': $sql_q = 'select * jobs title '%news%'" '; break; case 'jobs.php': $sql_q = 'select * jobs title '%jobs%'" '; break; }

and here:

$getquery = mysql_query("$sql_q limit $p_num, $per_page");

is possible somehow ?

thanks.

you can this:

switch ($page) { case 'index.php': $toselect = '%news%'; break; case 'jobs.php': $toselect = '%jobs%'; break; } $query = sprintf( 'select * `jobs` `title` "%s" limit %s, %s', $toselect, $p_num, $per_page );

also, consider using mysqli* functions, mysql* deprecated.

php select switch-statement

No comments:

Post a Comment