This topic is locked

Printing and query other tables

7/5/2008 6:53:27 PM
PHPRunner General questions
F
fsteves author

Hello, I am trying to query another table from the printer friendly page so as to populate the correct data based on a certain condition.
Below is what I have for the statement as of now:

// Print page: Before record processed

function BeforeProcessRowPrint(&$data)

{

global $conn;
$sql = sprintf("select * from user_accounts where employer='%s'", mysql_real_escape_string($data["employer"]));

$rs = db_query($sql, $conn);
while($dat = db_fetch_array($rs))

{
$_SESSION["empaddress"] = $dat["Employer_Address"];
$_SESSION["empstate"] = $dat["Employer_State"];

}
return true;
// return true if you like to display row on in the list

// return false otherwise
} // function BeforeProcessRowPrint


The problem is that the same Address and State are returned for EACH row that is processed. How can I create a loop to make it different for each record and query the correct data? Thanks!

J
Jane 7/7/2008

Hi,
I recommend you to join these two tables on the Edit SQL query tab and check off fields from both tables on the print page on the Choose fields tab.

F
fsteves author 7/7/2008

Thanks, Jane! That was what I was looking for. Your the best!