Jump to content

[SOLVED] mysql_fetch_field problem


vmavrou

Recommended Posts

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

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.

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.

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.