Closed Thread Icon

Topic awaiting preservation: Database retrieving question (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=24765" title="Pages that link to Topic awaiting preservation: Database retrieving question (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Database retrieving question <span class="small">(Page 1 of 1)</span>\

 
ddade13x
Nervous Wreck (II) Inmate

From:
Insane since: Aug 2004

posted posted 01-22-2005 18:42

I'm sure this is simple to all of you...or perhaps I've gone and done a horrilble thing setting up my database this way, so please forgive me I'm without db training here. I have a table containing my pages in one column and each unique ip in the next column like this:

page1......ip1
page1......ip2
page1......ip3
page2......ip1
page2......ip2
page2......ip3
page3......ip1
page3......ip2
page3......ip3
yadda yadda

So, how do I go about counting how many times page1 is recorded into the table? Is that even possible with this setup? I have managed to pull a single reference out of the page column, but can't figure out how to count each record. I would appreciate any help you can give.

zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 01-22-2005 18:54

Does this help?

code:
SELECT COUNT(*) FROM table WHERE page='1'


Replace 1 with what page number you want to count. From the information you provided above, this example will return 3.

ddade13x
Nervous Wreck (II) Inmate

From:
Insane since: Aug 2004

posted posted 01-22-2005 19:36

zavaboy,

Thank you for the help. I found something very similar on another page, however, your suggestion and the other page both give me a "resource id#5" error. I've done some searches, with no results (only resource id#3 errors), so I'm at a bit of a loss at what I'm doing wrong now.

corrosponding website: http://web-bureau.com/modules/free-php-hit-counter-script.php

code:
$unique_index = "SELECT count(*) FROM ip_hits WHERE page = '/index.php'";
$get_unique = mysql_query($unique_index,$conn) or die (mysql_error());
echo $display_hits;



I'm a little curious if it is the "/" before the "index.php" causing the error, but I honestly don't know. It could equally be my horrendous code. ::grin::

Again, all help is much appreciated.

Thank you

zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 01-23-2005 06:44

Try this:

code:
$Link = @mysql_connect ('localhost','username','password')
or die('Could not connect to database!<br />'.mysql_error());
if($Link)
@mysql_select_db($db_name)
or die('Could not select database!<br />'.mysql_error());

// Other code here if needed...

$query = "SELECT COUNT(*) FROM ip_hits WHERE page='/index.php' LIMIT 1";
$result = mysql_query($query);
$display_hits = mysql_result($result,0);
echo $display_hits;
@mysql_free_result($Result);

// The rest...


Change code to fit your current script.

« BackwardsOnwards »

Show Forum Drop Down Menu