Image slide show with PHP and MYSQL

images php coding issues or problems here.

Moderators: macek, egami, gesf

crf121359
New php-forum User
New php-forum User
Posts: 17
Joined: Sun Jan 22, 2012 7:40 am

Image slide show with PHP and MYSQL

Postby crf121359 » Sun Jan 22, 2012 7:56 am

Hi guys,

I am fairly new to this PHP/Mysql development and I am trying to learn.

I need to create a slideshow that will show images that users upload on my site.
I also need the users to be able to add texts i.e. the name of the image and their own name in two different text fields before pressing the submit or send button and those texts sould be shown under the image that has been uploaded.


any help will be much appreciated.


Cheers

User avatar
bigjoe11a
New php-forum User
New php-forum User
Posts: 128
Joined: Wed Aug 31, 2011 3:55 am
Location: USA
Contact:

Re: Image slide show with PHP and MYSQL

Postby bigjoe11a » Sun Jan 22, 2012 1:58 pm

Ok, what your takking about is a image gallery. A image gallery shows images and descriptions of the images from a mysql database. As for your slide show, That you would have to use some thing like Jquery or some thing in general that will let you do this. Or you could just let the page do it for you. When the page loads. a new image is displayed. or

If your wanted more then that. Like an image to to display for like 10 sec's and then another image to display. I can help you with this.

Your looking at a lot of coding for what your trying to do. So I think your will have to deside on just what your wanting to do.

Let me know

crf121359
New php-forum User
New php-forum User
Posts: 17
Joined: Sun Jan 22, 2012 7:40 am

Re: Image slide show with PHP and MYSQL

Postby crf121359 » Sun Jan 22, 2012 5:25 pm

bigjoe11a wrote:Ok, what your takking about is a image gallery. A image gallery shows images and descriptions of the images from a mysql database. As for your slide show, That you would have to use some thing like Jquery or some thing in general that will let you do this. Or you could just let the page do it for you. When the page loads. a new image is displayed. or

If your wanted more then that. Like an image to to display for like 10 sec's and then another image to display. I can help you with this.

Your looking at a lot of coding for what your trying to do. So I think your will have to deside on just what your wanting to do.

Let me know


Hi, Thanks for the reply. Yes you are right. I need it to disply for like 10 secs and then another image to disply.

could you please point me to the right direction?

User avatar
L33R
New php-forum User
New php-forum User
Posts: 133
Joined: Fri Dec 30, 2011 4:27 am
Location: Liverpool

Re: Image slide show with PHP and MYSQL

Postby L33R » Sun Jan 22, 2012 6:27 pm

check out:

http://nivo.dev7studios.com/

that should do what youre wanting.

crf121359
New php-forum User
New php-forum User
Posts: 17
Joined: Sun Jan 22, 2012 7:40 am

Re: Image slide show with PHP and MYSQL

Postby crf121359 » Sun Jan 22, 2012 7:18 pm

L33R wrote:check out:

http://nivo.dev7studios.com/

that should do what youre wanting.


That is just a slideshow though! I need to know how I can let the users upload image to my site and the images will be shown on my homepage for like 10-20-30 etc seconds!

User avatar
bigjoe11a
New php-forum User
New php-forum User
Posts: 128
Joined: Wed Aug 31, 2011 3:55 am
Location: USA
Contact:

Re: Image slide show with PHP and MYSQL

Postby bigjoe11a » Mon Jan 23, 2012 2:47 am

Well like I said. That will require some coding. How ever if you wanted an idea on how to do it. Then I would go to http://www.youtube.com and then do a search for phpclass. He has lots of video tutorials and this all so includes a way to upload images and then display them . It would be easy for you to do then for us to take out that a mount of time to code you a complete image gallery.

crf121359
New php-forum User
New php-forum User
Posts: 17
Joined: Sun Jan 22, 2012 7:40 am

Re: Image slide show with PHP and MYSQL

Postby crf121359 » Mon Jan 23, 2012 9:07 am

bigjoe11a wrote:Well like I said. That will require some coding. How ever if you wanted an idea on how to do it. Then I would go to http://www.youtube.com and then do a search for phpclass. He has lots of video tutorials and this all so includes a way to upload images and then display them . It would be easy for you to do then for us to take out that a mount of time to code you a complete image gallery.


Okay Thanks. I managed to code my way through lastnight and now I can save texts and the image names(i.e. myimage.jpg) in the mysql database. But now I have a different issue!

How can I pull those texts and the images and desply them on a php page?

I searched google and found a few but when I tried those codes I get errors...


is there is simple code that will get the details from database and shows them on the page?

Cheers

User avatar
bigjoe11a
New php-forum User
New php-forum User
Posts: 128
Joined: Wed Aug 31, 2011 3:55 am
Location: USA
Contact:

Re: Image slide show with PHP and MYSQL

Postby bigjoe11a » Mon Jan 23, 2012 9:27 am

Well like I said. That video tutorial will show you how to do all that. It will show you the images and a description from my mysql database. Let me know if you find the right one.

crf121359
New php-forum User
New php-forum User
Posts: 17
Joined: Sun Jan 22, 2012 7:40 am

Re: Image slide show with PHP and MYSQL

Postby crf121359 » Mon Jan 23, 2012 10:46 am

bigjoe11a wrote:Well like I said. That video tutorial will show you how to do all that. It will show you the images and a description from my mysql database. Let me know if you find the right one.


I can find videos on youtube but none of them actually helps with my problem to be honest!

Here is the issue that I have now! The images are uploaded into a directory on the server but before they are uploaded they are randomly renamed so they don't over write eachother.

But on the MySql database they are shown as their original name. for example: the image "myImage.png" has been uploaded and it has been renamed successfuly to something like 312344146.png.
BUT
when I look inot the mysql database it will show the image by its original name "myImage.png".

and thats why I cannot display the images on my page because they are renamed but in the database they kept their original name!! So what I need to do is that to do the same renaming function when they are saved in the database.


Here is my upload.php code:


Code: Select all

<?php   
 function findexts ($filename)
 {
 $filename = strtolower($filename) ;
 $exts = split("[/\\.]", $filename) ;
 $n = count($exts)-1;
 $exts = $exts[$n];
 return $exts;
 }
 
   //This gets all the other information from the form
 $uploaded=($_FILES['uploaded']['name']);
 $vehichle=$_POST['vehichle'];
 $contact=$_POST['contact'];
 
    // Connects to your Database
 mysql_connect("localhost", "username", "password") or die(mysql_error()) ;
 mysql_select_db("database") or die(mysql_error()) ;
 
   //Writes the information to the database
 mysql_query("INSERT INTO `employees` VALUES ('$vehichle', '$contact', '$uploaded')") ;
 
 
 //This applies the function to our file 
 $ext = findexts ($_FILES['uploaded']['name']) ;
 
 //This line assigns a random number to a variable. You could also use a timestamp here if you prefer. 
 $ran = rand () ;
 //This takes the random number (or timestamp) you generated and adds a . on the end, so it is ready of the file extension to be appended.
 $ran2 = $ran.".";
 //This assigns the subdirectory you want to save into... make sure it exists!
 $target = "images22/";

//This combines the directory, the random file name, and the extension
$target = $target . $ran2.$ext;

 if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
 {
 echo "The file has been uploaded as ".$ran2.$ext;
 }
 else
 {
 echo "Sorry, there was a problem uploading your file.";
 }
?>



Any sugesstions?

Cheers

User avatar
bigjoe11a
New php-forum User
New php-forum User
Posts: 128
Joined: Wed Aug 31, 2011 3:55 am
Location: USA
Contact:

Re: Image slide show with PHP and MYSQL

Postby bigjoe11a » Mon Jan 23, 2012 6:08 pm

yes I do. If this is the folder and the file name. I don't think you need to add the folder name all so.
$target = $target . $ran2.$ext;

Just add the new name that you named to too. So like if you wanted too. Keeps records of both file names. The new file name and the old file name.

and since you have an idea on where the files are stored. Then you don't really need to save the folder name with the file name.

So in you while loop. When you scroll threw the image records and display them to the user. You mite want to do some thing like this

Code: Select all

echo '<img src="'.$image_path.'/'.$row['rimage'].'">';
echo 'File Name : '.$row['filename'];


So what your doing here is displaying the image to the user. and just under the image your displaying the file name for that image.

Get the idea.

crf121359
New php-forum User
New php-forum User
Posts: 17
Joined: Sun Jan 22, 2012 7:40 am

Re: Image slide show with PHP and MYSQL

Postby crf121359 » Mon Jan 23, 2012 9:15 pm

sorry but I didn't quite get your idea/suggestion.

I removed the $target = $target . $ran2.$ext; from my code and tried it without that and I get errors so i cannot remove that from my code.

I shouldn't have a problem showing displying images on a PHP page if I could put the name of the renamed image into the databse! but once the images are uploaded onto the server and they are renamed their original names will be shown in the databse instead of their new (renamed) names.

Just to give you an example:

lets say I have an image called paypal.png
I can upload the paypal.png easily and smoothly.
the code that I have automatically renames the paypal.png to something random like 098983564.png
up to this stage everything works as they should. but when I look inot my Mysql databse, I see the name of the image that I uploaded i.e. paypal.png instead of 098983564.png

and that is what my problem is at the moment. I have another php code that I could use to display the images and the texts from the mysql databse but I cannot use that code because the paypal.png has been renamed to 098983564.png and has been saved in the images directory!!

So what I need to do is to twick the code that I already have for uploading the images and texts into mysql in a way that the table that holds the uploaded images name/details will show the new names of the images in this case 098983564.png instead of paypal.png

I hope I explained everything. please let me know if I confused you as I know some times it gets quite confusing explaining things on a forum and asking for help.


cheers


Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 1 guest