PHP - Result Counter
Need some help on my result counter. I am using a search box to return data from my database i can get the result returned fine but i am having problems getting the total number of result returned. It only returns the number of results per page as i am using a paginate.
Can some one point me in the right direction. The number count im using is below. Code: [Select] $num_rows = mysql_num_rows($sql); echo "$num_rows Results Found\n"; Similar TutorialsI am really lost here with this date issue of mine. The below code is the last part of a query: Code: [Select] $defendercheck_3 = $row_checkifattacked3['atdate']; $defendercheck1_3 = strtotime("$defendercheck_3"); $defendercheck2_3 = date("D", $defendercheck1_3); The query does not return any results as expected, but when echoing the various steps I get following: echo "$defendercheck3"; = nothing (as expected) echo "$defendercheck1_3"; = nothing (as expected) echo "$defendercheck2_3"; = result! (NOT expected) why does it return anything on "date("D", $defendercheck1_3)" when "$defendercheck1_3" is blank? Hi, After looking at some Javascript, I think it can only be done in PHP. I'm trying to get my script to add a "1" to an external file. It's made in Javascript, but I hope I can put some PHP in it, even if it's at the end. I'm working on a Safari Extension, and would like to know how many people use it. It's all made in a .HTML file, so I should be able to add a PHP script at the end. I hope this is clear, and I hope it can be done in PHP, or something at least. Thanks, Joseph Duffy I have a counter that updates the database automatically with out refreshing the page. However i was wondering if someone can give me some pointers on how i can keep it updating the database even after someone exits the page. Currently it updates the database every 2 seconds by increasing the number by 1..however i want to be able to do this even if the page i not loaded is there any way i can do this? Hey all. Have a question, im still learning but what i am trying to do is make the number 1 add 1 to itself and repeat in the loop so, 1 2, 3, 4, 5, 6 ect...What am i doing wrong. $result = mysql_query("SELECT * FROM comments WHERE quoteid = ".$_REQUEST['quoteid'].""); while($row=mysql_fetch_array($result)){ $date = $row[date]; $name = $row[name]; $email = $row[email]; $quoteid = $row[quoteid]; $comment = stripslashes($row[comment]); $commentid = $row[commentid]; $counter = 1; $counted = $counter++; $resultb = mysql_query("SELECT * FROM quotes WHERE quoteid= '$quoteid'") or die(mysql_error()); while($link=mysql_fetch_array($resultb)){ $artist = $link[artist]; $song = $link[song]; } echo'<table border="0" cellpadding="0" cellspacing="0"><tr> <td rowspan="3" align="center"><span class="commentNumber">'.$counted.'</span></td> how do I make $counter add one evertime it runs through the loop: Code: [Select] <?php // Query member data from the database and ready it for display $sql4 = mysql_query("SELECT * FROM labels where item_id='".$pid."'"); $num_rows = mysql_num_rows($sql4); echo $num_rows; while($row = mysql_fetch_array($sql4)){ $label =$row["label"]; $lid=$row['id']; $counter = 0; $counter = $counter + 1; print $counter . "<BR>"; ?> <select name="name<?php echo $counter; ?>"> <?php echo $label; ?>currently, it says counter is 1 everytime How can I say, if more than one of these if's happens do this.... Code: [Select] if ((!isset($_POST['state'])) && (($_POST['country'] != $r['country']) || ($_POST['city'] != $r['city']))) { $details = $_POST['city'].', '.$_POST['country']; update_user_actions(1, $details); } else if ((isset($_POST['state'], $_POST['city'])) && (($_POST['state'] != $r['state']) || ($_POST['city'] != $r['city']))) { $details = $_POST['city'].', '.$_POST['state']; update_user_actions(1, $details); } if ((isset($_POST['credentials'])) && ($_POST['credentials'] != $r['credentials'])) { $details = ''; update_user_actions(2, $details); } if ((isset($_POST['specialties'])) && ($_POST['specialties'] != $r['specialties'])) { $details = ''; update_user_actions(3, $details); } if ((isset($_POST['personalweb'])) && ($_POST['personalweb'] != $r['personalweb'])) { $details = $_POST['personalweb']; update_user_actions(4, $details); } I'm not sure if this is the right form I may need to put this in the mySQL forum so apologies if it's in the wrong place. I would however like to do this in php. What I need to do is set up a counter that resets every day at midnight. So it would start with 01 and count up till 12:00AM server time and then reset to 01 for the next day. This is for an ordering system to add a number to the end of any order. Any help is much appreciated. I know it's not much info but I'm not even sure where to begin such a thing. hi all, i have made a counter as a module for my website. when i directly go to de module and start de counter i see the picure en he does his work, butt wen i call it in de index.php by include('modules/counter/counter.php') then i see een not loaded picturebox and i dont know why it doesnt works ? you can see the counter and the problem on: http://nieuw.pc-hulp-online.nl/index.php can someone help me to make it als work with include()?? thnx Hello, My hit counter doesnt work, at all. It is ment to update hits.txt(add 1 to the number in there.), and desplay how many hits it has using gd2. Here is my code: <?php /** * @author Jragon * @copyright 2010 */ getHits() function getHits() { $file = "hits.txt"; $fh = fopen($file, "r"); $hits = fread($fh, filesize("$file")); fclose($fh); ++$hits; $fh = fopen($file, "w+"); fwrite($fh, "$hits"); fclose($fh); getImage("$hits"); } function getImage($string) { //Make $string to to a string $string = "$string"; //Define fontsize $font = 5; //use imagefontwidth to find out the widht of each charicter, //then times it by how many charicters theere are, //and add some padding. $width = imagefontwidth($font) * strlen($string) + 10; //height of a charicter, and add some padding. $height = imagefontheight($font) + 10; //random color thingy. $r = rand(25, 250); $g = rand(25, 250); $b = rand(25, 250); //create a blank image using the dimsions set above. $image = imagecreate($width, $height); //set the background color $background_color = imagecolorallocate($image, 0, 0, 0); //set the text color using the random integers made above. $text_color = imagecolorallocate($image, $r, $g, $b); //Put the text into the image. imagestring($image, $font, 6, 6, $string, $text_color); //Change the type of webpage so you see the image header("Content-type: image/png"); //put everything together and make the image imagepng($image); //free up some space on the temp drive imagedestroy($image); } ?> I have created hits.txt with the value of 0 inside of it. Thanks Jragon I have music (my own) that I want to put on my website for download, and I was wondering if there is a way to keep track of how many people download each song, by tracking the clicks and displaying that number in a css-styled box. Anyone know how this is done? I don't need help with the css, just the php. I am trying to keep track of how many times a page is loaded for debugging. Here is my code but it doesn't seem to work?! Code: [Select] <?php isset($counter) ? $counter++ : $counter=1; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Page A</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <h3>Add a Comment</h3> <form action="Processing.php" method="post"> <fieldset> <!-- Comment --> <label>Comment:</label><br /> <textarea cols="50" rows="15"><?php echo $counter; ?></textarea> <br /> <!-- Submit Form --> <input type="submit" name="addComment" id="addComment" value="Add a Comment"/> </fieldset> </form> </body> </html> What am I doing wrong? Debbie Hi, I can't think how to make a counter which goes up during the day, and when a new day starts it gets reset to 0. How can I do this without relying on visitors to the site to run the script? Cheers, Tom. Hey everyone! My upcoming site will host, potentiallly thousands of photographs, and i was wondering how to go about having a unique ip hit counter for EACH image. Obviously i dont want people refreshing the page to gain hits, therefore the hit counter will need to be dependent on the IP address. I have used google and found a few hit counters however i need to know how to make this practical as it seems like it will require a lot of databases! Thanks in advanced, Jimmy. <?php $counter_name = 'Counter.txt'; if (!file_exists($counter_name)) { $f = fopen($counter_name, "w"); fwrite($f,"0"); fclose($f); } $f = fopen($counter_name,"r"); $counterVal = fread($f, filesize($counter_name)); fclose($f); $counterVal++; $f = fopen($counter_name, "w"); fwrite($f, $counterVal); fclose($f); echo $counterVal; ?> This is click counter... Counter.txt only number... How to add a date? Counter / Date 1. 2021-02-28 19:50:47 2. 2021-02-23 17:57:11 etc
Ok, I'm not sure if this is even possible but I will try and explain what I want to do and then maybe someone will be able to point me in the right direction. Say I have a link to an external site like google for example, when that link is clicked the target (google in this case) will open in a new window and the page on my site remains the same, is it possible to insert data into a table in my database at the same time when the link was clicked like an id value for the link, effectively creating a count, which can be displayed somewhere on the page? I really hope that makes sense, any help would be much appreciated! I know this should be easy but I cannot find right query to do this online. I simple want a counter of each result of my query. What is the proper way to query this.
For example
1 | Result 1
2 | Result 2
3 | Result 3
The one I found online did a weird grouping counter.
Thanks
Hello. I am trying to build a PHP hit counter for each game ID in the column of my database when visited, and updating the 'fldPlays' column by +1 to show how many people visited each page. I have a huge table with a list of data, but I'll show just 3 of the columns I have. Here they a fldID | fldData | fldPlays =================== 32145 Data1 0 21543 Data2 0 75855 Data3 0 36623 Data4 0 12471 Data5 0 =================== I am trying to increase the counter number at the 'fldPlays' column to show how many users had played each game by identifying the ID first. So for example: User types in 'http://www.mysite.com/games.php?id=32145' in the address bar for the 'Data1' game, and then once the user enters that particular page with that ID 32145 as you see in the URL, it adds 1 to the 'fldPlays' in that row. Overall, when I echo out 'fldPlays' as text in each page, it shows how many people actually played that page. Just to let everybody know that I am still learning PHP and I am new to counters as well. My guess to start the PHP counter is to fetch the ID of that URL, you would have to get id like this: Code: [Select] <?php if(isset($_GET['id'])) { $conn = mysql_connect("database", "username", "password"); mysql_select_db("data"); $game_id = $_GET['id']; $sql = "SELECT * FROM dbname WHERE fldID='$game_id' LIMIT 1"; ?> If anyone needs clarification, I will reply. Thanks for helping. Hello, I am wondering how to create a counter that has 5 digits and counts the results from a db field (not just the returned results but the numeric SUM of the values in the field) for display. i.e. if the sum of the field = 347 the counter would read 00347 I have created images for the numbers 0-9 and named them 0.png, 1.png, 2.png etc Also, I may have to sum a value that is stored in the db as serialized data (part of an array). If so how can I do that?? So I'm trying to make a counter that counts how many times a record on mysql database has been viewed. Not a hit counter for a webpage. In other words I have a page that displays the info of that record from the mysql database and within that page I would like to display the amount of times it has been viewed. Would anyone know where I can begin or send me to a good tutorial? Thanks hi there i am looking to build a button counter. and i am wondering of you could help. i want the button to +1 every time someone clicks it and also store the value so it can be used as a voucher code. can anyone help thanks |