Jump to content

sac0o01

Members
  • Posts

    37
  • Joined

  • Last visited

Everything posted by sac0o01

  1. I have a script that pulls urls from a database and displays the corresponding image by means of a foreach loop. I am trying to add a dropdown form to each iteration but when I run the from it only sends the values from the last iteration in the loop. The image part of the loop works perfectly. Any suggestions on a better way or how to make this one work? (excuse the mess...) <?php foreach ($image as $image_arr){?> <center> <tr> <br /><td width="70"><img src="<?php echo $image_arr;?>" alt="rotation" /><br /> </td> URL:<?php echo $image_arr;?> <br /> <?php //get ratings from database $ratingresult = mysql_query("SELECT rating FROM images WHERE url = '$image_arr' "); $ratingrow = mysql_fetch_row($ratingresult); $rating = $ratingrow[0] ?> Rating:<?php echo $rating;?></td><br /> <form name="rateform" action="rate.php" method="POST"> <input type="hidden" name="seturl" VALUE="<?php echo $image_arr ?>"/> <select name="ratedrop"> <option value="1">1 star</option> <option value="2">2 stars</option> <option value="3">3 stars</option> <option value="4">4 stars</option> <option value="5">5 stars</option> </select> <input type="submit" VALUE="rate" /> <hr /> </tr></center> <?php }?>
  2. Thanks for the response. I'll try to explain a little better. The form displays properly in all of the foreach iterations. However the first iteration does not run changeweight.php when the submit button is clicked. All the other iterations work perfectly. I added shuffle($image) before the loop and when the previous first iteration is no longer first , it updates weight fine. Also, I understand what you mean about the query in the loop but not sure how to implement it outside the loop because I need the $image_arr variable from the foreach statement
  3. I start out by pulling a list of image urls from the database then I run it through a foreach loop to display the results and change the weight of the image <?php foreach ($image as $image_arr){?> <tr> <td width="70"><center><img src="<?php echo $image_arr;?>" alt="rotation" /><br /> URL:<?php echo $image_arr;?></center> <center> <?php //get image weights $weightresult = mysql_query("SELECT weight FROM images WHERE url ='$image_arr'"); $weightrow = mysql_fetch_row($weightresult); $weightcontents = $weightrow[0]; ?> higher weight images will show more often <br /> <form action= "changeweight.php" method="post"> Weight (1 to 9): <input type="number" name="weight" min="1" max="9" value="<?php echo $weightcontents ?>" /> <input type="hidden" name="seturl" VALUE="<?php echo $image_arr ?>"/> <input type="submit" VALUE="set weight" /> </form> The problem is all the weight boxes work except for the first one. Could the fact that it is [0] in the array be messing it up? Here is changeweight.php if it helps: <?php session_start(); //connect to db include("dbc.php"); $setweight = $_POST['weight']; $seturl = $_POST['seturl']; mysql_query ("UPDATE images SET weight = '$setweight' WHERE url = '$seturl' ; ") or die (mysql_error()); header("Location: /xxxxxx/myaccount.php",TRUE,303); ?>
  4. Yes I have looked through the manual on foreach. That is how I came up with what I have so far. Actually the "$image as $image" part is working but I see it would be better defined by "$image as $image_arr" (or similar). What I am confused on is how to call each value in the array so that I can delete just that value (url)
  5. I have a script that fetches image urls from a database and then displays the images on the page. This all works fine but the problem is I cannot remove just one image from the image list. I would like to add a "delete" button below each image that would correspond to that image. Problem is I don't fully understand foreach and how it works with arrays. Here is how I fetch the images: <?php $sqlresult = mysql_query("SELECT * FROM images WHERE user_id =".$_SESSION['userId']); $count = 0; while($data = mysql_fetch_array($sqlresult)) { $image[$count] = $data['url']; $count++; } ?> And here is how I list the images. This is where I want to add the delete button (I know the code is ugly ) : <?php foreach ($image as $image){?> <tr> <td width="70"><center><img src="<?php echo $image;?>" alt="rotation" /><br /> URL:<?php echo $image;?></center></td> </tr> <?php }?> Thanks for any suggestions
  6. I am working on a chatbox script and am using html to set the colors for the text. First in config.php I define the values for the colors: //Name color (sets color of name in messages) $nametextcolor = "6b9c69"; //Message text color (sets color of messages) $messagetextcolor = "FF9900"; Then I use the variables in the html code: <div class="<? echo $class; ?>" style="background-color:<? echo $bgcolor; ?>"> <font color="<? echo $nametextcolor; ?>" > <? echo $name; ?>: </font> <font color="<? echo $messagetextcolor; ?>" > <? echo $text; ?></font> </div> The problem is it does not change the color of $name only change the return for $text Is there something I am missing here?
  7. I see that now...so now I have to figure out how to call the image up. If I echo $filename it returns the correct path i.e. temp/example.jpg How do I go about downloading the image? Right now I just tell users to right click and save but would like to have the download link or button.
  8. So I am trying to download an image created with my php script. I use the following for the download: <?php session_start(); $filename = $_SESSION['imgOut']; header('Content-type: application/octet-stream'); header('Content-Disposition: attachment; filename='.$filename ); ?> The file downloads however instead of downloading "example.jpg" from the /temp folder , it downloads "temp_example.jpg" which of course is an empty file. I am sure I am approaching this the wrong way, any suggestions?
  9. Yes, good thinking. Hadn't thought of that. Would be rather simple to do. Actually I had just came up with this: $dailylimit = mysql_query("SELECT lastvisit FROM users WHERE user_id = '{$_SESSION['userId']}' "); $dlrow = mysql_fetch_row($dailylimit); $lastvisitdate = $dlrow[0]; $todaysdate = date("Y-m-d"); if($lastvisitdate != $todaysdate) { $addviews = mysql_query("UPDATE users SET viewlimit = viewlimit + 100 WHERE user_id = '".$_SESSION['userId'] . "' "); } Just have to make sure the code is executed before the query is sent to update "lastvisit" .
  10. So I have an application that allows users to earn points after logging in and visiting their account page using the following: $addviews = mysql_query("UPDATE users SET viewlimit = viewlimit + 100 WHERE user_id = '".$_SESSION['userId'] . "' "); This works fine except that by simply refreshing the page the user will gain another 100 points, and on and on.... What would be a simple way to only award the points once a day?
  11. Maybe some of the great coders here can help this noob out. So here is what I have so far: //set age criteria for deletion $age = 60; //get current date $datenow = date("Y-m-d"); //set the range we want to delete $delete_range = $datenow - $age; //get old user_id from users table $oldusers_users = mysql_query ("SELECT user_id FROM users WHERE lastvisit < $delete_range "); //get user_id from images table that correspond to users table $oldusers_images = mysql_query ("SELECT user_id FROM images WHERE $oldusers_users=user_id.images "); //find folders that correspond to the usernames and delete $oldusers_files = mysql_query ("SELECT username FROM users WHERE lastvisit < $delete_range "); //print out username //$result = mysql_($oldusers_files); $foldername = mysql_result($oldusers_files, 0); $sigspath = "sigs/"; unlink($sigspath . $foldername . ".gif/index.php"); rmdir($sigspath . $foldername . ".gif"); //now delete user_id's from database mysql_query("DELETE * FROM users WHERE user_id=$oldusers_users"); mysql_query("DELETE * FROM images WHERE user_id=$oldusers_images"); unset($oldusers_users, $oldusers_images, $oldusers_files, $foldername, $sigspath ); mysql_close($link); Right now it is only returning the first entry, not the entire list that meets the criteria. It does delete that one file though but does not remover the rows from the database. I am sure the database stuff is jacked up I am really new to that part. What am I doing wrong here or is there a better way to do this perhaps
  12. Thanks to both of you, I got it going. Harristweed I thought the same thing as you and had tried that but could not get it to work. In the end the problem was coming from the fact that when I created the column in the database I did not set it to "not null". So it would not update the row. I fixed the null problem and it works great now. Thanks again
  13. I am trying to update last logged in entry in the database upon succesful login. I may be way off in the logic here or I may be missing something simple. I don't get any errors and it logs in fine. Just does not update the lastvisit field in the database. //record date of most recent login $result = mysql_query("SELECT username FROM users WHERE user_id ='".$_SESSION['userId'] . "'"); $dtCreated = date('Y-m-d'); mysql_query("UPDATE users SET lastvisit=('$dtCreated') WHERE username = $result");
  14. I am running a script that uses curl to fetch an image and then pass it through to a user. It works well but is consuming a large amount of bandwidth. Is there another way that I could pass the url to the user directly, bypassing my host?
  15. This should work for you. I will try to explain it the best I can. The big thing here is changing from "imagecreate" to "imagecreatetruecolor" this allows the palette to use over 16 million colors rather than just 256. By using truecolor you can also now save the alpha channel of the image which can be antialiased. I also changed the final "imagepng" to create a file for easier viewing during testing. Simply change: // Create the signature canvas $signature = imagecreate($signatureX, $signatureY); // Make the signature background transparent imagecolorallocatealpha($signature, 0, 0, 0, 127); To this: // Create the signature canvas $signature = imagecreatetruecolor($signatureX, $signatureY); // Make the signature background transparent imageantialias($signature, true); imagealphablending($signature, true); imagesavealpha($signature, true); $trans_colour = imagecolorallocatealpha($signature, 0, 0, 0, 127); imagefill($signature, 0, 0, $trans_colour);
  16. I am no expert on php but I have had some experience wit GD and know exactly the problem you speak of. I will post a solution for you when I get home from work and on my pc.
  17. Gizmola, it is for an image rotator. The script grabs the urls from the database and randomly returns one of them. This page is the interface where users can enter the urls they want included but I need a way for users to change the urls as well. I tried using "REPLACE" instead of insert but it does not overwrite the urls, it simply adds new ones (although it does not make duplicates now) I am thinking this is more of a database problem than php problem. Or maybe there is just a better way to approach this?
  18. Gizmola, it worked like a charm. No more duplicate entries. Now if I may ask one last thing... How would I go about updating the database if a user entered a new url? I tried using another "if" statement with "isset" and the "UPDATE" command for the sql query. Perhaps "isset" is not correct???
  19. I am quite new so I am sure this is an easy fix for some of the experts around here. I am using the canned script below to add urls to the database as text. The problem is if you update one of the form text boxes it loads all the urls into the database again resulting in a lot of duplicates. My question is, How do I get the form to only post the new changes and not re-post the existing urls? <?php session_start(); if(isset($_SESSION['userSession']) && !empty($_SESSION['userSession'])) { include_once("dbc.php"); if($_POST) { $c = 0; $errMssg = ""; for($i=0;$i<count($_POST['url']);$i++) { if($_POST['url'][$i]=="") { $c++; } } if($c==5) { $errMssg = "Submission error . Please fill at least 1 url."; } else { for($j=0;$j<count($_POST['url']);$j++) { if(!empty($_POST['url'][$j])) { $sql = mysql_query("INSERT INTO images (id ,url ,user_id)VALUES (NULL , '".$_POST['url'][$j]."',".$_SESSION['userId'].")"); } } } } $sqlresult = mysql_query("SELECT * FROM images WHERE user_id =".$_SESSION['userId']); $count = 0; while($data = mysql_fetch_array($sqlresult)) { $image[$count] = $data['url']; $count++; } ?>
  20. Thanks so much, looks like I have some more studying to do.
  21. Thanks! Works great! I understand the first one but could you explain how this line in the second one works? Operators still give me a rough time. $num_of_imgs = ($num_of_imgs > 11) ? 11 : $num_of_imgs;
  22. I am using the following to display all the images within a folder. How could I limit the number of images displayed to a set number, for example 10? $files = glob("temp/*.png"); for ($i=1; $i<count($files); $i++) { $num = $files[$i]; echo '<img src="'.$num.'" alt="random image">'." "; }
  23. Upon submit the page runs script.php and then uses header("Location....") to return to the index page. I am afraid this is causing the set variable to be wiped out. I may have to stick with the session named file and find a way to force refresh each time the form is changed.
  24. I am creating an image file through GD. It successfully creates the file with a random file name. //define file name $rand = rand(1,100000); $filename = 'temp/' . $rand . '.png'; Upon the script completion it directs back to the index page where the image should be displayed but it does not. <img src="<?php echo 'temp/' . $rand . '.png';?>" /> I was using $PHPSESSID to create and display the image and it worked fine except that IE held the image in cache and required a hard refresh to display the new image. Any suggestions how to get the random image src working, or maybe a better way of handling the entire process??
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.