galvin Posted January 19, 2012 Share Posted January 19, 2012 There has to be a simple solution for this problem that I am apparently too dense to figure out... Say on a single page, I have code like this... <div id="stuff"> //stuff </div> and then further down on the page, I have code that runs and produces a variable ($i) that is a number. I then want to check to see if that number is 10 or higher, or not, (which I can handle doing ) and if it is 10 or higher, then I want to hide the "stuff" div that is further up on the page. What is the best way to do this? It's like I need the code to run and then go back and add something to the "stuff" div to make it not show, if the variable is 10 or higher. Any thoughts? This has to be easy so I"m feeling particularly newbie tonight :-\ if ($i >=10) { //the number is 10 or higher so let's somehow hide the "stuff" div that is further up on the page. but how? } else { // the number is less than 10 so it's cool to continue to display the "stuff" div } Quote Link to comment https://forums.phpfreaks.com/topic/255330-ordering-issue/ Share on other sites More sharing options...
scootstah Posted January 19, 2012 Share Posted January 19, 2012 You can't. Why not display it after the $i is set? Quote Link to comment https://forums.phpfreaks.com/topic/255330-ordering-issue/#findComment-1309101 Share on other sites More sharing options...
Drummin Posted January 19, 2012 Share Posted January 19, 2012 Anyway you can put the "code that runs and produces a variable ($i)" higher on the page? Not knowing what you're doing, I would say, run this above the html part of the page, and display what's needed for each section. Any "POST update" code should also be above this as well. Quote Link to comment https://forums.phpfreaks.com/topic/255330-ordering-issue/#findComment-1309105 Share on other sites More sharing options...
galvin Posted January 19, 2012 Author Share Posted January 19, 2012 Well, I am getting info from Amazon S3 and the variable I mentioned is the total number of images from a certain bucket. And the div that I sometimes want to hide contains the form to upload new images. Basically, if the user has uploaded a certain number of images (10), then I don't want the upload form to display (so that they can't upload anymore images). The S3 code gets and displays the images (and also counts them as it's doing that). I think the upload form needs to be above the S3 code (which is below) since there could be a lot of images listed out below it. I was thinking maybe putting the upload form after the S3 code and then positioning it above the images using CSS, but that seems hacky, no? Or could I run the S3 code before it and not display it (i.e. don't use echos until later in the code). This sounds right but not sure how I would store all the image code in a variable that is displayed later in the page. //include the S3 class require_once('sdk-1.4.4/sdk.class.php'); // Instantiate the class $s3 = new AmazonS3(); $response = $s3->get_object_list('bucket', array('prefix' => $id.'/')); $o=0; foreach ($response as $file){ $furl = "http://mydomain.s3.amazonaws.com/".$file; //output a link to the file echo "<img src='$furl' width='50' />$furl"; ?> <form action="/s3processdelete.php" method="post" enctype="multipart/form-data" name="form2" id="form2"> <input type="hidden" name="file" value="<?php echo $file;?>"/> <input name="SubmitDelete" type="submit" class="delete" value="Delete This Image"> </form> <?php $o=$o+1; } Quote Link to comment https://forums.phpfreaks.com/topic/255330-ordering-issue/#findComment-1309106 Share on other sites More sharing options...
galvin Posted January 19, 2012 Author Share Posted January 19, 2012 Sorry, I figured it out. Instead of echoing all the image code, I stored it in $imagecode (i.e. $imagecode .=) and then echoed it later on. Sorry for wasting your time with something so easy :/ Quote Link to comment https://forums.phpfreaks.com/topic/255330-ordering-issue/#findComment-1309108 Share on other sites More sharing options...
Drummin Posted January 19, 2012 Share Posted January 19, 2012 OK... while you posted that I was typing... Glad you got it working. <?php //include the S3 class require_once('sdk-1.4.4/sdk.class.php'); // Instantiate the class $imageforms=""; $s3 = new AmazonS3(); $response = $s3->get_object_list('bucket', array('prefix' => $id.'/')); $o=0; foreach ($response as $file){ $furl = "http://quizfox.s3.amazonaws.com/".$file; //output a link to the file $imageforms.="<img src='$furl' width='50' />$furl"; $imageforms.="<form action=\"/s3processdelete.php\" method=\"post\" enctype=\"multipart/form-data\" name=\"form2\" id=\"form2\"> <input type=\"hidden\" name=\"file\" value=\"$file\" /> <input name=\"SubmitDelete\" type=\"submit\" class=\"delete\" value=\"Delete This Image\" /> </form>"; $o=$o+1; } ?> <html> <body> <?php echo "$imageforms"; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/255330-ordering-issue/#findComment-1309109 Share on other sites More sharing options...
galvin Posted January 19, 2012 Author Share Posted January 19, 2012 Thanks Drummin! It worked, but now when I try to delete an image from Amazon S3, I get this error (deleting worked fine before I made the change). "Warning: S3::deleteObject(): [505] Unexpected HTTP status in /home/me/public_html/mydomain.com/S3.php Warning: Cannot modify header information - headers already sent by (output started at /home/me/public_html/mydomain.com/S3.php:602) in /home/me/public_html/mydomain.com/includes/functions.php on line 28" Not your guys problem (have to dig into S3 I guess), I just hate how I fix one thing and it breaks another i guess that's programming Quote Link to comment https://forums.phpfreaks.com/topic/255330-ordering-issue/#findComment-1309110 Share on other sites More sharing options...
Drummin Posted January 19, 2012 Share Posted January 19, 2012 Assuming it was working when form processing was in body, can you keep form processing in body and reload page with header redirect? Quote Link to comment https://forums.phpfreaks.com/topic/255330-ordering-issue/#findComment-1309119 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.