stanleybb Posted March 14, 2008 Share Posted March 14, 2008 I have already got code to produce random pictures on a website, but how do you get a rating system with that. So when a random picture comes up the viewer can rate it.Can somebody point me in the right direction Quote Link to comment https://forums.phpfreaks.com/topic/96142-can-this-been-done/ Share on other sites More sharing options...
Lamez Posted March 14, 2008 Share Posted March 14, 2008 just have each image have a certain value. Then you can go based off of that value. Quote Link to comment https://forums.phpfreaks.com/topic/96142-can-this-been-done/#findComment-492146 Share on other sites More sharing options...
Alexhoward Posted March 14, 2008 Share Posted March 14, 2008 Hi, There's plenty of rating scripts out there. have a look at google, some are really compicated, some not (but are not very good either) (I'm also stuggling with rating scripts at the moment, so i know where you're coming from) Basically when a rating is displayed on a page, it's tied to an ID, So in your case (if you don't store your pictures with an ID) it would be the name of the pic or whatever unique identifier you're using to pull them onto the page in the 1st palce i kind of know how they'll work, but i can't do it either!!! Quote Link to comment https://forums.phpfreaks.com/topic/96142-can-this-been-done/#findComment-492148 Share on other sites More sharing options...
stanleybb Posted March 14, 2008 Author Share Posted March 14, 2008 THanks next question lol I already have an upload script, is there a way you can get somebody to upload a picture for example, and the script changes the file name when they upload? or give it an id Quote Link to comment https://forums.phpfreaks.com/topic/96142-can-this-been-done/#findComment-492152 Share on other sites More sharing options...
Alexhoward Posted March 14, 2008 Share Posted March 14, 2008 I take it the pictures are being uploaded into an SQL table. Therefore, why not just have the 1st column as an INT autonumber primary key? then every new entry will have a unique ID Quote Link to comment https://forums.phpfreaks.com/topic/96142-can-this-been-done/#findComment-492155 Share on other sites More sharing options...
stanleybb Posted March 14, 2008 Author Share Posted March 14, 2008 The pictures are being uploaded onto the server and not a SQL table. Uploading to a table is even harder lol so if they have a primary key for example, you could then rate the items and link them to the ID. You then have to work out how to dispaly the rate system and make sure it works with the pictures Quote Link to comment https://forums.phpfreaks.com/topic/96142-can-this-been-done/#findComment-492163 Share on other sites More sharing options...
pauleth Posted March 14, 2008 Share Posted March 14, 2008 I agree with alexhoward that creating a unique ID is the best way - and using mysql's auto_increment feature, or the equivalent in PHP is probably the safest way. Once you create that unique ID, you can use it to create the file name. Quote Link to comment https://forums.phpfreaks.com/topic/96142-can-this-been-done/#findComment-492165 Share on other sites More sharing options...
pauleth Posted March 14, 2008 Share Posted March 14, 2008 The pictures are being uploaded onto the server and not a SQL table. Uploading to a table is even harder lol so if they have a primary key for example, you could then rate the items and link them to the ID. You then have to work out how to dispaly the rate system and make sure it works with the pictures I save my images in a directory on the server, but have the file path and a unique ID for each image stored in the database. That way, I reference all my images through the database table where the file paths are stored. I'm guessing you would create a separate table for the rating system, but link it to the table that stores the file path and image id by using the image id as a foreign key in the rating table... Quote Link to comment https://forums.phpfreaks.com/topic/96142-can-this-been-done/#findComment-492169 Share on other sites More sharing options...
stanleybb Posted March 14, 2008 Author Share Posted March 14, 2008 The pictures are being uploaded onto the server and not a SQL table. Uploading to a table is even harder lol so if they have a primary key for example, you could then rate the items and link them to the ID. You then have to work out how to dispaly the rate system and make sure it works with the pictures I save my images in a directory on the server, but have the file path and a unique ID for each image stored in the database. That way, I reference all my images through the database table where the file paths are stored. I'm guessing you would create a separate table for the rating system, but link it to the table that stores the file path and image id by using the image id as a foreign key in the rating table... How did you get it to upload and create a file path and unique ID P.S thanks for everybodies help btw Quote Link to comment https://forums.phpfreaks.com/topic/96142-can-this-been-done/#findComment-492173 Share on other sites More sharing options...
Alexhoward Posted March 14, 2008 Share Posted March 14, 2008 when they upload the image, you'll have to set the file name as a variable post the image onto your server then save the link into your data base as something like <img src="http://www.yoursite.co.uk/images/$variable"> sorry i can't work out the code from here, don't have time or the resource but say the link was saved as <img src="http://www.yoursite.com/images/eos.jpg"> when you selected the link from the table where the ID = $ID it would bring back <img src="http://www.everyonlinestore.co.uk/images/eos.jpg"> does this help at all....? Quote Link to comment https://forums.phpfreaks.com/topic/96142-can-this-been-done/#findComment-492195 Share on other sites More sharing options...
pauleth Posted March 14, 2008 Share Posted March 14, 2008 How did you get it to upload and create a file path and unique ID P.S thanks for everybodies help btw You can create a table that contains the image information (author, title, location, description, copyright, etc.) and relative file path on the server (i.e. my_images/image_name.jpg). The table will also generate unique identifiers for each image using the auto_increment attribute. I call the unique identifier the image_id. The image_id also becomes the image name. So if you have an image_id of 00012, the image name would be 00012.jpg. First you would populate the table with the image information and let the table automatically generate a unique image_id. Then you would use PHP to build a select statement to extract the newly created image_id from the table. After that, you can use PHP's move_uploaded_file function to upload the file to the server (after validating the file) - give it the correct name and put it in the right directory, according to the file path stored in your image table. For example: move_uploaded_file($POST['upload_file']['tmp_name'], "your_directory/".$image_id.".jpg"); or move_uploaded_file($POST['upload_file']['tmp_name'], $file_path); // Where file path is the relative path to the file on your server. Obviously, you don't have to store the relative file path to the image in your database - you can just store the actual image name (and set the file path in your HTML and PHP code). I just find it easier when I want to display images to just have that information in my database... Quote Link to comment https://forums.phpfreaks.com/topic/96142-can-this-been-done/#findComment-492196 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.