[Solved] php and mysqli help needed


The problem is that you are getting multiple rows back and storing your id in one variable that gets overwritten every loop.

I would recommend you create a class (if u are going the OO way) and add that to the list instead

$sortedData = [];

class Fotograf {
    public $Id;
    public $Firma;
}

// organiser 
foreach ($data as $d)
{
    $obj = new Fotograf();
    $obj->Id = $d['id'];
    $obj->Firma = $d['firma'];
    $sortedData[$d['sted']][] = $obj;   
}

From there you can access the object itself and now have the Id variable together with the Place variable. Now access it as such:

// output
foreach ($sortedData as $place => $userNames)
{
    echo '<h3>' . $place . '</h3>';

    foreach ($userNames as $userName)
    {

        echo '<div><p><a href="https://stackoverflow.com/questions/42783897/fotograf.php?id=". $userName->Id .'"><strong>' . $userName->Firma . ' </strong></a></div>';
    }

}

2

solved php and mysqli help needed