I m trying to created a code for the page in which no. of views are needed to be shown in the bottom of the page.
I don't know what will be the logic behind counting the views. let's say the views like on the home page of the stackoverflow. I like they way they display. And the logic for the same. (it'll be done via the php-mysql)
Please help
Thanks in advance
Set a function to select if their IP address is already in the table where you track your hits, if it is don't add one to the count, otherwise add 1 to the count as well as their IP for future tracking.
You'd stick something like this in the header of each page:
<?php
updatePageHitCount('name of page here');
?>
where the 'name of page here' is some unique identifier for the page. The function would then basically just do some SQL:
UPDATE pagehitcounts
SET hitcount = hitcount + 1
WHERE pageID = 'name of page here';
Of course, you'd want something a little more robust, but this would be the basics.
Related
I am developing a website in php/MySQL. Say this is a website for my students to check their course/subject results online of their respective semester. The logic is as follows.
The semester.php page lists semesters one through eight. The students clicks on the their semester link and are taken to courses.php where links to all the courses/subjects in that semester are given. When they click on any of their subject, subjectresult.php opens showing results of all the students in that subject.
I am passing semester and subject values as parameters in the URL as follows.
courses.php?semester=semestername
I am also using pagination to display only 10 results per page.
So far so good. The subjectresult.php shows only 10 results with pagination links at the bottom. Everything nice and tidy.
My problem is that when I click on page 2, everything goes away because the subject parameters is now no longer in the URL.
The two URLs as under:
course/subject URL: subjectresult.php?sub=subjectname
page # URL: subjectresult.php?page_no=pagenumber
The workaround that I have made is that I have changed the paging links logic and have added subject name as a second parameter. Now everything is working fine and the partial URL is as under:
subjectresult.php?sub=subjectname&page_no=pagenumber
Please note that I am a novice, still learning.
Now I have a few questions.
Am I doing it right? (Which I don't think so)
How to store my subject_result query result when the subjectresult.php page loads for the first time so that I don't have pass this again and again with each paging link?
Or in a Nutshell..How to do it correctly?
Thanks in advance.
Your approch is ok.
If you want to store and reuse the subject value,
In PHP use a session variable.
Eg:
session_start();
// give the subject value to the session variable.
$_SESSION['subject'] = "subject";
// get the value from the session variable if needed.
Like
session_start();
$subject = $_SESSION['subject'];
for more about sessions please check here..
The title may be a little vague, but I'll try to explain the concept here.
I have a site in which daily new items ( sports games ), get published, now what I would love is that my users would be able to click on a certain game and get redirected to a new page with more detailed information about that one game.
The thing is, creating every php page seperate for every game each day is a lot of work because also a lot details in the page need to be changed.
Now I was wondering if it is possible in some kind of way that there's a script that reads, OK you have 5 games today, page 1 = id number, title of the page is the matches name, extra info is the info that stands with that id.
I don't know how else to explain this so I hope this was good enough.
Thanks for your time and reading this :)
You can use requests to select the page (the best way is to use $_GET as suggested by gbestard) to select the ID. Then you can have some static content (like url or short article or link to screen shot or something similar) stored in your database under the same ID as the game, and upon clicking on the link to the game, the page is reloaded and you populate it with the new content, that was stored in the database.
You can even store entire pages with static html (as in article or short game description in your case) content and etc in your database and simply call them to populate a div.
If you have something like a custom made admin section of your site, you can add a page to edits it with a js plugin like ckeditor and the creation/editing of articles will be a piece of cake.
It's pretty much a standard case of a CMS(Content management system).
I have a project for school that I am working on where I have a table of different parts. In the last column of each row is an "Order" where they all link to orders.php page. Each link is for a different part, though, and so I want my variables to echo on the orders.php page for the correct link clicked. I have no idea how to approach this, but it must be done this way for the class and my professor is rather useless in terms of helping students.
Basically, if I click the "Orders" link in the "Batteries" row, I want the orders.php page to show $partname = Batteries, $price = (Battery Price) ... I really can't even figure out how to get each variable to be set once that link is clicked.
Thanks a bunch for any help please.
i had a hard time trying to understand your question but i think this may help:
you can use GET method to give information to the orders.php lie this:
in the original page you can have something like:
Battery
And in the orders.php:
$partname = $_GET["partname"];
$price = $_GET["price"];
i really hope that this is waht youre looking for. for more info google PHP GET Method.
I have completely no idea where to start so I apologise about the lack of code presented to you.
My problem is - I have a page of information, ordered by ID (gathered from the database). These ID's are referenced from another page to which the user clicks on a link and it takes them to the page with the information on, how ever, there could be potentially hundreds of ID's on that page - So I need to reference each specific ID so when the user clicks, it will take them to the exact position of the ID.
I understand its something like localhost:8888/index.html#id3 etc..
But i'm struggling to understand how to reference for a PHP Variable.
Many thanks in advance.
You would use anchors, so for example, on the page where you list your information, attach an anchor to it such as #id1, then on your links page, you would place the #id1 at the end of the url results.html?#id3
so i have a page where a user can submit his own links
i dont want to make a script that do everything automatic, i just want to make a page where, when the .php find a possible duplicated link, i get a warning like "ID 22 could possible have the same link as ID 738"
i only need like the query to do that...if its possible with that..i can only use php and mysql
if its too expensive (memory, cpu..) i can make like a submit button then when pressed generates like a report
ps: just to be clear, im not showing the message to the user, is something im going to put at my admin cp..and its not comparing "link 1" to "link 2" but searching the entire database
thanks
Your best bet would be to have a query that runs when new links are submitted. It could do something like this as a basic example:
SELECT * FROM links WHERE url = ""
If that returns results, then you have a dupe which can either be prevented from being inserted into the database, or simply flagged somewhere for review.
If you want to know which links are used by more than 1 ID, you could do something like this:
SELECT link,COUNT(id)
FROM link_table
GROUP BY link
HAVING COUNT(id) > 1