to get various parameter without repeat with the function str_repeat
I get various parameter but the while print all of them

Warning: Undefined variable $row in /var/www/html/cocoa/index.php on line 11

Warning: Trying to access array offset on value of type null in /var/www/html/cocoa/index.php on line 11

Deprecated: str_repeat(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/cocoa/index.php on line 11

<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = mysqli_connect("localhost", "root", "P-11fl32fg14", "cocoa");



    $query = "SELECT  type_chocolate.type_chocolate,type_chocolate.type_chocolate  
     FROM type_chocolate";
    $result = mysqli_query($mysqli, $query);
   
    /* numeric array */
    if(str_repeat($row["type_chocolate"], 1))
    {
        
        while ($row = mysqli_fetch_array($result, MYSQLI_BOTH))
        {
       
            printf("%s %s\n","<a href='cocoa_type_chocolate.php?type_chocolate=" .  
            $row["type_chocolate"] . "'>" ,  ucfirst($row["type_chocolate"]) . "</a>");?>  <br> 
<?php      

        }
    }
   
?>

    You are getting the error because $row is not yet set when you use it in the str_repeat() function: it gets set after that in the while loop declaration.

    when I put if inside the while return all of them
    the loop while return all of them; I want just one of each.
    I don't have now any error, but the if it doesn't works

    while ($row = mysqli_fetch_array($result, MYSQLI_BOTH))
        {
            if(str_repeat ($row["type_chocolate"],10))
            {
            printf("%s %s\n","<a href='cocoa_type_chocolate.php?type_chocolate=" .  
            $row["type_chocolate"] . "'>" ,  ucfirst($row["type_chocolate"]) . "</a>");?>  <br> 
    <?php      
            }
        }

      It's not totally clear to me what the goal is here, but I think you could simplify things a bit by letting the SQL remove duplicates via DISTINCT (plus remove the need to fetch the same field twice):

      $query = "SELECT DISTINCT type_chocolate.type_chocolate FROM type_chocolate";
      $result = mysqli_query($mysqli, $query);
      while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
          printf(
              "<a href='cocoa_type_chocolate.php?type_chocolate=%s'>%s</a><br>\n",
              urlencode($row["type_chocolate"]),
              htmlentities(ucfirst($row["type_chocolate"]))
          );
      }
      

      PS: A bit more streamlining since we're only hitting one DB table and only fetching one column:

      $query = "SELECT DISTINCT type_chocolate FROM type_chocolate";
      $result = mysqli_query($mysqli, $query);
      while ($type = mysqli_fetch_column($result)) {
          printf(
              "<a href='cocoa_type_chocolate.php?type_chocolate=%s'>%s</a><br>\n",
              urlencode($type),
              htmlentities(ucfirst($type))
          );
      }
      
        Write a Reply...