-1

Can someone explain me why this query is not working ? I tested the query in phpmyadmin and its working but inside the php code its not returning anything, no result and no rows, I even test if the query is executed and it returns false.


$queryAuchan = "SELECT dtOrt, tblport.dtName, dtGebäude, fiStandortcode
FROM tblport, tblstation, tblstandort WHERE tblport.idPort = tblstation.fiPort AND 
tblstandort.idStandortcode = tblstation.fiStandortcode AND fiStandortcode = 1 AND tblport.dtPortstatus = 0";

$resultAuchan = mysqli_query($mysqli, $queryAuchan);

$numres = mysqli_num_rows($resultAuchan);

echo "<table border='0' style='text-align: center'>";
echo "<tr>";
echo "<th style='text-align: center'>Ort</th>";
echo "<th style='text-align: center'>Port</th>";
echo "<th style='text-align: center'>Gebäude</th>";
echo "<th style='text-align: center'>Reservieren</th>";
echo "</tr>";

for ($i = 0; $i < $numres; $i++) {

    $row = mysqli_fetch_array($resultAuchan);
    $string = $row[1];
    $portnr = substr($string, -1);

    $location = $row['dtOrt'];
    $portname = $row['dtName'];
    $building = $row['dtGebäude'];

    echo "<tr>";
    echo "<td>" . $location . "</td>";
    echo "<td>" . $portname . "</td>";
    echo "<td>" . $building . "</td>";
    echo "<td><button type='submit' name='activate' value='" . $portnr . "'>Activate</button>";
    echo "</tr>";

}

echo "</table>";
  • What does `mysqli_error($mysqli)` reveal? – Funk Forty Niner May 28 '20 at 00:59
  • Please learn to use ANSI JOIN instead of cross products, it makes your queries easier to understand. – Barmar May 28 '20 at 01:17
  • 1
    I suspect the problem is due to having a character with diacritical in one of the column names. You probably haven't set the correct CHARSET option when connecting to MySQL from PHP. – Barmar May 28 '20 at 01:18

1 Answers1

-1

As @Barmar already said, the Problem is the "ä" in dtGebäude. Never use umlauts in a column name.

If you still want to, you have to use mysqli_set_charset($mysqli, YOUR_CHARSET) after connecting to your database. Also, change the charset on your table/column.

You could use utf8_unicode_ci, or utf8mb4_unicode_ci as example.

https://www.php.net/manual/de/mysqli.set-charset.php

Luka Theisen
  • 181
  • 1
  • 6