I have a mysql data table with "itemLevels" (numbers). So if i echo the itemlevels out i want that they get replaced with a certain text.
itemLevels 1 => Text1; itemLevels 2 => Text2; itemLevels => Text3
At the moment i have the following code:
<?php
$con = mysqli_connect("localhost","XXXXXX","XXXXX","XXXXX");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
/* change character set to utf8 */
if (!mysqli_set_charset($con, "utf8")) {
printf("Error loading character set utf8: %s\n", mysqli_error($con));
exit();
} else {
}
$sql = "SELECT * FROM TEST WHERE name=test";
$result = mysqli_query($con,$sql)or die(mysqli_error());
echo "<table>";
while($row = mysqli_fetch_array($result)) {
$name= $row['name'];
$itemLevel= $row['itemLevel'];
echo
"<tr><td class='name'>".$name."</td></tr>
<tr><td class='name'>Gegenstandsstufe ".$itemLevel."</td></tr>
</tr>";
}
echo "</table>";
mysqli_close($con);
?>
I´ve read about "php str_replace" but im not sure if it is the right idea and how to use it in my code.