Jump to content


Photo

PHP code change MySQL to SQL


  • Please log in to reply
No replies to this topic

#1 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 09 October 2006 - 11:08 AM

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.
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>';
}




Broken SQL.
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>';
		}

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

Cheers
Tom
"Whats wrong with the cat?" - Mrs Schrödinger




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users