Forum Moderators: coopster
The short piece of code I've written is just an experiment to see what I can do with the referer which basically takes each referer, parse_url()'s it to get the query part, parse_str()'s that to get the keywords and then displays the keywords next to the referer.
However, if the next referer doesn't have a query part after I parse_url() it, or has a query part that the keywords can be read from, then it echo's out the keywords from the last referer which it shouldn't :(
<?
$query1 = ("SELECT referer, count FROM $table_prefix ORDER BY count DESC LIMIT 100");
$result = mysql_query($query1);?>
<table border="0" cellpadding="2" cellspacing="0">
<tr>
<td>Count</td>
<td>Keywords</td>
<td>Referer Url</td>
</tr>
<?
while($resulta = mysql_fetch_array($result)) {$referer2 = parse_url($resulta[referer]);
if ($referer2[query]!= "") {
parse_str($referer2[query]);if ($q) { $ref = $q; } else { $ref = ""; }
if ($ref!= "") {
$ref = str_replace("+", " ", $ref);
$ref = str_replace("\"", "", $ref);
$ref = str_replace("\?", "", $ref);
$ref = str_replace(" ", " ", $ref);
$ref = stripslashes($ref);
$ref = rawurldecode($ref);
$ref = trim($ref);
?>
<tr>
<td nowrap><?=$resulta[count];?></td>
<td nowrap><?=$ref;?></td>
<td nowrap><?=$resulta[referer];?></td>
</tr>
<?
} else {
?>
<tr>
<td><?=$resulta[count];?></span></td>
<td>Blank</td>
<td><?=$resulta[referer];?></td>
</tr>
<?
}
} else {
?>
<tr>
<td><?=$resulta[count];?></td>
<td>Blank</td>
<td><?=$resulta[referer];?></td>
</tr>
<?
}}
?>
</table>
Because this is just experimental, I've only used Google's variable which is '$q', can't for the life of me figure out why or how the keywords are being repeated when the table cell should be blank.
Can anyone shed any light on my problem please :)
Thanks
Marc :O)
unset($referer2);