View Full Version : Pulling data out from customfields
MikaK
08-29-2006, 11:58 PM
I'm planning to show 1 event by memebrs at their public profile.
This should be the query:
$query = "SELECT `eventid` , `userid` , `title` , `customfields` , `dateline_from`
FROM `" . TABLE_PREFIX . "event`
WHERE userid = '$userinfo[userid]'
ORDER BY `dateline_from` DESC
LIMIT 1";
In my case the customfields contains data regarding event type and location
like in the following example: a:2:{i:1;s:4:"Club";i:2;s:8:"Helsinki";}
What would be the best php code snippet for getting "Club" and "Helsinki" in displayed the final output?
Thanks for any insight.
-Mika
Corsec
08-30-2006, 02:20 AM
That is the data you want. It is an array (as seen by the "a" at the start I think) with 2 objects (denoted by the 2 at the start I believe, Im not entirely sure the inner workings of serializing data).
You can do this:
$customArray = unserialize($row["customfields"]);
array(2) {
[1]=>
string(4) "Club"
[2]=>
string(8) "Helsinki"
}
MikaK
08-30-2006, 05:15 AM
array(2) {
[1]=>
string(4) "Club"
[2]=>
string(8) "Helsinki"
}
Thanks, man! Glad to hear I'm getting there - even if by small steps:D Now... I still wonder how to formulate string (4) "Club" and string(8) "Helsinki" so it appears dynamically in the final output?
array(2) {
[1]=>
$bbinfo['calendarfield1']
[2]=>
$bbinfo['calendarfield2']
}perhaps?
This is the code outlining also the problematic, still missing variables
$limit_page1 = '1'; // Enter the number of maximum events you want to have displayed
$get_events = DB_site->query ("SELECT `eventid` , `userid` , `title` , `customfields` , `dateline_from`
FROM `" . TABLE_PREFIX . "event`
WHERE userid = '$userinfo[userid]'
ORDER BY `dateline_from` DESC
LIMIT $limit_page1");
while($events = $DB_site->fetch_array($get_events))
{
exec_switch_bg();
$events['date'] = vbdate($vboptions['dateformat'],$events['dateline_from']);
// THE PROBLEM
// how to formulate the customfields based variables ?
// Below should be pulling clendar customfield id 1
$events['type'] = ' ';
// Below should be pulling clendar customfield id 2
$events['location'] = ' ';
eval('$usersevents .= "' . fetch_template('memberinfo_usersevents') . '";');
}
Now my problem only seems to be how to implement the above offered snippet into $events['type'] = ' '; and $events['location'] = ' ';
Once again... Thank's for any insight.
-Mika
MikaK
09-09-2006, 02:25 PM
case solved and closed.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.