Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Data is there, but results of query are not
Old 07-28-2008, 02:36 AM Data is there, but results of query are not
Average Talker

Posts: 25
Name: John Grafflin
Trades: 0
The info is in the database, but the query is not producing the expected results.

Code:
<?php
session_start();
ob_start();
include("includes/header.php");
include("includes/messages.php");
include("includes/validate_member.php");
ini_set("include_path", "./");if($siteCode== ""){
header("Location:selectSite.php");}if($siteCode!= ""){
$site = $siteCode;}?>
 
<span class="error"><b>Site Statistics by Referring URL</b></span>
 
<?if(isset($site)){?>
 
<p>The following list shows the total hits and unique visitors by referring URL to the site in the
time since tracking commenced.</p>
 
<p>
<table width="550" cellspacing="0" cellpadding="4" class="table">
<thead>
<th>Referring URL</th>
<!--<th>Percentage (%)</th>-->
<th>Hits</th>
<th>Unique</th>
</thead>
 
<?// Count the total number of hits to the site
 
$res = mysql_query("SELECT distinct referrer, COUNT(ip) AS total_hits, COUNT(DISTINCT ip) AS total_visitors FROM stats WHERE site = $site
GROUP BY referrer");
 
$row = mysql_fetch_array($res);
 
$total_hits = $row[total_hits];while(($row= mysql_fetch_array($res))!=NULL){if($row[referrer]== "")
$row[referrer]= "Could Not Detect";?>
 
<tr class="text2">
<td><?=$row[referrer]?></td>
<td><?=$row[total_hits]?></td>
<td><?=$row[total_visitors]?></td>
</tr>
 
<?}}?>
 
</p>
</table>
<?php
include("includes/footer.php");?>
jwgrafflin is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-28-2008, 04:46 PM Re: Data is there, but results of query are not
Average Talker

Posts: 18
Trades: 0
Maybe I'm missing something, but don't you want your code that prints out the table rows to be in a for or while loop so it can loop through the results of your query? Looks to me like you'd only get one row with that code.
__________________
30 Day Money-Back Guarantee -
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

awatson is offline
Reply With Quote
View Public Profile
 
Old 07-28-2008, 05:10 PM Re: Data is there, but results of query are not
Extreme Talker

Posts: 177
Trades: 0
try switching mysql_fetch_array to mysql_fetch_assoc.
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 07-28-2008, 07:04 PM Re: Data is there, but results of query are not
Average Talker

Posts: 25
Name: John Grafflin
Trades: 0
Problem solved. There was too much in the above code - revised as follows:

Code:
<?php
session_start();
ob_start();
include("includes/header.php");
include("includes/messages.php");
include("includes/validate_member.php");
ini_set("include_path", "./");if($siteCode== ""){
header("Location:selectSite.php");}if($siteCode!= ""){
$site = $siteCode;}?>
<span class="error"><b>Site Statistics by Referring URL</b></span>
 
<?if(isset($site)){?>
 
<p>The following list shows the total hits and unique visitors by referring URL to the site in the
time since tracking commenced.</p>
 
<p>
<table width="550" cellspacing="0" cellpadding="4" class="table">
<th>Referring URL</th>
<!--<th>Percentage (%)</th>-->
<th>Hits</th>
<th>Unique</th>
 
<?// Count the total number of hits to the site
 
$res = mysql_query("SELECT referrer, COUNT(ip) AS total_hits, COUNT(DISTINCT ip) AS total_visitors FROM stats WHERE site = $site
GROUP BY referrer");
 
$row = mysql_fetch_array($res);while(($row= mysql_fetch_array($res))!=NULL){if($row[referrer]== "")
$row[referrer]= "Could Not Detect";?>
 
<tr class="text2">
<td><?=$row[referrer]?></td>
<td><?=$row[total_hits]?></td>
<td><?=$row[total_visitors]?></td>
</tr>
 
<?}}?>
 
</p>
</table>
<?php
include("includes/footer.php");?>
So, on to the next problem.

This portion of the code is not delivering what is expected:

Code:
while(($row= mysql_fetch_array($res))!=NULL){if($row[referrer]== "")
$row[referrer]= "Could Not Detect";
When HTTP_Referrer cannot detect, it is placing "//" into the table data. Tried using
Code:
while(($row= mysql_fetch_array($res))!=NULL){if($row[referrer]== "//")
$row[referrer]= "Could Not Detect";
But still no output as expected. It reports nothing for those visits.
jwgrafflin is offline
Reply With Quote
View Public Profile
 
Old 07-28-2008, 09:16 PM Re: Data is there, but results of query are not
Average Talker

Posts: 25
Name: John Grafflin
Trades: 0
Problem ressolved. Added "ORDER BY referrer DESC" to the query, inserted the "//" in the while statement, and the script now outputs "Could Not Detect" with the applicable numbers.
jwgrafflin is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Data is there, but results of query are not
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.41906 seconds with 12 queries