Super tough PHP if/else statement add array help needed

I have the following PHP if/else statement that I need to change the order of the $image variable.  It currently displays <img value low to high when it needs to display the highest value for $c_ext first...can someone adjust this to show me how I would build an array to save the $c_ext found in the if statement and then write them out with the highest value first?


                                                      
<?
									$image = "<br>";
									$img_cnt = 1;
									$image .= "<a href=/feeds/sancap/rets_images/$MLNumber.jpg rel=\"enlargeimage\" rev=\"targetdiv:loadarea\"><img src=/feeds/sancap/rets_images/$MLNumber.jpg alt='' width='100' height='75' border='0' /></a>&nbsp;";
									for ($c=1;$c<30;$c++) {
										if ($c<10)
											$c_ext = "0".$c;
										else
											$c_ext = $c;

										if (file_get_contents("http://www.mysite.com/feeds/sancap/rets_images/{$MLNumber}_{$c_ext}.jpg"))
									$image .= "<a href=/feeds/sancap/rets_images/{$MLNumber}_{$c_ext}.jpg rel=\"enlargeimage\" rev=\"targetdiv:loadarea\"><img src=/feeds/sancap/rets_images/{$MLNumber}_{$c_ext}.jpg alt='' width='100' height='75' border='0' /></a>&nbsp;";
										else
											break;

										$img_cnt++;
										if ($img_cnt == 5) {
											$image .= "<br>";
											$img_cnt = 0;
										}

									}

									?>  

Open in new window

pda4meAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Greg AlexanderLead DeveloperCommented:
How about something like this you can change the ksort to krsort depending on which way to sort the array
<?
$url = "http://www.mysite.com/feeds/sancap/rets_images/";
for($c=1;$c<30;$c++){
	
	if($c<10){
		$c_ext = "0".$c;
	}else{
		$c_ext = $c;
	}
	
	if (file_get_contents($url."{$MLNumber}_{$c_ext}.jpg")){
		$image_array[$c_ext] = "{$MLNumber}_{$c_ext}.jpg";	
	}
	
}

ksort($image_array);

$img_cnt = 1;
$image = "<br>";
$image .= "<a href=/feeds/sancap/rets_images/$MLNumber.jpg rel=\"enlargeimage\" rev=\"targetdiv:loadarea\"><img src=/feeds/sancap/rets_images/$MLNumber.jpg alt='' width='100' height='75' border='0' /></a>&nbsp;";
foreach($image_array as $key => $value){
	
	$image .= "<a href=/feeds/sancap/rets_images/".$value." rel=\"enlargeimage\" rev=\"targetdiv:loadarea\">";
	$image .= "<img src=/feeds/sancap/rets_images/".$value." alt='' width='100' height='75' border='0' />";
	$image .= "</a>&nbsp;";
	
$img_cnt++;
}

?>

Open in new window

0
pda4meAuthor Commented:
so close...there is one image that is first that needs to be last...the first image $MLNumber.jpg with no _$c_ext.jpg ends up as the first thumbnail...anyway to kick that one back to the end of the line?

Thanks!
0
Greg AlexanderLead DeveloperCommented:
Here, try this:
<?
$url = "http://www.mysite.com/feeds/sancap/rets_images/";
for($c=1;$c<30;$c++){
        
        if($c<10){
                $c_ext = "0".$c;
        }else{
                $c_ext = $c;
        }
        
        if (file_get_contents($url."{$MLNumber}_{$c_ext}.jpg")){
                $image_array[$c_ext] = "{$MLNumber}_{$c_ext}.jpg";      
        }
        
}

ksort($image_array);

$image_array[$c_ext] = "{$MLNumber}.jpg"; 

$img_cnt = 1;
$image = "<br>";
foreach($image_array as $key => $value){
        
        $image .= "<a href=/feeds/sancap/rets_images/".$value." rel=\"enlargeimage\" rev=\"targetdiv:loadarea\">";
        $image .= "<img src=/feeds/sancap/rets_images/".$value." alt='' width='100' height='75' border='0' />";
        $image .= "</a>&nbsp;";
        
$img_cnt++;
}

?>

Open in new window

0
Greg AlexanderLead DeveloperCommented:
Sorry.... use this one
<?
$url = "http://www.mysite.com/feeds/sancap/rets_images/";
for($c=1;$c<30;$c++){
        
        if($c<10){
                $c_ext = "0".$c;
        }else{
                $c_ext = $c;
        }
        
        if (file_get_contents($url."{$MLNumber}_{$c_ext}.jpg")){
                $image_array[$c_ext] = "{$MLNumber}_{$c_ext}.jpg";      
        }
        
}

ksort($image_array);

$image_array[] = "{$MLNumber}.jpg"; 

$img_cnt = 1;
$image = "<br>";
foreach($image_array as $key => $value){
        
        $image .= "<a href=/feeds/sancap/rets_images/".$value." rel=\"enlargeimage\" rev=\"targetdiv:loadarea\">";
        $image .= "<img src=/feeds/sancap/rets_images/".$value." alt='' width='100' height='75' border='0' />";
        $image .= "</a>&nbsp;";
        
$img_cnt++;
}

?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pda4meAuthor Commented:
Awesome, thanks so much!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.