I rewrote your code, this should work. And for god's sake, escape your inputs, guys! >:0
<?php
require_once('Connections/phptoConn.php');
require_once('includes/tng/tNG.inc.php');
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_photoConn = 100;
$pageNum_photoConn = 0;
if (isset($_GET['pageNum_photoConn'])) {
$pageNum_photoConn = $_GET['pageNum_photoConn'];
}
$startRow_photoConn = $pageNum_photoConn * $maxRows_photoConn;
mysql_select_db($database_phptoConn, $phptoConn);
// my main change is here
// checks if get[like] has been set, if it has, it includes it in a where statement
if (isset($_GET['like'])) {
$like = 'WHERE img_cat LIKE '.mysql_real_escape_string($_GET['like']);
}
// otherwise blanks out the variable
else {
$like = '';
}
// and appends it to your query
$query_photoConn = "SELECT * FROM usr_img".$like;
// this would yield:
// $query_photoConn = "SELECT * FROM user_img" . ' WHERE img_cat LIKE banana';
// if ?like=banana were passed, and:
// $query_photoConn = "SELECT * FROM user_img" . ''; (in effect) if ?like is not set
$query_limit_photoConn = sprintf("%s LIMIT %d, %d", $query_photoConn, $startRow_photoConn, $maxRows_photoConn);
$photoConn = mysql_query($query_limit_photoConn, $phptoConn) or die(mysql_error());
$row_photoConn = mysql_fetch_assoc($photoConn);
if (isset($_GET['totalRows_photoConn'])) {
$totalRows_photoConn = $_GET['totalRows_photoConn'];
} else {
$all_photoConn = mysql_query($query_photoConn);
$totalRows_photoConn = mysql_num_rows($all_photoConn);
}
$totalPages_photoConn = ceil($totalRows_photoConn/$maxRows_photoConn)-1;
$queryString_photoConn = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_photoConn") == false &&
stristr($param, "totalRows_photoConn") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_photoConn = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_photoConn = sprintf("&totalRows_photoConn=%d%s", $totalRows_photoConn, $queryString_photoConn);
?>
Edit: you just beat me 😛