pukstpr12 Posted September 14, 2007 Share Posted September 14, 2007 ok, i am a bit of a php newbie here so i am hoping this is something that can be figured out pretty easily I created a website to display pictures i have taken. I create the rows in phpmyadmin with the image source and insert the code into the body. /photo.php?id=1 displays picture 1, but the problem is that /photo.php?id=2 displays picture 1 also, despite a different image source in the row. The thing is also, that /photo.php?id=3 displays image 1 also even though there is no row 3 in the database. Can anyone help? <?php echo $row_Photo['id']; ?> <?php echo $row_Photo['photopath']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/69391-php-displaying-id1-for-all-ids/ Share on other sites More sharing options...
Psycho Posted September 14, 2007 Share Posted September 14, 2007 No way to help without seeing some code. Quote Link to comment https://forums.phpfreaks.com/topic/69391-php-displaying-id1-for-all-ids/#findComment-348644 Share on other sites More sharing options...
hcdarkmage Posted September 14, 2007 Share Posted September 14, 2007 Please show your problem code. Then the help you need may be revealed. Quote Link to comment https://forums.phpfreaks.com/topic/69391-php-displaying-id1-for-all-ids/#findComment-348645 Share on other sites More sharing options...
janim Posted September 14, 2007 Share Posted September 14, 2007 you must show the rest of your code but i think you didn't told the page wich id you want do you have something like this in your page include("config.php"); $id=$_GET['id']; mysql_connect($server, $datauser, $datapass) or die (mysql_error()); $result = mysql_db_query($database, "select * from $table where id='$id'") or die (mysql_error()); if (mysql_num_rows($result)) { $qry = mysql_fetch_array($result); $img=$qry['your image name or whatever in your sql']; then try <img src="<?php echo $img; ?>"/> Quote Link to comment https://forums.phpfreaks.com/topic/69391-php-displaying-id1-for-all-ids/#findComment-348656 Share on other sites More sharing options...
pukstpr12 Posted September 14, 2007 Author Share Posted September 14, 2007 Sorry, here is the full code <?php require_once('Connections/Photo.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $currentPage = $_SERVER["PHP_SELF"]; $maxRows_Photo = 1; $pageNum_Photo = 0; if (isset($_GET['pageNum_Photo'])) { $pageNum_Photo = $_GET['pageNum_Photo']; } $startRow_Photo = $pageNum_Photo * $maxRows_Photo; mysql_select_db($database_Photo, $Photo); $query_Photo = "SELECT * FROM photos"; $query_limit_Photo = sprintf("%s LIMIT %d, %d", $query_Photo, $startRow_Photo, $maxRows_Photo); $Photo = mysql_query($query_limit_Photo, $Photo) or die(mysql_error()); $row_Photo = mysql_fetch_assoc($Photo); if (isset($_GET['totalRows_Photo'])) { $totalRows_Photo = $_GET['totalRows_Photo']; } else { $all_Photo = mysql_query($query_Photo); $totalRows_Photo = mysql_num_rows($all_Photo); } $totalPages_Photo = ceil($totalRows_Photo/$maxRows_Photo)-1; $queryString_Photo = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_Photo") == false && stristr($param, "totalRows_Photo") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_Photo = "&" . htmlentities(implode("&", $newParams)); } } $queryString_Photo = sprintf("&totalRows_Photo=%d%s", $totalRows_Photo, $queryString_Photo); ?> Quote Link to comment https://forums.phpfreaks.com/topic/69391-php-displaying-id1-for-all-ids/#findComment-348657 Share on other sites More sharing options...
MadTechie Posted September 14, 2007 Share Posted September 14, 2007 change $query_Photo = "SELECT * FROM photos"; to $ID = (int)$_GET['ID']; $query_Photo = "SELECT * FROM photos WHERE ID=$ID"; or probably better to use: $ID = (int)$_GET['ID']; $query_Photo = (isset($_GET['ID']))?"SELECT * FROM photos WHERE ID=$ID":"SELECT * FROM photos"; Quote Link to comment https://forums.phpfreaks.com/topic/69391-php-displaying-id1-for-all-ids/#findComment-348682 Share on other sites More sharing options...
pukstpr12 Posted September 14, 2007 Author Share Posted September 14, 2007 change $query_Photo = "SELECT * FROM photos"; to $ID = (int)$_GET['ID']; $query_Photo = "SELECT * FROM photos WHERE ID=$ID"; or probably better to use: $ID = (int)$_GET['ID']; $query_Photo = (isset($_GET['ID']))?"SELECT * FROM photos WHERE ID=$ID":"SELECT * FROM photos"; tried, but to no avail. still have the problem. thank you for your response though. Quote Link to comment https://forums.phpfreaks.com/topic/69391-php-displaying-id1-for-all-ids/#findComment-348696 Share on other sites More sharing options...
BlueSkyIS Posted September 14, 2007 Share Posted September 14, 2007 Have you looked at the data to make sure the IDs are actually different? Quote Link to comment https://forums.phpfreaks.com/topic/69391-php-displaying-id1-for-all-ids/#findComment-348725 Share on other sites More sharing options...
pukstpr12 Posted September 15, 2007 Author Share Posted September 15, 2007 Have you looked at the data to make sure the IDs are actually different? Yes I have. I also had a line that displayed the ID# next to the image. Even when the address bar read id=2, the picture and the ID# next to the image belonged to that of id=1. Quote Link to comment https://forums.phpfreaks.com/topic/69391-php-displaying-id1-for-all-ids/#findComment-348751 Share on other sites More sharing options...
pukstpr12 Posted September 15, 2007 Author Share Posted September 15, 2007 The code was generated using recordset in dreamweaver if that helps. Quote Link to comment https://forums.phpfreaks.com/topic/69391-php-displaying-id1-for-all-ids/#findComment-348816 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.