Notice what the error is telling you - that $row is a non-object - and looking at the code you posted, you’ve not defined $row anywhere, which is why you’re getting the error. Edit: what I meant to say was, you’re trying to use it before it’s assigned.
I’m not entirely sure what you’re trying to do, but it would be a lot simpler to rewrite your code like this:
<?php
try {
$sql = $db->prepare("select em.*,jb.*
from employee em
inner join job jb
on em.emp_id = jb.emp_id");
$sql->execute();
}
catch(PDOException $ex) {
// You might want to log the error here and
// display some kind of message to the user
}
?>
<table border="1">
<tr>
<th>Name</th><th>job</th>
</tr>
<?php while ($row = $sql->fetch(PDO::FETCH_OBJ)): ?>
<tr>
<th><?php echo $row->emp_name ?></th><th><?php echo $row->job_date ?></th>
</tr>
<?php endwhile; ?>
</table>
but i have this array $tdrow ,i want to compare the strings first and if that string meets my condition
i will call the the column name from my table which is the $row->emp_name or whatsoever ;
The output is like this,the $tdrow array is depend on my parameter in the url, because those data in the $tdrow is passed as array.
that’s why i compare those string first.
The problem is when i put the foreach inside my while loop it will display the data repeatedly because of the while condition.how can i display the data ?
I’m using the array_intersect function to return an array of db columns and names ONLY where they exist both arrays.
Then, when it comes to generating the table, I’d loop over the array twice… once to generate the column headings, and again inside the while loop to output the required rows:
Note that I’ve changed the return type of PDO’s fetch method to return an associative array. This makes it easy to access the columns we want using a variable containing the column name.
Hi fretburner, Thank you for this…I am almost got it,i have some little problem…my table is displayed echo ,i think i am lost in the quotes…how will you display that table as echo ?