Jump to content

[SOLVED] how to execute html code inside for loop


phplearner2008

Recommended Posts

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

 

 

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>

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>

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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.