vmavrou Posted January 14, 2009 Share Posted January 14, 2009 Hi! I'm having this problem..i have made this code.. $result = mysql_query("SELECT * FROM groupspu"); $fields_num = mysql_num_fields($result); while ($field = mysql_fetch_field($result)) { $query = "SELECT $field->name FROM groupspu WHERE $field->name ='$username'"; $result = mysql_query($query); $numrows = mysql_num_rows($result); if ($numrows!=0) { $grr = $field->name; } ------>HERE IS THE PROBLEM $newgr = $newgr."/".$grr; } } How i can set the $field->name to a variable ? Becuase the way that i used $grr = $field->name; it's not working.. Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/140813-solved-mysql_fetch_field-problem/ Share on other sites More sharing options...
trq Posted January 14, 2009 Share Posted January 14, 2009 Use mysql_fetch_object if you want to use that syntax. The logic of your code however is behond me. Why exactly are you querying for all rows in the first place if all you are going to do is filter them with yet another query within your while? Your code makes little sense. Link to comment https://forums.phpfreaks.com/topic/140813-solved-mysql_fetch_field-problem/#findComment-737289 Share on other sites More sharing options...
flyhoney Posted January 14, 2009 Share Posted January 14, 2009 I think your code could be compressed to this: <?php $result = mysql_query("SELECT name FROM groupspu"); while ($field = mysql_fetch_object($result)) { $newgr = "$newgr/{$field->name}"; } ?> Link to comment https://forums.phpfreaks.com/topic/140813-solved-mysql_fetch_field-problem/#findComment-737301 Share on other sites More sharing options...
vmavrou Posted January 14, 2009 Author Share Posted January 14, 2009 Use mysql_fetch_object if you want to use that syntax. The logic of your code however is behond me. Why exactly are you querying for all rows in the first place if all you are going to do is filter them with yet another query within your while? Your code makes little sense. Yes you are right..the 2 first lines where there because at the beggining i was planning to use the num_of fields in a for loop do get the fields names but finally used while. So really there is no need of them. Too much coding lately and my mind starts getting dizzy! Thanks for the help guys. I will give a try at the fetch_object , didn't know the existance of this function. Link to comment https://forums.phpfreaks.com/topic/140813-solved-mysql_fetch_field-problem/#findComment-737330 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.