Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting if statement... 1

Status
Not open for further replies.

cranebill

IS-IT--Management
Jan 4, 2002
1,113
US
I have this table row....

<tr>
<td><img src="../images/black_bear/bburdim.gif" width="594" height="250"></td>
</tr>

I need to be able to change the 594 and the 250 via php... we can concentrate on the 594 and I can figure it out from there...

I have this piece of code...

if ($_SESSION['res'] == '800') {
echo "200"
} elseif ($_SESSION['res'] == '1024') { echo "400"
}

So I tried:

<tr>
<td><img src="../images/black_bear/bburdim.gif" width= <?php>if ($_SESSION['res'] == '800') {
echo "200"
} elseif ($_SESSION['res'] == '1024') { echo "400"
}<php>
height="250"></td>
</tr>

Then istead of my pic resized it printed text.. what did I do wrong?
 
First of all, elseif is evil and should never be used. Assuming good indentation style, nested switch statements and if statements are much more readable and thus more maintainable.

Switching back and forth from PHP-interpreted mode to throughput mode kills performance and clouds readability.

I'm not sure what you're trying to do, but I'd try something like:

Code:
print '
	<tr>
      	<td>
      		<img src="../images/black_bear/bburdim.gif" width="';

switch ($_SESSION['res']_
{
	case '800':
		print '200';
		break;
	case '1024':
		print '400';
		break;
}

print '" height="250">
		</td>
	</tr>';

Also, if you change one dimension of the height and width of an image but not the other proportionally, the image will be out-of-shape.




Want the best answers? Ask the best questions!

TANSTAAFL!!
 
You're not escaping into PHP correctly. Try:
Code:
<? switch ($_SESSION['res']) {
   case '800':
        $wid = '200';
        break;
   case '1024':
        $wid = '400';
        break;
   default:
        $wid = '???'; //what happens if $_SESSION['res'] is neither 800 or 1024?
   } ?>
<tr>
      <td><img src="../images/black_bear/bburdim.gif" width="<?php echo $wid; ?>"
 height="250"></td>
    </tr>
I took your imbedded "if" statement out of the flow and made it into a "case" statement. I think it's easier to read than nested "if" statements.

You escape into PHP with either "<?php" or "<?" and out with "?>"

BTW "<?" only works if short tags are turned on in PHP.INI

Ken
 
For some reason I cannot get either way to work... it shows the pic but it is like 1 pixel wide...
 
Post your code. Also, do a 'show source' to see what is being generated and post that.

Ken
 
Ok I found the problem and I am not sure how to work around it....

What I am doing is using a pre made php system since my php skills arent that great. Using their control panel i input a product description. To format it correctly I used html tables which worked fine. However I am wanting to resize images according to resolution and apparently this set up will accept html but rejects the php. Sample source...

hook comes equipped with a safety latch and a thrust bearing which enables
the hook to swivel 360°.</font></td>
</tr>
</table>
<div align="left">
<table width="100%" border="0" height="250">
<? switch ($_SESSION['res']) {
case '1024':
<tr>
<td><img src="../images/black_bear/bburdim.gif" width="1000"
height="250"></td>
</tr>
} ?>

</table></p>

Right now this is my resolution so I was just trying to narrow it down to find the problem...

Does anyone have any ideas on how to maybe escape to php in this format?
 
Ok... I have made a little progress and now it is actually printing a variable...

it is printing ??? which is default as suggested above...

I am running 768x1024 resolution...

What do I have to do to see what the value of ($_SESSION['res']) is?
 
New development... it works at 800x600 resolution but not 1024x768... weird
 
Use the following code (or something similar) to see what is in the $_SESSION superglobal:
Code:
<?
echo '<pre>';print_r($_SESSION);echo '</pre>',"\n";
?>

Ken
 
Your example worked however I had to split it up between 3 different includes... what a pain... but it works lol * for you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top