Jump to content

Ordering issue


galvin

Recommended Posts

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
}

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

}

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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