carlosx2 Posted October 23, 2009 Share Posted October 23, 2009 i have this script that i made only i try to also put in a if else for for some reason the script is not putting out the else echo. its not really a problem as the script works but it would be nice to have it work as i intended. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- .style1 {color: #FFFFFF} --> </style> </head> <body> <?php echo '<link href="path/custom/style.css" rel="stylesheet" type="text/css">'; $model = $_GET['id']; $filename = (explode (":",$model)); $filename2 = (explode ("-",$filename[1])); $space = " "; $path = $filename2[0]. $space . $filename2[1]; $user_name = ""; $password = ""; $database = ""; $server = ""; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); $model = "SELECT * FROM ..... WHERE name='$path'"; $result = mysql_query($model); while($rows=mysql_fetch_array($result)){ if ($rows['name'] == $path){ ?></p> <table width="100%" border="0" cellspacing="1" cellpadding="0" class="profile"> <tr> <td width="25%" height="113" valign="top"><table width="100%" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="27%" bgcolor="#8DCEFA">Model</td> <td width="5%" bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td width="68%" bgcolor="#FAE4AB"><? echo $rows['name']?></td> </tr> <tr> <td bgcolor="#8DCEFA">Age:</td> <td bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td bgcolor="#FAE4AB"><? echo $rows['age'] ?></td> </tr> <tr> <td bgcolor="#8DCEFA">Country</td> <td bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td bgcolor="#FAE4AB"><? echo $rows['country'] ?></td> </tr> <tr> <td bgcolor="#8DCEFA">City</td> <td bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td bgcolor="#FAE4AB"><? echo $rows['city'] ?></td> </tr> <tr> <td bgcolor="#8DCEFA">Ethnic</td> <td bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td bgcolor="#FAE4AB"><? echo $rows['ethnic'] ?></td> </tr> </table></td> <td width="19%" valign="top"><table width="100%" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="66" bgcolor="#8DCEFA">Eyes</td> <td width="12" bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td width="99" bgcolor="#FAE4AB"><? echo $rows['eyes'] ?></td> </tr> <tr> <td bgcolor="#8DCEFA">Hair</td> <td bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td bgcolor="#FAE4AB"><? echo $rows['hair'] ?></td> </tr> <tr> <td bgcolor="#8DCEFA">Height</td> <td bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td bgcolor="#FAE4AB"><? echo $rows['height'] ?></td> </tr> <tr> <td bgcolor="#8DCEFA">Weight</td> <td bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td bgcolor="#FAE4AB"><? echo $rows['weight'] ?></td> </tr> <tr> <td width="66" bgcolor="#8DCEFA">style</td> <td bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td bgcolor="#FAE4AB"><? echo $rows['style'] ?></td> </tr> </table></td> <td width="56%" valign="top"><table width="100%" border="0" cellspacing="2" cellpadding="0"> <tr> <td bgcolor="#8DCEFA">Biography</td> </tr> <tr> <td bgcolor="#FAE4AB"><? echo $rows['bio'] ?></td> </tr> </table></td> </tr> </table> <? }else { echo "it works"; } } mysql_close($db_handle); ?> </p> </body> </html> maybe sone help me figure out what i did wrong here. Quote Link to comment https://forums.phpfreaks.com/topic/178778-if-else-problem-help-please/ Share on other sites More sharing options...
lmhart Posted October 23, 2009 Share Posted October 23, 2009 Your are missing a php tag at the beginning of the else statement <? }else { echo "it works"; } } mysql_close($db_handle); ?> Quote Link to comment https://forums.phpfreaks.com/topic/178778-if-else-problem-help-please/#findComment-943097 Share on other sites More sharing options...
carlosx2 Posted October 23, 2009 Author Share Posted October 23, 2009 i don't see where i miss that. it is there so far as i can see it. Also i have the problem that on the site i have another code that won't execute for some reason. i think it has to do with opening the date base to get data. when i try another piece of code and i put it about the other piece of code (not the one displayed above) and it works perfectly. it looks like that it get stuck something where in the piece of code above. Quote Link to comment https://forums.phpfreaks.com/topic/178778-if-else-problem-help-please/#findComment-943187 Share on other sites More sharing options...
hadeosdin Posted October 23, 2009 Share Posted October 23, 2009 might be the fact you end the php after the if and then reopen it on the else just echo the for the if and it should work Quote Link to comment https://forums.phpfreaks.com/topic/178778-if-else-problem-help-please/#findComment-943188 Share on other sites More sharing options...
trq Posted October 23, 2009 Share Posted October 23, 2009 Use <?php not <? Quote Link to comment https://forums.phpfreaks.com/topic/178778-if-else-problem-help-please/#findComment-943193 Share on other sites More sharing options...
merylvingien Posted October 23, 2009 Share Posted October 23, 2009 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- .style1 {color: #FFFFFF} --> </style> </head> <body> <?php echo '<link href="path/custom/style.css" rel="stylesheet" type="text/css">'; $model = $_GET['id']; $filename = (explode (":",$model)); $filename2 = (explode ("-",$filename[1])); $space = " "; $path = $filename2[0]. $space . $filename2[1]; $user_name = ""; $password = ""; $database = ""; $server = ""; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); $model = "SELECT * FROM ..... WHERE name='$path'"; $result = mysql_query($model); while($rows=mysql_fetch_array($result)){ if ($rows['name'] == $path){ </p> <table width="100%" border="0" cellspacing="1" cellpadding="0" class="profile"> <tr> <td width="25%" height="113" valign="top"><table width="100%" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="27%" bgcolor="#8DCEFA">Model</td> <td width="5%" bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td width="68%" bgcolor="#FAE4AB"><{$rows['name']}></td> </tr> <tr> <td bgcolor="#8DCEFA">Age:</td> <td bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td bgcolor="#FAE4AB"><{$rows['age']}></td> </tr> <tr> <td bgcolor="#8DCEFA">Country</td> <td bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td bgcolor="#FAE4AB"><{$rows['country']}></td> </tr> <tr> <td bgcolor="#8DCEFA">City</td> <td bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td bgcolor="#FAE4AB"><{$rows['city']}></td> </tr> <tr> <td bgcolor="#8DCEFA">Ethnic</td> <td bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td bgcolor="#FAE4AB"><{$rows['ethnic']}></td> </tr> </table></td> <td width="19%" valign="top"><table width="100%" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="66" bgcolor="#8DCEFA">Eyes</td> <td width="12" bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td width="99" bgcolor="#FAE4AB"><{$rows['eyes']}></td> </tr> <tr> <td bgcolor="#8DCEFA">Hair</td> <td bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td bgcolor="#FAE4AB"><{$rows['hair']}></td> </tr> <tr> <td bgcolor="#8DCEFA">Height</td> <td bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td bgcolor="#FAE4AB"><{$rows['height']}></td> </tr> <tr> <td bgcolor="#8DCEFA">Weight</td> <td bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td bgcolor="#FAE4AB"><{$rows['weight']}></td> </tr> <tr> <td width="66" bgcolor="#8DCEFA">style</td> <td bgcolor="#003464"><div align="center"><span class="style1">:</span></div></td> <td bgcolor="#FAE4AB"><{$rows['style']}></td> </tr> </table></td> <td width="56%" valign="top"><table width="100%" border="0" cellspacing="2" cellpadding="0"> <tr> <td bgcolor="#8DCEFA">Biography</td> </tr> <tr> <td bgcolor="#FAE4AB"><{$rows['bio']}></td> </tr> </table></td> </tr> </table> }else { echo "it works"; } } mysql_close($db_handle); ?> </p> </body> </html> You may need to change the double quotes to singles, but see how that works out, i have had some drinks so dont blame me if it dont work lol Quote Link to comment https://forums.phpfreaks.com/topic/178778-if-else-problem-help-please/#findComment-943213 Share on other sites More sharing options...
trq Posted October 23, 2009 Share Posted October 23, 2009 You may need to change the double quotes to singles, but see how that works out, i have had some drinks so dont blame me if it dont work lol Surely its your fault for drinking though Anyway, your code will result in nothing but parse errors. You have plain html within php. Quote Link to comment https://forums.phpfreaks.com/topic/178778-if-else-problem-help-please/#findComment-943214 Share on other sites More sharing options...
merylvingien Posted October 24, 2009 Share Posted October 24, 2009 Yea i know i was being lazy, thats why i added the note about double quotes, surely the fella can add them in? Quote Link to comment https://forums.phpfreaks.com/topic/178778-if-else-problem-help-please/#findComment-943219 Share on other sites More sharing options...
merylvingien Posted October 24, 2009 Share Posted October 24, 2009 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- .style1 {color: #FFFFFF} --> </style> </head> <body> <?php echo '<link href="path/custom/style.css" rel="stylesheet" type="text/css">'; $model = $_GET['id']; $filename = (explode (":",$model)); $filename2 = (explode ("-",$filename[1])); $space = " "; $path = $filename2[0]. $space . $filename2[1]; $user_name = ""; $password = ""; $database = ""; $server = ""; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); $model = "SELECT * FROM ..... WHERE name='$path'"; $result = mysql_query($model); while($rows=mysql_fetch_array($result)){ if ($rows['name'] == $path){ echo "</p> <table width='100%' border='0' cellspacing='1' cellpadding='0' class='profile'> <tr> <td width='25%' height='113' valign='top'><table width='100%' border='0' cellspacing='2' cellpadding='0'> <tr> <td width='27%' bgcolor='#8DCEFA'>Model</td> <td width='5%' bgcolor='#003464'><div align='center'><span class='style1'>:</span></div></td> <td width='68%' bgcolor='#FAE4AB'><{$rows['name']}></td> </tr> <tr> <td bgcolor='#8DCEFA'>Age:</td> <td bgcolor='#003464'><div align='center'><span class='style1'>:</span></div></td> <td bgcolor='#FAE4AB'><{$rows['age']}></td> </tr> <tr> <td bgcolor='#8DCEFA'>Country</td> <td bgcolor='#003464'><div align='center'><span class='style1'>:</span></div></td> <td bgcolor='#FAE4AB'><{$rows['country']}></td> </tr> <tr> <td bgcolor='#8DCEFA'>City</td> <td bgcolor='#003464'><div align='center'><span class='style1'>:</span></div></td> <td bgcolor='#FAE4AB'><{$rows['city']}></td> </tr> <tr> <td bgcolor='#8DCEFA'>Ethnic</td> <td bgcolor='#003464'><div align='center'><span class='style1'>:</span></div></td> <td bgcolor='#FAE4AB'><{$rows['ethnic']}></td> </tr> </table></td> <td width='19%' valign='top'><table width='100%' border='0' cellspacing='2' cellpadding='0'> <tr> <td width='66' bgcolor='#8DCEFA'>Eyes</td> <td width='12' bgcolor='#003464'><div align='center'><span class='style1'>:</span></div></td> <td width='99' bgcolor='#FAE4AB'><{$rows['eyes']}></td> </tr> <tr> <td bgcolor='#8DCEFA'>Hair</td> <td bgcolor='#003464'><div align='center'><span class='style1'>:</span></div></td> <td bgcolor='#FAE4AB'><{$rows['hair']}></td> </tr> <tr> <td bgcolor='#8DCEFA'>Height</td> <td bgcolor='#003464'><div align='center'><span class='style1'>:</span></div></td> <td bgcolor='#FAE4AB'><{$rows['height']}></td> </tr> <tr> <td bgcolor='#8DCEFA'>Weight</td> <td bgcolor='#003464'><div align='center'><span class='style1'>:</span></div></td> <td bgcolor='#FAE4AB'><{$rows['weight']}></td> </tr> <tr> <td width='66' bgcolor='#8DCEFA'>style</td> <td bgcolor='#003464'><div align='center'><span class='style1'>:</span></div></td> <td bgcolor='#FAE4AB'><{$rows['style']}></td> </tr> </table></td> <td width='56%' valign='top'><table width='100%' border='0' cellspacing='2' cellpadding='0'> <tr> <td bgcolor='#8DCEFA'>Biography</td> </tr> <tr> <td bgcolor='#FAE4AB'><{$rows['bio']}></td> </tr> </table></td> </tr> </table></p>"; }else { echo "it works"; } } mysql_close($db_handle); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/178778-if-else-problem-help-please/#findComment-943223 Share on other sites More sharing options...
DavidAM Posted October 24, 2009 Share Posted October 24, 2009 I think thorpe is correct. The original code looks OK except that the openning tag before the else is a short tag. Maybe the OP's server does not support short tags. Apparently, this site's '[ code ]' tags don't support short tags either. Good for you! It's a nasty habit. Hey, can we get the government to ban short tags in public places? They are hazardous to the internet's well-being. Quote Link to comment https://forums.phpfreaks.com/topic/178778-if-else-problem-help-please/#findComment-943284 Share on other sites More sharing options...
carlosx2 Posted October 24, 2009 Author Share Posted October 24, 2009 ok going to try it out. thanks Quote Link to comment https://forums.phpfreaks.com/topic/178778-if-else-problem-help-please/#findComment-943437 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.