Jump to content

mysql_fetch_object()


dhimo

Recommended Posts

Hei everyone.I want to update a mysql table and i want to use mysql_fetch_object() and mysql_fetch_name()I want to put the values in a textfield and then update them like <input type="text" name="{name}" value="{value}" />This is what I have so far. I cant get both fieldnames and object from the array.

$result = mysql_query("select * from tbl WHERE id = 1");$num = mysql_num_fields($result);$fieldname = array();for($i=0;$i<$num;$i++){	   $fieldname[$i] = mysql_field_name($result, $i);}while($row = mysql_fetch_object($result)){	 for($i=0;$i<$num;$i++) {		 $fieldname[$i] = $row->$fieldname[$i];	 }}

Well I used array_combine and I got all I want it. Any other ideas will be appriciated

$combine = array_combine($fieldname, $fieldvalue);foreach($combine as $field => $value) {	echo '<p><input type="text" name="'.$field.'" value="'.$value.'" /></p>'."\n";}

Thanks

Link to comment
Share on other sites

I don't get it but I say if you want to put the value of your query to text box you only have to echo itit goes like this value ="<? echo "your value here ";?>" or value="<?="your value here"?>"

Link to comment
Share on other sites

Hi...Instead of looping more than once you can do the following use of assoc functions..$result = mysql_query("select * from tbl WHERE id = 1");$resArr=mysql_fetch_assoc($result);foreach ($resArr as $key=>$val){ echo '<p><input type="text" name="'.$key.'" value="'.$val.'" /></p>'."\n";}Regards,Vijay

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...