Add title to webpage from database - php

I have a table in my database that has a page title, keywords, images and other content for every page. I want to write some code in PHP and MySQL to fetch that data and create the file that is an HTML or PHP file (by fetching the file name stored in table) and write the code to fetch the page title and other content for page into the file one by one for each row, so that if later on I want to increase one column in any page, I may able to do so by increasing one field or table only.

Why write out files when you can just have one page that examines the URL to determine what data from the database to use when returning the HTML?
You can see that StackOverflow has hundreds of thousands of question and answer webpages, but there is only one file serving all these pages. They are not saving a file for every question onto a hard drive.

Related

How to insert an xml file in a single cell of sql table

I have a .xml file in my computer and i want it to be inserted in a single column and single cell of a sql table corresponding to serial no.s so that i can create a link on web page that would be directly downloadable from web page when clicking on it .I've searched everywhere but what i am getting is insert xml data in a table or how to upload a file on web page .
But i want them to be already uploaded on web page and when clicking on a link it will be directly downloaded on user,s local machine. So for this , I've to put those files in a column corresponding to their serial no.s then using php i can make those files downloadable to user machine .How is this possible have any idea...???
Go to this link "http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading-files-to-mysql-database.aspx"
This is a tutorial where you can insert xml file into database and also can create its downloadable link .This may help you.
In such case I would encode whole content of XML file using base64 before inserting into single database cell. And when using direct link use a php script which selects that cell, decodes data and simply outputs as xml.
If xml files are quite big, it is recommended to use gzip for compressing data before encoding with base64.
Did I understood your question correctly?

Loading file links from database with PHP

As a beginner I need some information. I've been trying to piece together bits for an online user uploading and sharing site like newgrounds.com
I don't have any code so far, just questions.
My big one at the moment, is how can I display SQL entries as file links? The idea is when a user uploads a file, an entry is created with the username, file name and file location. The file location will be a folder relevant to the user's username. But how will I create a link to that file onto a most recent uploads page?
You'll need to perform an SQL query everytime you list all the files anyway, so when you do your query, make sure to include the file location field and parse it in your PHP.
For example, if you are using MySQL, you can do SELECT * FROM FILES WHERE 'user_id' = $userid ORDER BY 'date' DESC LIMIT 10 and loop through those to display all the fields in your PHP code.

How can I make an image refresh everytime it is called on a page

By default when a webpage is loaded, images are loaded one single time for each image. If you have 5 instances of the same image on a page, that image is loaded once, and then used in all 5 places seemingly from the cache of the first image load.
What I want to do is have a single image displayed 5 times on a page, and each time the images is called have it re-loaded.
The reason for this is I have an image that is called from a database and each time the image is called it loads a different picture. Now this works perfectly when refeshing the page, but not when the image is loaded multiple times on the same page.
For example if I put the following into a webpage:
<img src='http://bannerpillar.com/u/viraladmin.jpg'>
The image loads perfectly. If I reload the page, a different picture is displayed for each time the page reloads. However if I add the image to a page in 2 different locations, the same one picture is displayed from both locations.
How can I make it so the image is refreshed every time it is called on a page? Is that possible?
Try adding something to the end of the file reference, like this:
<img src='http://bannerpillar.com/u/viraladmin.jpg?<?=rand(11111,99999)?>'>
The browser will think each image is unique and load each one separately rather than using the image from cache.
You can find a tutorial on this exact question here:
http://www.marcofolio.net/webdesign/php_random_image_rotation.html
Basically, in the src, you call a php file. The php file loads a filename from a directory of images.
For your case, you would need to write some logic to offset the database return, so this becomes a mysql question as well?
If you wanted the markup to call for an image file, you could redirect using a .htaccess rewriterule
Random no. generetion can be a good option.
but more better if you load those images serially i.e. one after another
n u can use looping for that.
Add a ?rand= to the image url.
<img src='http://bannerpillar.com/u/viraladmin.jpg?rand=<?php echo rand(100000,999999); ?>'>

Use javascript to read/write images to IndexedDB

I need help writing javascript (jquery?) for a web app to save a set of images to an IndexedDB and then load them into an html page.
I have two html pages, img.html that is just a listing of images in this format:
'image-id','base64-image'
and index.html, my main page that includes a series of image tags in this format:
<img name="imglist" id="image-id" img-src="">
I'd like the user to be able to click a button to load all of the images from img.html into IndexedDB and then click another button to read the images from IndexedDB and insert them into the appropriate image tag in index.html (the 'image-id' in img.html corresponds to the appropriate img tag id in index.html).
Also, is it possible to set a cookie (or some other method) that will cause the DB to be erased after a certain time period? I'd like to be able to force the user to re-load the images from the server about once a week.
I'm not great with javascript or indexeddb, so any help or examples would be great.
See the article titled Storing images and files in IndexedDB.
N.B. I just posted a similar question here, though it concerns the particular case of a cross-site request. If your requests are on the same site, the link above should be a perfect example for you to work by.

How to store multile images full path into a database so that I can display them in a user home page like Orkut

I am making an application in which every user has to sign in first and then he can access his home page. Now on the home page, I have given an option of uploading an image. Now if the user is uploading one image I am storing the full path of the uploaded image into a database and from there I can display the image easily by an img tag...
But what should I do when the user want to upload many images? Then how should I store their full paths in a database for the same user. Give me an idea just like Orkut or Facebook. Should I make a different table with named images and should I store images in different rows with the same username. What should I do?
I don't know the logic. What should I do? How can I upload many images and how can I store their path and what will be the wisest method and how do I display many images on one page (I can display one)?
You can make a folder, named after user name and id and put all their images there.
To display many images on one page, just add more <img> tags to the page.
This seems to be more of a design question than a PHP question. I would create a separate table to store all paths, this is more normalized.
You still need to handle the UI, but if you are doing a sort of gallery then that is fairly simple with some jQuery sideshows or something like that.
Yes, you want to use a separate table to store the image paths. You'll most likely want a record ID, the User ID, and the path to the image. You could also add a field to contain the sorting order for the images.
Having the sorting order field will allow you to page through the photos if there is more than one page of photos.
Your thinking is correct where you suggest creating a separate table with rows containing the image path and the username. The concept that you are dealing with is called cardinality. I'd recommend that you take a few minutes to read about this concept, since it is so important to database design.
In this case, you're talking about a one-to-many relationship between the user and the images.

Categories