Hi All,
I'm having trouble printing values from a function into a table.
I have a page that displays the data from a table:
<?php
// Add data for llwyfan result
include '../connect.php';
$sql = "SELECT * FROM request";
$results = mysql_query($sql) or die ("MG - Invalid query: " . mysql_error());
echo "<table border=1>\n<tr>\n";
echo "<th>Record No</th><th>Rhif Ffôn</th><th>Rhwydwaith</th><th>Neges</th><th>Rhif y gystadleuaeth</th>\n";
echo "</tr>\n";
include 'function.php';
while($row = mysql_fetch_array($results)){
$net = network($row["network"]);
echo "<tr>\n<td>" . $row["id_request"];
echo "</td><td>" . $row["source"];
echo "</td><td>";
echo $net;
echo "</td><td>" . $row["message"];
echo "</td><td>" . $row["comp_number"];
echo "</td>\n</tr>\n";
}
echo "</table>";
?>
and here is the function:
<?php
function network($code){
if ($code == 10) {
$netname = "O2";
}
if ($code == 15) {
$netname = "Vodaphone";
}
if ($code == 20) {
$netname = "3";
}
if ($code == 30) {
$netname = "T-Mobile/Virgin";
}
if ($code == 33) {
$netname = "Orange";
}
if ($code == 99) {
$netname = "Arall/Other";
}
echo $netname;
}
?>
The function is to change the number value stored in the database to a string. But the table does not display properly. The html code is returned like this
<tr>
<td>1</td><td>447815891441</td><td></td><td>URDD 482</td><td>482</td>
</tr>
Orange<tr>
In this case $net is printed (as Orange) after the </tr> tag.
Can someone explain what I'm doing wrong?
Thanks,
Mei