- Moderated by:
- Support
-
- rank:
-
Freshman
- registered:
- August 2004
- Status:
- offline
- last visit:
- 15.06.08
- Posts:
- 24
I have problems filling up the variable that would have to contain the data of the table of the data base
This is the source code:
Code
function hpnProjects_userapi_getallcats($args)
{
// Extraemos los argumentos
extract($args);
$cats = array();
// Chequeo de seguridad
if (!pnSecAuthAction(0, 'hpnProjets::', '::', ACCESS_READ)) {
return $cats;
}
// Conectamos con la base de dato
$dbconn =& pnDBGetConn(true);
$pntable =& pnDBGetTables();
// Llamamos a la tabla y a la columna
$categories_table = $pntable['hpnprojects_categories'];
$categories_table_column = &$pntable['hpnprojects_categories_column'];
// Obtenemos los items
$sql = "SELECT $categories_table_column[cid],
$categories_table_column[title],
$categories_table_column[image]
FROM $categories_table
ORDER BY $categories_table_column[cid]";
$result = $dbconn->Execute($sql);
// Chequeamos que no haya errores o devolvemos el mensaje adecuado
if ($dbconn->ErrorNo() != 0) {
pnSessionSetVar('errormsg', _GETFAILED);
return false;
}
for (; !$result->EOF; $result->MoveNext()) {
list($cid, $title, $image) = $result->fields;
if (pnSecAuthAction(0, 'hpnProjects::', "$cid::", ACCESS_READ)) {
$cats[] = array('cid' => $cid,
'title' => $title,
'image' => $image);
}
}
// Retornamos las categorias
return $cats;
}
You check that there isn't any error, please.
Thanks!
--
JaooZi -
- rank:
-
Steering Committee
- registered:
- December 2002
- Status:
- online
- Posts:
- 13418
What sort of problems are you having? Have you tried echoing out the SQL to check it's correct?
--
Regards,
Simon
itbegins.co.uk - Zikula Consulting
Please read the Support Guide -
- rank:
-
Freshman
- registered:
- August 2004
- Status:
- offline
- last visit:
- 15.06.08
- Posts:
- 24
The problem is _HPNPROJECTS_CATFAILED:
Code
if (!$cats) {
return pnVarPrepHTMLDisplay(_HPNPROJECTS_CATFAILED);
}
The $SQL variable return: SELECT pn_cid, pn_title, pn_image FROM pn_hpnprojects_categories ORDER BY pn_cid
--
JaooZi -
- rank:
-
Freshman
- registered:
- August 2004
- Status:
- offline
- last visit:
- 15.06.08
- Posts:
- 24
-
- rank:
-
Helper
- registered:
- November 2004
- Status:
- offline
- last visit:
- 12.03.07
- Posts:
- 387
No problem. Glad it was easy to find! I get stupid comma errors that I can't see because I just am not used to looking for them, and I tear my hair out before I find them, then feel dumb walking around bald. ;) -
- rank:
-
Freshman
- registered:
- August 2004
- Status:
- offline
- last visit:
- 15.06.08
- Posts:
- 24
I have another problem. It doesn't print the things in screen. This it is hpnprojects_user_view.htm:
Code
Thanks
--
JaooZi -
- rank:
-
Steering Committee
- registered:
- December 2002
- Status:
- online
- Posts:
- 13418
Should that not be:
Code
<!--[foreach item=cat from=$cats]-->
<li><!--[$cat]--></li>
<!--[/foreach]-->
--
Regards,
Simon
itbegins.co.uk - Zikula Consulting
Please read the Support Guide -
- rank:
-
Freshman
- registered:
- August 2004
- Status:
- offline
- last visit:
- 15.06.08
- Posts:
- 24
-
- rank:
-
Helper
- registered:
- November 2004
- Status:
- offline
- last visit:
- 12.03.07
- Posts:
- 387
I think the problem, in addition to the cat vs. cats issue, is that your new $cat variable will be an array.
Code
<!--[foreach item=cat from=$cats]-->
<li><!--[$cat.title]--></li>
<!--[/foreach]-->
That should show you the title of the category. -
- rank:
-
Freshman
- registered:
- August 2004
- Status:
- offline
- last visit:
- 15.06.08
- Posts:
- 24
it doesn't work. In case it serves to you, this is the pnuser.php function:
Code
function hpnProjects_user_viewcats($args)
{
// Chequeo de seguridad
if (!pnSecAuthAction(0, 'hpnProjects::', '::', ACCESS_OVERVIEW)) {
return pnVarPrepHTMLDisplay(_MODULENOAUTH);
}
// Llamamos a la funcion API
$cats = pnModAPIFunc( 'hpnProjects',
'user',
'getallcats');
// Comprobamos que se ha rellenado la variable cats. Si no devolvemos el mensaje apropiado
if (!$cats) {
return pnVarPrepHTMLDisplay(_HPNPROJECTS_CATFAILED);
}
// Create output object
$pnRender =& new pnRender('hpnProjects');
// Loop through each item and display it.
// Note that we do NOT use pnVarPrepForDisplay, pnVarCensor or anything like
// that here as this is left to the template to simplify the code.
$hpnprojectscats = array();
foreach ($cats as $cat) {
if (pnSecAuthAction(0,
'hpnProjects::',
"$cat[cid]::",
ACCESS_READ)) {
$pnRender->assign($cat);
$hpnprojectscats[] = $pnRender->fetch('hpnprojects_user_row_read.htm', $cat['cid']);
}
}
// Return the output that has been generated by this function
return $pnRender->fetch('hpnprojects_user_view.htm');
}
--
JaooZi -
- rank:
-
Freshman
- registered:
- August 2004
- Status:
- offline
- last visit:
- 15.06.08
- Posts:
- 24
-
- rank:
-
Helper
- registered:
- November 2004
- Status:
- offline
- last visit:
- 12.03.07
- Posts:
- 387
Heh. Any time. It took me quite a few months to learn how to look for the source of problems when making my modules. Always happy to share what I've learned. (Too happy, my friends probably think!) :)
