Jump to content

[SOLVED] Execute PHP code from within an ECHO


karl_009

Recommended Posts

Hi,

 

I have a form that I have set up to INSERT data into, now am trying to set it up so that I can edit the data that has been entered.

 

My table output is via an echo which out puts all the table but I need to execute a small PHP script from there so that I can click on the update link and the row for data is selected from the database.

 

Here is the code;

 

// Database Connection

<html>
<title>View Contacts</title>
<center>
<table bgcolor="#0066FF" border="0" width="75%" cellspacing="1" cellpadding="2">
<?php
// Query for displaying data in the order of the persons last name
$query = "SELECT * FROM contacts ORDER BY last";
$result = mysql_query ($query, $connection);

for ($i = 0; $i < mysql_num_rows ($result); $i++)
{
	$first = mysql_result ($result, $i,"first");
	$last = mysql_result ($result, $i,"last");
	$company = mysql_result ($result, $i,"company");
	$town = mysql_result ($result, $i,"town");
	$email = mysql_result ($result, $i,"email");
	$email_len = strlen($email);

	if ($i % 2)
	{
		$bg_color="#EEEEEE";
	}
	else
	{
		$bg_color="#AAAAAA";
	}

	echo '
		<tr>
			<td width="30%" bgcolor="'.$bg_color.'">
				<font face="arial" size="2">';
					if ($email_len > 0)
					{
						echo '<b>First Name:</b> <a href="mailto:'.$email.'">'.$first.'</a>';
					}
					else
					{
						echo '<b>First Name:</b> '.$first;
					}
					echo '
					<br>
					<b>Last Name:</b> '.$last.'
					</font>
				<td>
				<td width="20%" valign="top" bgcolor="'.$bg_color.'">
					<font face="arial" size="2">
						<b> Email: </b> '.$email.'
					</font>
				</td>
				<td>
				<td width="20%" valign="top" bgcolor="'.$bg_color.'">
					<font face="arial" size="2">
						<b> Town: </b> '.$town.'
					</font>
				</td>	
				<td>
				<td width="20%" valign="top" bgcolor="'.$bg_color.'">
					<font face="arial" size="2">
						<b> Company: </b> '.$company.'
					</font>
				</td>
				<td>

// This is the line where I am trying to run this code within the echo...
				<td width="10%" valign="top" bgcolor="'.$bg_color.'"><a href="contact_edit.php?id=<?php echo $rows['id'];?>">Update</a>
					<font face="arial" size="2">
					</font>
				</td>
			</tr>
		';
}
?>
</table>

</center>

<body>
</body>
</html>

 

<td width="10%" valign="top" bgcolor="'.$bg_color.'"><a href="contact_edit.php?id=<?php echo $rows['id'];?>">Update</a>

 

Many Thanks for any help

Karl

<td width="10%" valign="top" bgcolor="'.$bg_color.'"><a href="contact_edit.php?id=<?php echo $rows['id];?>">Update</a>

 

You are using <?php tags inside of an echo. Concat it like King has done, or like you have done previously and it should work.

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.