Anyone worked with and upload-file-service before?

Hello :slight_smile:

I hope this will not be an unwelcome question on FCC. It’s my coding haven ^.^

I’m using Cloudinary’s file upload service for one of the first times, and I’m getting a very odd behaviour. Please have a look at this page: http://vrentals.co.za/trial/vrentals/cashlisting

If you’ll notice, some of the car images are doubling up and showing 2 (sometimes 3) times. How and why this happens I have no idea. I’m calling the images dynamically with a CSV file and using PHP, like this:

if ($rowImg['status'] == 2) { /* 2 = csv imported image url*/
echo "<img src='".$img_url."' width='225' class='class-".$modelid."'>";
}

where $img_url looks like https://res.cloudinary.com/dhbqncvh6/image/upload/v1545050899/honda_brio.jpg

I don’t see any way the image could double up like the result. How on earth do I find the cause of such behaviour?

Any help would be greatly appreciated.

Can you show all of the code?

Thanks for responding.

This is the full query in PHP, note that a user can upload an image directly on the website or he can upload a CSV file with image urls in them.

$sql = "SELECT * FROM cashlisting";
		if (isset($_GET['sort'])) {
			if ($_GET['sort'] == 'date') {
				$sql .= " ORDER BY last_updated DESC;";
			} else if ($_GET['sort'] == 'model') {
				$sql .= " ORDER BY model;";
			} else {
				$sql .= " ORDER BY last_updated DESC;";
			}
		} else {
			$sql .= " ORDER BY last_updated DESC;";	
		}

	$result = $conn->query($sql);

	while ($row = $result->fetch_assoc()) {
		$modelid = $row['cid']; //get the id of the model
		$img_url = $row['img_url']; //get the img url of the model
		
		echo "
	<div class='listing cashlisting'>
		<p class='header'>".$row['model']." <span class='subtitle mhideFALSE'>".$row['subtitle']."</span></p>
		<div class='listing-img'>
			<div class='listing-img-inner'>";
			$sqlImg = "SELECT * FROM modelimg WHERE modelid='$modelid'"; //comparing image's id to model's id.
			$resultImg = mysqli_query($conn, $sqlImg);
			while ($rowImg = mysqli_fetch_assoc($resultImg)) {
				//$modelid = $row['modelid']; //get the id of the model
				if ($rowImg['status'] == 2) { /* 2 = csv imported image url*/
					echo "<img src='".$img_url."' width='225' class='class-".$modelid."'>";
				} else if ($rowImg['status'] == 0) {
					$filename = "uploads/model".$modelid."*";
					$fileinfo = glob($filename);
					$fileext = explode(".", $fileinfo[0]);
					$fileactualext = $fileext[1];
					if ($filename) {
						echo "<img src='uploads/model".$modelid.".".$fileactualext."?".mt_rand()."' width='225' class='catalog mhideFALSE modalshow'>";
					}
				} else {
					echo "<img src='uploads/placeholder.jpg' width='225' class='catalog mhideFALSE modalshow' >";
				}
			}

I would be inclined to limit the rows to 1 result from the database to make sure you don’t get duplicates.

1 Like

That seems like a great suggestion, will give it a try.

It just needed the LIMIT clause, and I was stumped for 3 days, oh gee wizz! Thank you! :hugs:

1 Like