ok, either mysql is being stupid or I am...
whenever i try to run this:
$mycountry_query = $db->query("SELECT fid FROM ".TABLE_PREFIX."profilefields WHERE name = 'country'");
It returns the FID as "RESOURCE ID #78" or something, breaking the rest of the file...
Basically, it should find the fid in the mybb_profilefields table where the name equals "country"....
What am i doing wrong?
(2010-07-06, 10:04 AM)Tommyk Wrote: [ -> ]What am i doing wrong?
You doesn't use the MyBB database layer in the right way. You just want to select something? Use this:
$mycountry_query = $db->simple_select('profilefields', 'fid', 'name = "country"');
If "country" is the value of a variable set by a user, use this instead:
$search = 'country';
$mycountry_query = $db->simple_select('profilefields', 'fid', 'name = "' . $db->escape_string($search) . '"');
What I am trying to do is find out what the profile field is, in userfields it creates a column name fidx with the x being the fid in the profile fields table. I needto find what the fid is for the country field
You have to actually fetch the result of the query, $mycountry_query is a resource, not an actual value.
$query = $db->simple_select("profilefields", "fid", "name = 'category'");
// and then either...
$fid = $db->fetch_field($query, "fid");
echo $fid;
// or...
$field = $db->fetch_array($query);
echo $field['fid'];
Ok now that gives me a "4" which is correct. I append that to fid like so:
$mycountry = "fid".$fid;
Now i need to search for that field in the db.
$query = $db->simple_select("userfields", $mycountry, "ufid = $mybb->user['uid']");
$fid = $db->fetch_field($query, $mycountry);
echo mycountry;
But I still get a resource id
$mycountry = "fid".$fid;
$query = $db->simple_select("userfields", $mycountry, "ufid = $mybb->user['uid']");
$fid = $db->fetch_field($query, "fid4");
//echo $mycountry; this will display the number 4, because of the first line
echo $fid;
Try that.
You'd need to change:
$fid = $db->fetch_field($query, "fid4");
to:
$fid = $db->fetch_field($query, $mycountry);
Ok, i fixed it with a bit of tinkering
Thanks all
Wouldn't this be better with a left join to grab in one query?
Probably
But to be honest, I don't exactly know how to do that XD