Jump to content

sac0o01

Members
  • Posts

    37
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

sac0o01's Achievements

Member

Member (2/5)

0

Reputation

  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?
×
×
  • 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.