问题
Following from Way/coding method to do activitylist/log
I worked with the accepted answer on above question, by having two tables one for the descriptions of the activities, and other for the activities themselves..
table: activitylist
Columns:
id, description, date
table: activities
Column:
id, aID, uID, date
aID is activity id, uID is user id. activity id is the id in table ´activitylist´
I can now output:
person ate another persons apple
As this text is non-personal and can be used to all..
What if i would like to output:
Michael ate Peters apple
(example)
That will require to split up in the description/text?
I thought of that you would need to include the uIDs of Michael and Peter somewhere, but where? And how should i work with that splitted description?
I mean i cant make a row in table activitylist with description: "Michael ate Peters apple" as im trying to make these descriptions universal so it could be Adam and Julia instaed of michael and peter..
Hope you understand, please comment if questions..
Update: Conclusion:
Theres a activity list that shows all activities done on the page, that all users can see. Then i wish to show an activity as "Mike has commented on Peters photo". How can i make an activity description when it includes users (this case: Mike, peter)
回答1:
Just add another column to activities and call it uID2. Then in your description put something like '##UID1## commented on ##UID2##'s photo' then use str_replace to replace ##UID1## and ##UID2## like this:
$description = activitylist['description'];
$description = str_replace('##UID1##', $uid, $description);
$description = str_replace('##UID2##', $uid2, $description);
You'll of course have to query your database to replace the id with the name associated with that user id but that's the basic logic you could use with your current setup.
回答2:
If I were to do something like that, I would have all of the varchars store strings which can be parsed by sprintf.
$uid1 = 'Frank'; $uid2 = 'George';
$format = '%s ate %s\'s apple';
$ret = sprintf($format, $uid1, $uid2);
echo $ret; // Frank ate George's apple
来源:https://stackoverflow.com/questions/6893120/coding-structure-for-an-activitylist