Dyllon |
|
---|---|
I'm looking to create something similar to Cotonti.com's private message feature. I've been browsing around through the source code, but I don't know how to achieve it. From what I gather, this is the main part of it on the javascript end: $.getJSON('index.php?r=pm_json', function(data) { var rows = '<ol>'; $.each(data, function(key, val) { console.log(val); var url = 'pm?m=message&id=0'.replace('0', val.pm_id); rows += '<li><a href="'+url+'">'+val.pm_title+'</a><small>Sender: '+val.pm_fromuser+'</small></li>'; }); rows += '</ol>'; $('#pmbox').prepend(rows); }); I just can't seem to figure out how to PHP side of it goes. Any insight? We are what we repeatedly do. Excellence then, is not an act, but a habit.
|
Trustmaster |
|
---|---|
It's as simple as this: <?php defined('COT_CODE') or die('Wrong URL.'); /* ==================== [BEGIN_COT_EXT] Hooks=ajax [END_COT_EXT] ==================== */ if ($usr['id'] > 0 && COT_AJAX) { require_once cot_incfile('pm', 'module'); if ($usr['newpm']) { echo json_encode($db->query("SELECT * FROM $db_pm WHERE pm_touserid=? AND pm_tostate=0", $usr['id'])->fetchAll()); } }
May the Source be with you!
|
Sergey |
|
---|---|
Function json_encode does not work correctly. It is with a large array of data gives an error when processing objects and arrays. This function corrects the errors. In the form, I keep the contents of pages, it increases the rate of conversion of pages in a friendly layout: function object_in_array // преобразование структуры в массивы. исправление косяка json_decode ( // внимание! функция рекурсивная. $объект // @param - сложная структура состоящая из объектов и массивов ) { if (!is_object($объект) and !is_array($объект)) return $объект; if (is_object($объект)) $объект = get_object_vars($объект); return array_map('object_in_array',$объект); }
www.cotonti.mobi
|
Trustmaster |
|
---|---|
In the above example fetchAll() method always returns an array of arrays, not objects. May the Source be with you!
|