Hi I am getting very frustrated with my php code I am relitivaly new to php and need a little help displaying multiple results from mysql within the one page and it wont do it!! what am I missing??

I am displaying the results with this code but feel I must missing something from one or another part of my code??

Please help me out

<?php echo $image; ?>
<?php

$productid = $_GET['id'];

$query = "SELECT * FROM shop_products WHERE productid = '" . $productid . "'";
$result = mysql_query($query) or die( "An error has occured: " .mysql_error (). ":" .mysql_errno ());
if (mysql_num_rows($result) > 0)
{
	while ($row = mysql_fetch_array($result))
	{
		// Get an image 
		$queryi = "SELECT filename FROM images WHERE productid = '" . $row['productid'] . "' LIMIT 0,4";
		$resulti = mysql_query($queryi) or die( "An error has occured: " .mysql_error (). ":" .mysql_errno ());
		$tweener = mysql_fetch_row($resulti);
		$filename = $tweener[0];
		
		
		if ($filename != "") 
		{
			// Resize thumbs ready for display
			$imagesizer = getimagesize($root . 'admin/uploads/' . $filename); 
			$imgrs = imageResize($imagesizer[0], $imagesizer[1], 300);
			$image = '<img src="' . $root . 'admin/uploads/' . $filename . '" alt="' . $row['productid'] . '" ' . $imgrs . ' />';
			
		}
		else
		{
			$image = '<img src="' . $root . 'assets/no-image-large.jpg" alt="No Image Available" />';
		}
		
		
		?>

Try this

// Get an image 
		$queryi = "SELECT filename FROM images WHERE productid = '" . $row['productid'] . "' LIMIT 0,4";
		$resulti = mysql_query($queryi) or die( "An error has occured: " .mysql_error (). ":" .mysql_errno ());
		
		while ($tweener=mysql_fetch_array($result)) 
{
		if ($tweener['filename'] != "") 
		{
			// Resize thumbs ready for display
			$imagesizer = getimagesize($root . 'admin/uploads/' . $tweener['filename']); 
			$imgrs = imageResize($imagesizer[0], $imagesizer[1], 300);
			$image = '<img src="' . $root . 'admin/uploads/' . $tweener['filename'] . '" alt="' . $row['productid'] . '" ' . $imgrs . ' />';
			
		}
		else
		{
			$image = '<img src="' . $root . 'assets/no-image-large.jpg" alt="No Image Available" />';
		}
}

well the code I assume is working no parse errors as such however it will not display any of the 4 images in the database?? I assume I wouls still use the $image mark to define where I want them to be displayed??

Or am I still missing something?

Is the link to where the images are stored definitely correct, including your $root variable?

Is the link to where the images are stored definitely correct, including your $root variable?

Yes my $root is correct and so is the image url??

well the code I assume is working no parse errors as such however it will not display any of the 4 images in the database?? I assume I wouls still use the $image mark to define where I want them to be displayed??

Yes you need to echo the $image where you want it in the page. Another thought - have you checked your source code to make sure your page is even getting to where it should display the images without any errors?

Yes you need to echo the $image where you want it in the page. Another thought - have you checked your source code to make sure your page is even getting to where it should display the images without any errors?

well the source is onlt a div with some style attributes and the $image to echo the images which is another thing should the $image variable display all the images on the page instead of just one of them??

Right PROGRESS!! have got one images to display now bearing in mind it is the last image to be uploaded I am guessing that it is looping otherwise it would stop at the first to be uploaded?? however it is still only displaying one image... any ideas?

OK, I am literally just looking at things by a process of elimination at the moment - are all your filenames different? I am wondering if you are using your productid as your image filename which would then only return the last record / image??

Yes all the file names are different just checked in the DB the query calls by product ID but the file names are different

SOLUTION!!

this works great for what I need.

<?php

$productid = $_GET['id'];

$query = "SELECT * FROM shop_products WHERE productid = '" . $productid . "'";
$result = mysql_query($query) or die( "An error has occured: " .mysql_error (). ":" .mysql_errno ());
if (mysql_num_rows($result) > 0)
{
	while ($row = mysql_fetch_array($result))
	{
		$queryi = "SELECT filename FROM images WHERE productid = '" . $row['productid'] . "' LIMIT 0,4";
$resulti = mysql_query($queryi) or die( "An error has occured: " .mysql_error (). ":" .mysql_errno ());
 
while ($tweener=mysql_fetch_array($resulti))
{
if ($tweener['filename'] != "")
{
// Resize thumbs ready for display
$imagesizer = getimagesize($root . 'admin/uploads/' . $tweener['filename']);
$imgrs = imageResize($imagesizer[0], $imagesizer[1], 200);

echo <div>'<img src="' . $root . 'admin/uploads/' . $tweener['filename'] . '" alt="' . $tweener['productname'] . '" ' . $imgrs . ' />';
 
}
else
{
$image = '<img src="' . $root . 'assets/no-image-large.jpg" alt="No Image Available" />';

}
}
		
		
		?>

THANKYOU SIMPLEPIXIE FOR YOUR HELP WITH MUCH GRATITUDE!!:)

I presume you have run your query in the database to make sure you have no errors?

Also check in the PHP that you are getting 4 rows returned and echo out the actual filenames

$total_rows=0;
$queryi = "SELECT filename FROM images WHERE productid = '" . $row['productid'] . "' LIMIT 0,4";
		$resulti = mysql_query($queryi) or die( "An error has occured: " .mysql_error (). ":" .mysql_errno ());
$total_rows=mysql_num_rows($resulti);
echo $total_rows;
while ($tweener=mysql_fetch_array($result)) 
{
echo $tweener['filename'].'<br`>';		
if ($tweener['filename'] != "") 
		{
			// Resize thumbs ready for display
			$imagesizer = getimagesize($root . 'admin/uploads/' . $tweener['filename']); 
			$imgrs = imageResize($imagesizer[0], $imagesizer[1], 300);
			$image = '<img src="' . $root . 'admin/uploads/' . $tweener['filename'] . '" alt="' . $row['productid'] . '" ' . $imgrs . ' />';
 
		}
		else
		{
			$image = '<img src="' . $root . 'assets/no-image-large.jpg" alt="No Image Available" />';
		}
}

Sorry, I missed that you had solved before writing this :-)

Hi I am getting very frustrated with my php code I am relitivaly new to php and need a little help displaying multiple results from mysql within the one page and it wont do it!! what am I missing??

I am displaying the results with this code but feel I must missing something from one or another part of my code??

Please help me out

<?php echo $image; ?>
<?php

$productid = $_GET['id'];

$query = "SELECT * FROM shop_products WHERE productid = '" . $productid . "'";
$result = mysql_query($query) or die( "An error has occured: " .mysql_error (). ":" .mysql_errno ());
if (mysql_num_rows($result) > 0)
{
	while ($row = mysql_fetch_array($result))
	{
		// Get an image 
		$queryi = "SELECT filename FROM images WHERE productid = '" . $row['productid'] . "' LIMIT 0,4";
		$resulti = mysql_query($queryi) or die( "An error has occured: " .mysql_error (). ":" .mysql_errno ());
		$tweener = mysql_fetch_row($resulti);
		$filename = $tweener[0];
		
		
		if ($filename != "") 
		{
			// Resize thumbs ready for display
			$imagesizer = getimagesize($root . 'admin/uploads/' . $filename); 
			$imgrs = imageResize($imagesizer[0], $imagesizer[1], 300);
			$image = '<img src="' . $root . 'admin/uploads/' . $filename . '" alt="' . $row['productid'] . '" ' . $imgrs . ' />';
			
		}
		else
		{
			$image = '<img src="' . $root . 'assets/no-image-large.jpg" alt="No Image Available" />';
		}
		
		
		?>
<?php

$productid = $_GET['id'];
if(!ctype_digit($productid)){$productid = 1;}

$query = "SELECT * FROM shop_products WHERE productid = {$productid}";
$result = mysql_query($query) or die( "An error has occured: " .mysql_error (). ":" .mysql_errno ());
if(mysql_num_rows($result) > 0){
	while ($row = mysql_fetch_array($result)){
		// Get an image 
		$queryi = "SELECT `filename` FROM images WHERE productid = {$row['productid']} LIMIT 0,4";
		$resulti = mysql_query($queryi) or die( "An error has occured: " .mysql_error (). ":" .mysql_errno ());
		//you want to loop through the 4 images not pull 1
		while($tweener = mysql_fetch_row($resulti)){
			$filename = $tweener[0];
			if ($filename != ""){
				// Resize thumbs ready for display
				$imagesizer = getimagesize($root . 'admin/uploads/' . $filename); 
				$imgrs = imageResize($imagesizer[0], $imagesizer[1], 300);
				$image = '<img src="' . $root . 'admin/uploads/' . $filename . '" alt="' . $row['productid'] . '" ' . $imgrs . ' />';
			}else{
				$image = '<img src="' . $root . 'assets/no-image-large.jpg" alt="No Image Available" />';
			}
		}
	}
}else{
	//no rows
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.