Forum Moderators: coopster

Message Too Old, No Replies

Need help with a querry, please.

This is a problem I'm having with a querry when trying to pass URL vars

         

jaykelly450

1:36 am on Nov 23, 2005 (gmt 0)



I'm trying to pass a variable from a previous page "pageid" to this result page. The previous page contains photos. pageid=photonum in the databse. I want this to work so that when pageid is passed it shows the photo that has been clicked on but also shows the next/back buttons to show all the other photos that share the same "artinum" value in the database. I'm new to PHP and am using Dreamweaver. Here is the code I have to get the pageid/photonum and artinum. I appologize for it being so kluged together.

<?php
$colname_Photos = "-1";
if (isset($_GET['pageid'])) {
$colname_Photos = (get_magic_quotes_gpc())? $_GET['pageid'] : addslashes($_GET['pageid']);

mysql_select_db($database_DB, $DB);
$query_Photos = sprintf("SELECT * FROM arti_photos WHERE photonum = '%s'", $colname_Photos);
$Photos = mysql_query($query_Photos, $DB) or die(mysql_error());
$row_Photos = mysql_fetch_assoc($Photos);
$totalRows_Photos = mysql_num_rows($Photos);
$colname_Photos2 = $row_Photos['artinum'];
}

$maxRows_Photos2 = 1;
$pageNum_Photos2 = 0;
if (isset($_GET['pageNum_Photos2'])) {
$pageNum_Photos2 = $_GET['pageNum_Photos2'];
}
$startRow_Photos2 = $pageNum_Photos2 * $maxRows_Photos2;

mysql_select_db($database_DB, $DB);
$query_Photos2 = "SELECT * FROM arti_photos WHERE artinum = '$colname_Photos2'";
$query_limit_Photos2 = sprintf("%s LIMIT %d, %d", $query_Photos2, $startRow_Photos2, $maxRows_Photos2);
$Photos2 = mysql_query($query_limit_Photos2, $DB) or die(mysql_error());
$row_Photos2 = mysql_fetch_assoc($Photos2);

if (isset($_GET['totalRows_Photos2'])) {
$totalRows_Photos2 = $_GET['totalRows_Photos2'];
} else {
$all_Photos2 = mysql_query($query_Photos2);
$totalRows_Photos2 = mysql_num_rows($all_Photos2);
}
$totalPages_Photos2 = ceil($totalRows_Photos2/$maxRows_Photos2)-1;

$queryString_Photos2 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Photos2") == false &&
stristr($param, "totalRows_Photos2") == false) {
array_push($newParams, $param);
}
}
if (count($newParams)!= 0) {
$queryString_Photos2 = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Photos2 = sprintf("&totalRows_Photos2=%d%s", $totalRows_Photos2, $queryString_Photos2);
?>

Thanks,

Jay

coopster

3:32 pm on Nov 24, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld [webmasterworld.com], jaykelly450.

Can you be more specific? Is it the query statement you are struggling with?