[PHP] Image Submission into a Database & Updating
Ok.. I have created a submission form that works great just like what I want.. but there is one minor detail if possible to figure out. When I let users upload a photo to my site, the image will be stored on the server hdd and the name of the image will be stored in the database. Works great!.. but lets say they submit another image in the same form.. it will overwrite the image name in the database, and uploads the new image.. but what about the old one? It stays dorment unusable and taking up space on my hdd. So... my question is.. what line can I add to delete the image before or after uploading the new one. I mean you can make the old name value into a temp value, and then it will overwrite the original value and you still have the temp value.. I think.. here is what by submit code looks like. Hopefully someone can figure this out. -code : if ($submit) { $connection = mysql_pconnect(SQL_SERVER, SQL_UID, SQL_PWD); mysql_select_db(SQL_DB, $connection); $sql = "UPDATE user SET desc_one='".addslashes($desc_one)."',photo_one='".addslashes($picture_name). "' WHERE userid='userid'"; mysql_query($sql); exec("cp $picture /root/lets/play/folder/tag/images/$picture_name"); return 0; } -code end. Thanks BradC -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Utilizing info from 2 tables in the database
Lets say I have created 2 tables : create table comments {contents} userid username comment datetime user ip primary key key table users {contents} userid username and many more.. :) -- if I want to get that to work togther to add comments to users would I have something like this.. -- $user=$DB_site->query_first("SELECT *,FROM username, FROM user LEFT JOIN comments ON comments.userid=user.userid WHERE user.userid=$userid"); -- that above code is slapped toghther.. can anyone shed some light on this.. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Pulling a random image
Hello everyone... I have been working on this random function for awhile now.. and it is close to being complete. It works as for a random function. But what my goal was is to make it where it goes through all the images before showing a random twice. Kind of like you put all the images in a bucket, and random select one out of the bucket while you eyes are closed, once you take it out of the bucket you put it on the table till there is no images left in the bucket, then you fill the bucket again and start over. Now... I thought the following function did that, but for some reason it is not... I might have just missed a line of code, or misspelled something, but I come to you guys/gals to be more second pair of fresh eyes to see if you can find where I made a mistake. Thanks.. -code snippet function getRandomUser() { static $itemarray; if (empty($itemarray)) { $connection = mysql_pconnect(SQL_SERVER, SQL_UID, SQL_PWD); mysql_select_db(SQL_DB, $connection); $sql = "select * from user where valid = 1 and inrotation = 1"; $query = mysql_query($sql); while($thisrow = mysql_fetch_array($query)) { $itemarray[] = $thisrow; } } if (sizeof($itemarray) == 0) return Array('userid'=>'-1', "photo_name"=>'', "photo_num"=>'', "counter"=>'', "size"=>''); srand((double)microtime()*100); $row = rand(0, sizeof($itemarray)- 1); $toreturn = $itemarray[$row]; $itemarray = array_splice($itemarray,$row,1); return $toreturn; } -code snippet thanks guys... :) Brad C
RE: [PHP] Re: Pulling a random image
You know what.. that might just work the way I need it to... will try it out tonight, thanks!!! :) Brad C. -Original Message- From: Hugh Bothwell [mailto:[EMAIL PROTECTED]] Sent: Monday, September 03, 2001 1:05 PM To: [EMAIL PROTECTED] Subject: [PHP] Re: Pulling a random image "Brad R. C." <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > But what my goal was is to make it where it goes through all the images > before showing a random twice. ... if you actually want to do this, you will have to keep track of which items you have seen in the last rotation. > Now... I thought the following function did that, but for some reason it is > not... Nope. You are just (inefficiently) choosing one item at random. An equivalent-but-faster approach would be SELECT * FROM user WHERE valid=1 AND inrotation=1 ORDER BY RAND() LIMIT 1 If you really need random-order, once-per-cycle images, you could achieve it by adding a 'views' field to the table; initialize all entries to the same value (ie 0). Each time an image is displayed, increment the views; when you choose an image, choose from the pool where the views value is minimal, ie. SELECT id,imgname FROM user WHERE valid=1 AND inrotation=1 AND views=MIN(views) ORDER BY RAND() LIMIT 1 UPDATE user SET views=views+1 WHERE id=$id How's that? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] PHP Web Base Email
www.hotscripts.com www.sourceforge.net both of them have some.. Squirrell is one I can think of in particular. Brad C. -Original Message- From: Sall Him [mailto:[EMAIL PROTECTED]] Sent: Sunday, September 09, 2001 11:18 PM To: [EMAIL PROTECTED] Subject: [PHP] PHP Web Base Email Hi All Does anyone know is there any web base email system which is written in PHP? thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]