kissfreaque Posted April 16, 2010 Share Posted April 16, 2010 I have a rollover problem. I want to use an If/Else here and it is not working. The original code is this: <td width="111"><a href="resources.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Resources','','navigation/resources1.jpg',0)"><img src="navigation/resources.jpg" alt="Resources" name="Resources" width="111" height="63" border="0" id="Resources" /></a></td> and my new statement depends on a variable, so I wrote this: <?php if ($ID == "resources") { echo ("<td width='111'><img src='navigation/resources2.jpg' alt='Resources' width='111' height='63' /></td>"); } else { echo ("<td width='111'><a href='resources.php' onmouseout='MM_swapImgRestore()' onmouseover='MM_swapImage('Resources','','navigation/resources1.jpg',0)'><img src='navigation/resources.jpg' alt='Resources' name='Resources' width='111' height='63' border='0' id='Resources' /></a></td>");} ?> So when the variable is false, or "else", I needed to go in and change all the " to ' since it is already in an " ". Everything works except for the rollover. everything here ('Resources','','navigation/resources1.jpg',0) was already a single ', and I have no clue of how to handle this part. Please help if you can. Link to comment https://forums.phpfreaks.com/topic/198739-php-if-else-help-needed/ Share on other sites More sharing options...
deanlearner Posted April 16, 2010 Share Posted April 16, 2010 you can use \" to print a " even if it is between " ... " echo "quote \"within\" a quote"; will show quote "within" a quote The same logic goes with using \' between ' ... ' Link to comment https://forums.phpfreaks.com/topic/198739-php-if-else-help-needed/#findComment-1042990 Share on other sites More sharing options...
TeddyKiller Posted April 16, 2010 Share Posted April 16, 2010 No errors here. <?php if ($ID == "resources") { echo '<td width="111"><img src="navigation/resources2.jpg" alt="Resource" width="111" height="63" /></td>'; } else { echo '<td width="111"><a href="resources.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'Resources\',\'\',\'navigation/resources1.jpg\',0)"><img src="navigation/resources.jpg" alt="Resources" name="Resources" width="111" height="63" border="0" id="Resources" /></a></td>'; } ?> Your origional code.. good lord, it was ugly. Link to comment https://forums.phpfreaks.com/topic/198739-php-if-else-help-needed/#findComment-1042995 Share on other sites More sharing options...
litebearer Posted April 16, 2010 Share Posted April 16, 2010 just a thought 1. the if in php 2. drop out of php and use nice clean easy to use html/js 3. the else in php 4. drop out of php and use nice clean easy to use html/js 5. the endif in php for me, that makes trying keep track of single/double quotes mute Link to comment https://forums.phpfreaks.com/topic/198739-php-if-else-help-needed/#findComment-1042996 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.