First, this makes no sense:
$cookies = $row['cookies'];
$text="$cookies";
you can just do this instead:
$text = $row['cookies'];
The simplest method to get what you want is to run a new query for every $text value you find with the first query.
you'd get something like this:
$sql="select cookies, refere from bitlog where refere='$url'";
while ($row = mysql_fetch_array($result))
{
$text = $row['cookies'];
$sql2 = "SELECT refere FROM bitlog WHERE cookies ='$text'";
$result2 = mysql_query($sql2);
while ($row2 = mysql_fetch_array($result2))
{
echo $row['refere'];
}
}
A more comples method involves a JOIN between the table and a copy of itself.
But that gives all the results in one large set, and you have to filter them manually.