scarezekiel Posted June 5, 2012 Share Posted June 5, 2012 okay so my current problem is my table only shows (refer photo 1) this is the code that needs to be altered. <?php require("html2fpdf.php"); $district = trim($_POST[district]); $server = ''; $username = ''; $password = ''; $database_name=''; $dbconn = mysql_connect($server, $username,$password,false) or die("Could not establish connection"); mysql_select_db($database_name, $dbconn) or die ("Could not select database"); if (!$dbconn) { die('Something went wrong while connecting to MSSQL'); } ob_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> <title></title> </head> <body> <table style="text-align: left; width: 715px; height: 32px;" border="1" cellpadding="2" cellspacing="2"> <tbody> <tr> <td colspan="2" rowspan="1" style="font-style: italic;">List-Location</td> </tr> <tr> <td style="font-style: italic;">code</td> <td style="font-style: italic;">description</td> <td style="font-style: italic;">districtid</td> </tr> <? $query="SELECT * FROM xtbllocation LEFT JOIN xtbldistrict ON xtbllocation.districtid = xtbldistrict.id"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { $code = $row['code']; $description = $row['description']; $districtid = $row['districtid']; echo "<tr><td>$code</td>"; echo "<td>$description</td></tr>"; echo "<td>$districtid</td></tr>"; } ?> </tbody> </table> <br> </body> </html> <?php $var = ob_get_clean(); $pdf = new HTML2FPDF('P', 'mm', 'Letter'); $pdf->AddPage(); $pdf->WriteHTML($var); $pdf->Output('test.pdf', 'I'); ?> okay based on photo 1..i need to change the districtid with description from another table that is called tbldistrict photo2(tbllocation) photo3(tbldistrict) okay so i need the DESCRIPTION from tbldistrict to replace DISTRICTID as in photo 1.. how do i do the query..n the codes to display it. please teach me. im new.. Quote Link to comment Share on other sites More sharing options...
smoseley Posted June 5, 2012 Share Posted June 5, 2012 Substitute this in place of the equivalent section of your code: <? $query="SELECT l.*, d.description AS district FROM xtbllocation AS l LEFT JOIN xtbldistrict AS d ON l.districtid = d.id"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { $code = $row['code']; $description = $row['description']; $district = $row['district']; echo "<tr><td>$code</td>"; echo "<td>$description</td></tr>"; echo "<td>$district</td></tr>"; Quote Link to comment Share on other sites More sharing options...
scarezekiel Posted June 5, 2012 Author Share Posted June 5, 2012 it doesnt work Quote Link to comment Share on other sites More sharing options...
smoseley Posted June 5, 2012 Share Posted June 5, 2012 What does it do? Are you sure you replaced your code with the code I gave you? Quote Link to comment Share on other sites More sharing options...
Illusion Posted June 5, 2012 Share Posted June 5, 2012 i think join condition should be on code column instead of id $query="SELECT l.*, d.description AS district FROM xtbllocation AS l LEFT JOIN xtbldistrict AS d ON l.code = d.code"; Quote Link to comment Share on other sites More sharing options...
scarezekiel Posted June 5, 2012 Author Share Posted June 5, 2012 yep..sure.but still..doesnt work Quote Link to comment Share on other sites More sharing options...
smoseley Posted June 5, 2012 Share Posted June 5, 2012 i think join condition should be on code column instead of id $query="SELECT l.*, d.description AS district FROM xtbllocation AS l LEFT JOIN xtbldistrict AS d ON l.code = d.code"; Definitely should not be on the code column. scarezekiel, "doesn't work" doesn't give me enough info to help you. What is it doing? Can you post your complete code as it looks now? Quote Link to comment Share on other sites More sharing options...
scarezekiel Posted June 6, 2012 Author Share Posted June 6, 2012 sorry <? $query="SELECT l.*, d.description AS district FROM xtbllocation AS l LEFT JOIN xtbldistrict AS d ON l.code = d.code"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { $code = $row['code']; $description = $row['description']; $districtid = $row['districtid']; echo "<tr><td>$code</td>"; echo "<td>$description</td></tr>"; echo "<td>$districtid</td></tr>"; } ?> 1 thing i didnt mention..im using YII framework Quote Link to comment Share on other sites More sharing options...
smoseley Posted June 6, 2012 Share Posted June 6, 2012 Don't join on code. That's incorrect. What are you seeing as page output? Quote Link to comment Share on other sites More sharing options...
smoseley Posted June 6, 2012 Share Posted June 6, 2012 Here is my solution again.... now with your complete code.... there's absolutely no way this doesn't work. You must have copied it wrong. <?php require("html2fpdf.php"); $district = trim($_POST[district]); $server = ''; $username = ''; $password = ''; $database_name=''; $dbconn = mysql_connect($server, $username,$password,false) or die("Could not establish connection"); mysql_select_db($database_name, $dbconn) or die ("Could not select database"); if (!$dbconn) { die('Something went wrong while connecting to MSSQL'); } ob_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> <title></title> </head> <body> <table style="text-align: left; width: 715px; height: 32px;" border="1" cellpadding="2" cellspacing="2"> <tbody> <tr> <td colspan="2" rowspan="1" style="font-style: italic;">List-Location</td> </tr> <tr> <td style="font-style: italic;">code</td> <td style="font-style: italic;">description</td> <td style="font-style: italic;">districtid</td> </tr> <? $query="SELECT l.*, d.description AS district FROM xtbllocation AS l LEFT JOIN xtbldistrict AS d ON l.districtid = d.id"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { $code = $row['code']; $description = $row['description']; $district = $row['district']; echo "<tr><td>$code</td>"; echo "<td>$description</td></tr>"; echo "<td>$district</td></tr>"; } ?> </tbody> </table> <br> </body> </html> <?php $var = ob_get_clean(); $pdf = new HTML2FPDF('P', 'mm', 'Letter'); $pdf->AddPage(); $pdf->WriteHTML($var); $pdf->Output('test.pdf', 'I'); ?> 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.