Linking to previous/next PHP/MySQL - php

I am creating a PHP/MySQL site which has records giving details about images.
Each record contains the field image_id (the key) and image_name.
I want to create a link on each page to go to the next record based on image_name rather than ship_id.
I have the current image_id and image_name as parameters in the URL. I've got as far as this line for the link but it just links to the current page... any help????
Previous

Related

How to upload multiple images with DropzoneJS

I don't really understand properly the concept behind uploading multiple files with preview. I checked DropzoneJS and it looks nice and I feel I can do a lot of stuff with it.
I have this example: I have a user (id: 801) that creates a new post (id: TBD since the post is not yet created). I have a table image_post which holds the images of the specific post, and an image table which holds the image details. Now, I have the Dropzone form which is supposed to upload images to a folder that I specify in the .php file that is implemented to deal with the ajax request coming from Dropzone. Let's say the user uploads 2 images and I store them into an temp folder. The user submits the creating of the new post, it receives an ID: 10001. The temporary files are on the disk (but should they be stored in the DB as well?) but don't see how to link the post to the images.
What are the exact steps that are required to be able to (after the files were uploaded with Dropzone ajax request) link those images to the actual post id?
Your system will need to create a database record for the post prior to them uploading images. Consider the following table structure, where an i prefix indicates an INT column, s a VARCHAR/TEXT column, and dt a DATETIME.
Table posts: iPostId | iUserId | iStatus | sComments | dtCreated
Table photos: iPhotoId | iPostId | dtUploaded
When a user begins to start a new post, create a record in the posts table with their user id, an empty comments, a datetime such as '0000-00-00 00:00:00', and a status of 0, and then add a hidden form input to the photo upload form so that the assigned post id is known to your photo upload script, e.g.:
<input type="hidden" name="iPostId" value="22" />
The photo upload script could create a new record in the photos table using the post id and then save the photo in a particular folder using the post id in the filename, for example if the photo_id for the record created was 2821 you would save the file as 2821.jpg in your chosen folder.
When the user finishes their post and clicks to save/submit, you could use an UPDATE query to modify the original record on the posts table, assigning their entered text to the sComments column, the current date and time to the dtCreated column, and changing the iStatus to 1.
On your pages where you display a list of posts simply modify your query to something like this to exclude those currently in a draft status (0): SELECT * FROM posts WHERE status=1;, and then when viewing the post you can run a query such as SELECT * FROM photos WHERE post_id=22; to get an array of the photos to be displayed.
Obviously this can be expanded upon but hopefully gives you a good starting point.

Get the Item id when creating dynamic pages on wordpress

I've been searching for several days now trying to find how to retrieve the item id of a select item from a mySQL database on a wordpress website.
I have a database of several hundreds of recipes. They are all displayed in a list on a certain page. I then want to be able to click on one of the recipes in the link and be sent to a unique recipe.php page.
The list of all recipes is on main-page.php. On this page, I have created the following:
echo '<td class="recipe"><a href=recipe?id='.$id.'><div class="recipe-container"><img src="'.$img.'" id="recipe-image"/>';
echo '<div class=recipe_name>'.$nam.'</a></div>';
As you can see, clicking on a recipe with the id of 4 would send you to www.example.com/recipe?id=4.
My question is, how do I tell the code to recognize that we are on the page for recipe #4, so that I can display its unique details? In particular, what do I write in recipe.php so that I can display the unique content for the selected recipe?
create an onload() event on the recipe.php, then check for $_SERVER['QUERY_STRING'] to retrieve id value and retrieve data from database based on the value
Found the awnser. All I had to do was:
$id = $_GET['id']
Had no idea it would be that easy.

Count Page views each separate

I want to make a count views system ,I have one for the site count views , but that's in general for the main site , dunno how to do it individually but it seems like this one will not be easy !
So I will show you my old system and in what way does the new should work, so I got this Running so far
$guest_ip = $_SERVER['REMOTE_ADDR'];
$visits = mysql_query("INSERT INTO visitors(ip) VALUES('".$guest_ip."')");
$visitoronsite = mysql_query("SELECT * FROM visitors");
$onlinevisits = mysql_num_rows($visitoronsite);
?>
Visitors: <?PHP echo $onlinevisits; ?>
Of Course It is great to keep track of who and how many , but As my site is with videos and each video has link with php ID which is something like site/index.php?id=8 and that page , What I want to do is to put a counter on that page saying that many people watched using this link and I already have a teory but Has Few Issues
So I created a table called pageviews with 2 columns one ip and the other one page , now here's my question , I cannot use unique because I want to show that that IP has also watched this link but it wount insert it because it will be unique so what do I do to keep one ip unique as for that page only?
On your pageviews table, you should create a unique index based on two columns (ip and video or link id).
You add a unique on your table like this:
ALTER TABLE `pageviews` ADD UNIQUE INDEX `ip_video_unique` (`ip`, `video_id`);
Than you would be able to store unique video views per IP.
On the page, you can get the count of how many IPs have viewed that video by doing a query such as:
SELECT * FROM `pageviews` WHERE video_id = x
where x in this query is the id of the video. In case of site/index.php?id=8 it would be 8.
Its also better if you separate the IPs on a separate table where you store visitors with a unique id and their respective IP and on pageviews table you reference the unique visitor id instead of the IP. Later on, this would allow you to count video views on a table and something else's views on another table but have the visitors(and their IPs) aggregated on a single table.

PHP+MySQL: Creating a photo gallery based on views

So I'm trying to create a system where the user can go to a page where a photo is displayed. The photos have a column in the MySQL db for views. How would I be able to view the top viewed photo with a link on the page for the photo with the 2nd most viewed photo, which has a link for the 3rd most viewed photo, etc. Each photo would have a dedicated page.
I'm using CakePHP, if there are any CakePHP specific strategies for doing this. Any suggestions?
I have never had the experience of using cakePHP, but with PHP and MySQL, you can use a query like this:
SELECT image_link, view_count
FROM `tablename`
ORDER BY view_count DESC
LIMIT 1
OFFSET $i;
and then, using a GET variable to pass on the incremental/decremental value of $i.
You can collect statistics for each image using
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$url = $_SERVER['HTTP_REFERER'];
?>
where $url - is a full path for your image.
well i don't have knowledge of cakephp, but i am telling you the logic to achieve that you want,
just send some parameter on the photo click and set a unique id of the photos, so that on the click event on the photo you will get the unique id of the photo and get which photo is viewed and update the database on every click.
beside that the link you will genrate according to your requiement to fetch the image on view filed on descending order

Last visited pages in site

I have one script where am trying to display in a website block The LATEST ARTICLES VISITED BY THE CURRENT USER.
The user can be anonymous or a member.
The articles are in table like [ id_art, intro, text]
So when the visitor X visit a page, i would like to put in the bloc the visited page.
Create a table on the form:
id, tstamp, art_id (key=[id, tstamp, art_id], index=[id, tstamp])
Whenever a user requests an article, add a row with article ID and timestamp. For the ID you can use the user ID for members or an auto-generated ID (persisted in a (session) cookie).
The list is then generated by extracting the latest N records in the table based on the (user/auto) id. (I.e., the actual list is generated by extracting N article titles and links based on a join on the IDs in the two tables.)
Credit goes to silvo for the following point (see comments):
... you should do some periodic upkeep on your table to make sure you don't keep entries that are too old and irrelevant
(Note: This is a generic solution. Nothing specific for Joomla / technology X / ... .)

Categories