Jump to content

[SOLVED] Building dynamic array key from array


xstevey_bx

Recommended Posts

$query = "SELECT * FROM users WHERE id=$id";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$row = mysql_fetch_array ($result, MYSQL_NUM);

if ($num == 1) 
{
echo '<h3>Edit User</h3><form action="?id=news_comment_edit&num='.$id.'" method="post">';

$arr = array('id', 'username', 'password', 'email', 'forename', 'surname', 'country', 'state', 'postcode', 'dob', 'gender', 'registrationdate', 'lastlogin', 'code', 'activated');

foreach ($arr as $value) 
{
	echo '<p>'.$value.' : <input type="text" name="'.$value.'" size="25" maxlength="255" value="'. $row[{$value}] .'" /></p><br/>'; 
}

unset($value);
}

 

This is a snippet from a code from an edit information page. Im trying to build a form from a list of MySQL column names stored in an array.

 

The problem is in the line

 

echo '<p>'.$value.' : <input type="text" name="'.$value.'" size="25" maxlength="255" value="'. $row[{$value}] .'" /></p><br/>';

 

I want the

$row[{$value}]

to show the information stored in  the $row = mysql_fetch_array depending on what the $value in the foreach loop is

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.