-1

I wrote a query and it works fine. But I need some help to edit a part of the php "while".

<?php 

require ('db.inc.php');

echo mysql_error();
?>
<form action="#" method="get">
Kundennr: <input type="text" name="nummer" /><br />
<input type="Submit" value="Absenden" />
</form>

<?php
if ($_GET['nummer'])
{

$gruppe = $_GET['nummer'];
    echo $gruppe.":<br>";
$result = mysql_query("SELECT catalog_product_entity_media_gallery.value, customer_group_code, catalog_product_entity_varchar.value, sku, qty, catalog_product_entity_tier_price.value FROM `catalog_product_entity_tier_price`

JOIN catalog_product_entity on catalog_product_entity.entity_id = catalog_product_entity_tier_price.entity_id

JOIN customer_group ON customer_group.customer_group_id = catalog_product_entity_tier_price.customer_group_id 

JOIN catalog_product_entity_varchar ON catalog_product_entity_varchar.entity_id = catalog_product_entity.entity_id

JOIN catalog_product_entity_media_gallery ON catalog_product_entity_media_gallery.entity_id = catalog_product_entity.entity_id

WHERE customer_group_code = '$gruppe' AND catalog_product_entity_varchar.attribute_id = 71");
while ($row = mysql_fetch_array($result))
{
        $bilddaten = $row[0];
         $ids = $row[1];
        $ids1 = $row[2];
        $ids2 = $row[3];
        $ids3 = $row[4];
        $ids4 = $row[5];

    echo "<img src='http://localhost/media/catalog/product/cache/1/thumbnail/60x60/9df78eab33525d08d6e5fb8d27136e95/".$bilddaten."' >";
    echo "Art.Nr.: ".$ids2." Bezeichung: ".$ids1." ->Menge: ".$ids3." Preis: ".$ids4."<br><br>";
}
}

?>

My Problem is that I want for the variable $bilddaten only the first value. How can I Edit the while so that take only the first from the value from the $bilddaten?

Result: enter image description here

In the Picture you see the result in the browser. The problem is that row repeated 3 times for each picture URL in the Database. But I need only the first picture for each loop.

Here is the result of the query in the the database. I need only the yello colored. You see in the column with duplicate No. (red-colored): Database result

Marcel
  • 13
  • 3
  • Do you mean that you want to not do the whole while loop but only the first iteration? – Med May 16 '18 at 09:57
  • 2
    Your code is vulnerable to [SQL injection](https://en.wikipedia.org/wiki/SQL_injection) attacks. You should use [mysqli](https://secure.php.net/manual/en/mysqli.prepare.php) or [PDO](https://secure.php.net/manual/en/pdo.prepared-statements.php) prepared statements with bound parameters as described in [this post](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). –  May 16 '18 at 09:59

1 Answers1

0
$i=0;
while ($row = mysql_fetch_array($result))
{
     if($bilddaten=='' && $i==0)
     {
        $bilddaten = $row[0];
     }
         $ids = $row[1];
$i++;
}
Hosain Ahmed
  • 115
  • 6