Fearpig Posted October 9, 2006 Share Posted October 9, 2006 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.[code]include("../ConnectMySQL.php");$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>';}[/code]Broken SQL.[code]include("../ConnectSQL2005.php");$sql="SELECT * FROM tbl_department";$result=odbc_exec($conn,$sql);if (!$result) {exit("Error in SQL");} $DeptID=odbc_result($result,"Dept");$Department_Name=odbc_result($result,"Description");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"; $subresult=odbc_exec($conn,$sub_sql); if (!$subresult) {exit("Error in SQL");} $Department=odbc_result($subresult,"Department"); $First_Name=odbc_result($subresult,"First_Name"); $Last_Name=odbc_result($subresult,"Last_Name"); while (odbc_fetch_row($subresult)) { if ($DeptID == $Department) { echo "<tr><td>$First_Name $Last_Name</td></tr>"; } } echo "</table>\n"; echo '<br><br>'; }[/code]Can anyone see where the problem is? Any help would be appreciated.CheersTom Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.