phplearner2008 Posted September 22, 2008 Share Posted September 22, 2008 Hi, I have a piece of code which should be executed as many times as mentioned in for loop. Here is the code: <?php session_start(); $MID[] = $_SESSION['MID']; for($i=0;$i<3;$i++) { ?> <form name="form1" method="post" action="expressInterest.php"> <table width="75%" border="1" align="center" cellspacing="1" cellpadding="1"> <tr><td> Matrimonial ID </td> <td> <? echo "$MID[]"; ?> </td></tr></table></form> <? } ?> I want this piece of html code to be executed three times. I do not want to echo the whole html code but execute as it is. What mistake am I doing? Thank you Link to comment https://forums.phpfreaks.com/topic/125282-solved-how-to-execute-html-code-inside-for-loop/ Share on other sites More sharing options...
ranjuvs Posted September 22, 2008 Share Posted September 22, 2008 Try this <?php session_start(); $MID[] = $_SESSION['MID']; ?> <form name="form1" method="post" action="expressInterest.php"> <table width="75%" border="1" align="center" cellspacing="1" cellpadding="1"> <tr><td> Matrimonial ID </td> </tr> <? for($i=0;$i<3;$i++) { <tr> <td> echo "$MID[]"; ?> </td></tr> <?php } ?> </table></form> Link to comment https://forums.phpfreaks.com/topic/125282-solved-how-to-execute-html-code-inside-for-loop/#findComment-647589 Share on other sites More sharing options...
gaza165 Posted September 22, 2008 Share Posted September 22, 2008 why are u making $_SESSION['mid'] an array?? Link to comment https://forums.phpfreaks.com/topic/125282-solved-how-to-execute-html-code-inside-for-loop/#findComment-647596 Share on other sites More sharing options...
ranjuvs Posted September 22, 2008 Share Posted September 22, 2008 I only answered for your question Link to comment https://forums.phpfreaks.com/topic/125282-solved-how-to-execute-html-code-inside-for-loop/#findComment-647599 Share on other sites More sharing options...
gaza165 Posted September 22, 2008 Share Posted September 22, 2008 ranjav u should check your code... there are mistakes in it phplearner2008 try this code... <? session_start(); $MID = $_SESSION['MID']; for($i=0;$i<3;$i++) { ?> <form name="form1" method="post" action="expressInterest.php"> <table width="75%" border="1" align="center" cellspacing="1" cellpadding="1"> <tr> <td>Matrimonial ID</td> <? echo "<td>".$MID."</td>"; } ?> </tr> </table> </form> Link to comment https://forums.phpfreaks.com/topic/125282-solved-how-to-execute-html-code-inside-for-loop/#findComment-647604 Share on other sites More sharing options...
phplearner2008 Posted September 22, 2008 Author Share Posted September 22, 2008 Dear all, I have shown only part of my code as it is awfully long. I am trying to output ID and other details of several people. That's why I stored $MID[] as array.It is something like this ... <?php $MID[] = $row['MATRIMONIAL_ID']; $NAME[] = $row['NAME']; $AGE[] = $row['AGE']; $HEIGHT[] = $row['HEIGHT']; $RELIGION[] = $row['RELIGION']; $CASTE[] = $row['CASTE']; $OCCUPATION[] = $row['OCCUPATION']; $EDUCATION[] = $row['EDUCATION']; $COUNTRY[] = $row['COUNTRY']; $STATE[] = $row['STATE']; $CITY[] = $row['CITY']; for($i=0;$i<$limit;$i++) { ?> <form name="form1" method="post" action="expressInterest.php"> <table width="75%" border="1" align="center" cellspacing="1" cellpadding="1"> <tr><td> <table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" background="slices/colour.gif"> <tr><td width="19%"><img src="" alt="Photo not available" name="PHOTO" width="100" height="100" id="PHOTO"></td> <td width="81%"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr width = "30%"><td ><div align="right">Matrimonial ID:</div></td> <td> <? echo "$MID[]"; ?> <input type = "hidden" name = "FROM" value = "'.$MYLOGIN.'"> <input type = "hidden" name = "FROMGENDER" value = "'.$FROMGENDER.'"> <input type = "hidden" name = "TO" value = "'.$row['MATRIMONIAL_ID'].'"> <input type = "hidden" name = "TOGENDER" value = "'.$GENDER.'"> <input type = "hidden" name = "THISDATE" value = "'.$today.'"> </td></tr> <tr><td><div align="right">Name :</div></td> <td><? echo "$NAME[]"; ?> </td></tr> <tr><td><div align="right">Age :</div></td> <td> <? echo "$AGE[]"; ?> </td></tr> <tr><td><div align="right">Height :</div></td> <td> <? echo "$HEIGHT[]"; ?> </td></tr> <tr><td><div align="right">Religion : </div></td> <td> <? echo "$RELIGION[]"; ?> </td></tr> <tr><td><div align="right">Caste :</div></td> <td> <? echo "$CASTE[]"; ?> </td></tr> <tr><td><div align="right">Occupation : </div></td> <td> <? echo "$OCCUPATION[]"; ?> </td></tr> <tr><td><div align="right">Education : </div></td> <td> <? echo "$EDUCATION[]"; ?> </td></tr> <tr><td><div align="right">Country : </div></td> <td> <? echo "$COUNTRY[]"; ?> </td></tr> <tr><td><div align="right">State : </div></td> <td> <? echo "$STATE[]"; ?> </td></tr> <tr><td><div align="right">City : </div></td> <td> <? echo "$CITY[]"; ?> </td></tr></table></td></tr></table> <tr><td> <table width="100%" border="0" align="center" cellspacing="0" cellpadding="0"> <tr><td><div align="left"> <a href = "http://localhost/matrimonial/FullProfile.php<? id='.$MID.' ?>">Full Profile >> </a> </div><div align="right"> <input type="submit" name="Express_Interest" value = "Express Interest"> </div></td></tr></table></td></tr></table></form> I am sorry if the code is very long I included for better explanation Link to comment https://forums.phpfreaks.com/topic/125282-solved-how-to-execute-html-code-inside-for-loop/#findComment-647606 Share on other sites More sharing options...
ranjuvs Posted September 22, 2008 Share Posted September 22, 2008 Try this <?php session_start(); $MID[] = $_SESSION['MID']; ?> <form name="form1" method="post" action="expressInterest.php"> <table width="75%" border="1" align="center" cellspacing="1" cellpadding="1"> <tr><td> Matrimonial ID </td> </tr> <?php for($i=0;$i<3;$i++) { ?> <tr> <td> MATRIMONIAL_ID:<?php echo $row['MATRIMONIAL_ID'][$i]; ?> </td></tr> <tr> <td> NAME:<?php echo $row['NAME'][$i]; ?> </td></tr> <?php } ?> </table></form> Link to comment https://forums.phpfreaks.com/topic/125282-solved-how-to-execute-html-code-inside-for-loop/#findComment-647609 Share on other sites More sharing options...
ranjuvs Posted September 22, 2008 Share Posted September 22, 2008 Sorry the above will do. Let me know if that works for you or not Link to comment https://forums.phpfreaks.com/topic/125282-solved-how-to-execute-html-code-inside-for-loop/#findComment-647614 Share on other sites More sharing options...
nadeemshafi9 Posted September 22, 2008 Share Posted September 22, 2008 what the hell DO U WHANT THE FORM to submit or are you trying to output the html ? u need an understanding of client server scripting Link to comment https://forums.phpfreaks.com/topic/125282-solved-how-to-execute-html-code-inside-for-loop/#findComment-647635 Share on other sites More sharing options...
phplearner2008 Posted September 22, 2008 Author Share Posted September 22, 2008 ranjuvs, Thanks for your suggestion. The code works with foll code. echo $row['MATRIMONIAL_ID']; No for loop required. When I looped, the same id was printed so many number of times. Thanks for your time. Link to comment https://forums.phpfreaks.com/topic/125282-solved-how-to-execute-html-code-inside-for-loop/#findComment-647636 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.