Jump to content

[SOLVED] mysql loop or while or something related, not working


Recommended Posts

this is my code

<?php
if (isset($_GET['image_id']))
{
if ((int) $_GET['image_id'] > 0) 
{

$imageid = $_GET['image_id'];
$sql = "SELECT * FROM `hayleyimages` WHERE `image_id`='{$imageid}' LIMIT 0,1;";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$imageprofname = $row['image_name'];
$imageprofcaption = $row['image_caption'];
$imageproflink = $row['image_link'];
echo "$imageprofname<br>$imageprofcaption<br>";
?>
<table align="center" border="1"><th>Image<?php echo "$imageprofname"; ?></th>
<tr><td><?php echo ' <img src="'.$rows['image_link'].'"width="200px" /></a>'; ?></td><td><?php echo 'ID'.$rows['image_id'].''; ?></td></tr><td><?php echo ' <a href="'.$rows['image_link'].'" rel="lightbox" title="'.$rows['image_caption']. '" >'.$rows['image_name']. ' </a>'; ?></td><td><br /></td></tr>
</table>
<?php
	if (mysql_num_rows($result) < 1) {
		 echo 'This ID does not exist in the database<br>';
		 echo "<a href=\"index.php\">Return to Image Page</a>";
		 exit();
	}
exit();
}
	else {
	 echo "Unknown Image ID! <br />";
	 echo "<a href=\"index.php\">Return to Image Page</a>";
	 exit();
	}
}
//No ID passed to page, display user list:
$query = "SELECT image_id, image_name, image_link, image_caption FROM `hayleyimages`";
$result = mysql_query($query) or die("Error:" . mysql_error());

if (mysql_num_rows($result) > 0) {
	while($rows=mysql_fetch_array($result)){ // Start looping table row
	?>
	<table align="center" border="1"><th>Images</th>
	<tr><td><?php echo ' <a href="?image_id'.$rows['image_id'].'">'.$rows['image_name']. ' Details</a>'; ?></td><td><?php echo ' <a href="'.$rows['image_link'].'" rel="lightbox" title="'.$rows['image_caption']. '" >'.$rows['image_name']. ' </a>'; ?></td><td><?php echo ' <img src="'.$rows['image_link'].'"width="200px" /></a>'; ?><br /></td></tr>
	</table>
	<?php
	}
		if (mysql_num_rows($result) < 1) {
		echo "No Images To Display";
		}
}
mysql_close();
?>

 

But this is not working, the page has a table with a dynamic link in it, this links address is http://hayley.awardspace.com?image_id(then the image id number)

but when you click on the link it has the same content, it shouldn't.

the URL changes in the address bar, but the page remains unchanged .

any ideas?

Link to comment
Share on other sites

Im re-writting your query, just to simplify it:

 

$sql = "SELECT * FROM hayleyimages WHERE image_id=$imageid";

 

It doesnt need smart quotes (`), curly braces on a variable, single quotes on an int variable, LIMIT 0,1 can be written LIMIT 1, the LIMIT isnt needed as a where id=xx will return only one value (1 id for 1 row) and u dont need to have a semicolon in a query.

 

Anyway it cant work as the fetched array returned by the database is assigned to $row and below ure using $rows['image_link'], $rows['image_id'] etc.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.