I have i DB a table named "jobadd". And in this table i have the columns "Kategori" and "Länk"
in "Kategori" i have different add categorys ex, "bygg" and in "Länk" i have links that will direct a user
to a page so that the user can see the details of this add.

And in the table USERS i have the columns "Kategori" and "email" in "Kategory" i have different categorys that a company
picks when registering on the site ex, "Bygg & Anläggning" and in "email" is the email to this company.

Now what i want is to send a mail to the companys that is in the "USERS" / "Bygg & Anläggning" categoty. After checking
in the "jobadd" table if there are some new (24 hrs) adds in the category "bygg" and if there are, then send a mail containing the
link(Länk) to this add.

I'v got this code but it only sends the top link(Länk) in DB to all the emails in DB. But i also need it not to send the same link(Länk) two times.

Code:
//DB CONNECTION CODE
.....................

//CONNECT TO MYSQL
$link=mysql_connect($mysqladd, $mysqluser, $mysqlpass, true) or die('Could not connect to database: ' . mysql_error());

//CONNECT TO DATABASE
mysql_select_db($databasename, $link) or die('Could not connect to table: ' . mysql_error());

$query="SELECT  *,  DATE_FORMAT(Time_of_Submission, '%Y/%m/%d') FROM jobadd  WHERE Kategori='bygg' AND Time_of_Submission BETWEEN SYSDATE() - INTERVAL 1 DAY AND SYSDATE() ORDER BY ID DESC"; 
$query2="SELECT * FROM USERS WHERE Kategori='Bygg & Anläggning'";

$result=mysql_query($query); 

$result2=mysql_query($query2);

$mailmessage = mysql_fetch_array($result);  

$mailmessage2 = mysql_fetch_array($result2);

$num=mysql_numrows($result); 

$num=mysql_numrows($result2);

if (!mysql_query($query,$link)) 
{ 
die('Error: ' . mysql_error()); 
} 

mysql_close($link)
?>
<?php
$i=0; 
while ($i < $num) {
$where=mysql_result($result,$i,"where"); 
$submitted=mysql_result($result,$i,"Länk");

$email=mysql_result($result2,$i,"email");


// Your email address 

 
$fromemail = "no_reply@jobler.se"; 


// The subject 

$subject = "Det har kommit in en ny Tjänstförfrågan på Jobler.se som passar er profil (klicka på länken nedan)"; 



// The message 


$message = $mailmessage['where']."  ".$mailmessage['Länk']."\n";


mail($email, $subject, $message, "From: $fromemail"); 


$i++; 
} 
echo "Förfrågan skickad";

?> 
<?php 

$i=0; 
while ($i < $num) { 
$where=mysql_result($result,$i,"where"); 
$submitted=mysql_result($result,$i,"Länk");

$submitted2=mysql_result($result2,$i,"email");

echo "<b><br>$where</b><br>$submitted<hr><br>"; 
echo "<b><br>$submitted2</b><hr><br>";


$i++; 
} 

?>