Jump to content

help please


scarezekiel

Recommended Posts

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..

 

post-131669-13482403583585_thumb.jpg

post-131669-13482403583686_thumb.jpg

post-131669-13482403583926_thumb.jpg

Link to comment
https://forums.phpfreaks.com/topic/263674-help-please/
Share on other sites

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>";

Link to comment
https://forums.phpfreaks.com/topic/263674-help-please/#findComment-1351270
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/263674-help-please/#findComment-1351415
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/263674-help-please/#findComment-1351559
Share on other sites

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');

?>

Link to comment
https://forums.phpfreaks.com/topic/263674-help-please/#findComment-1351563
Share on other sites

Archived

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

×
×
  • Create New...

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.