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