xstevey_bx Posted July 6, 2008 Share Posted July 6, 2008 $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 Link to comment https://forums.phpfreaks.com/topic/113495-solved-building-dynamic-array-key-from-array/ Share on other sites More sharing options...
ratcateme Posted July 6, 2008 Share Posted July 6, 2008 change $row[{$value}] to $row[$value] Scott. Link to comment https://forums.phpfreaks.com/topic/113495-solved-building-dynamic-array-key-from-array/#findComment-583156 Share on other sites More sharing options...
trq Posted July 6, 2008 Share Posted July 6, 2008 Your not returning an associative array from mysql_fetch_array(). Either use mysql_fetch_assoc() (recommended) instead or use the MYSQL_ASSOC constant. eg; $row = mysql_fetch_array ($result, MYSQL_ASSOC); Link to comment https://forums.phpfreaks.com/topic/113495-solved-building-dynamic-array-key-from-array/#findComment-583158 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.