Jump to content


This topic is now archived and is closed to further replies.


PHP code change MySQL to SQL

Recommended Posts

Hi Guys,
I'm tring to change my code from a MySQL database to an SQL database. The code below should list the members of each department under the department heading. The first block works fine and outputs in the format that I want... the second one just lists the name of the first department 12 times (there are 13 departments in total if that helps).

Working MySQL.

$result = mysql_query("SELECT * FROM tbl_department",$db);
$subresult = mysql_query("SELECT * FROM tbl_telephonenumbers",$db);

while ($row = mysql_fetch_array($result)) {

echo "<table width='250' border=0 class='Body2'>\n";

    printf("<tr><td align=center bgcolor=#CCCCCC><b class='Body2'>%s</b></td></tr>", $row["Department"]);
    $subresult = mysql_query("SELECT * FROM tbl_telephonenumbers",$db);

echo "</table>";
echo "<table width='250' border=0 class='Body2'>\n";

while ($row2 = mysql_fetch_array($subresult)) {
        if ($row['ID'] == $row2['Department']) {
            printf("<tr><td width='150'>%s %s</td>
<td width='50'>%s</td>
<td width='50'>%s</td></tr>",
$row2["First_Name"], $row2["Last_Name"], $row2["DDI"], $row2["Mobile_SD"]);

echo "</table>\n";
    echo '<br><br>';


Broken SQL.

$sql="SELECT * FROM tbl_department";
if (!$result)
      {exit("Error in SQL");}

while (odbc_fetch_row($result))

echo "<table>\n";
echo "<tr><td><b class='Body2'>$Department_Name</b></td></tr>";

$sub_sql="SELECT * FROM qry_Full_Employee_Details";
if (!$subresult)
      {exit("Error in SQL");}


while (odbc_fetch_row($subresult))
                                  if ($DeptID == $Department)
echo "<tr><td>$First_Name $Last_Name</td></tr>";
echo "</table>\n";
                echo '<br><br>';

Can anyone see where the problem is? Any help would be appreciated.


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.