I don't say this to be a prick, but it would be really helpful if you only showed us what we needed to see. That is, we don't need to see all of your HTML. And you can reduce your PHP to a simpler format that is representative of the real issue; doing so might even lead you to the solution all on your own. Also, it would be nice if you could use the PHP code tags instead of the generic code tags, so we have the benefit of viewing your code with syntax highlighting.
More important, if you have a problem of this nature, it would be great if you could provide us with a zipped SQL dump of your database tables. That way, we can actually test with your real configuration instead of spend time guessing.
Okay, now onto your problem. The flaw is in your logic. Think about what you are actually doing here... you are looping through your MySQL result set and setting $hl_id to a given value EACH ITERATION through the loop; $hl_id's value is changing each time your while() loop runs.
Now, think about your second while() loop. You're doing the same thing with $ef_favid. So, when you do your value comparison
if ($hl_id == $ef_favid)
both of those values are set to whatever the LAST row in each respective MySQL result set returned. You need to perform the value comaprison within the looping process, not at the end (because, after all, you want to compare the values for EACH favorite, not just the last one, right?).
Is this helping?