Programación de un foro
- Bogey
- Bogey


- Registrado: Jul 14, 2005
- Mensajes: 8211
- Loc: USA
- Status: Offline
Por el momento, tomé un proyecto de programa de un foro como una experiencia de aprendizaje tanto en programación PHP y solución de problemas (ya que los theres probable que haya problemas que iba a correr a través de)...y me encontré con uno que necesita ayuda.
Im no es realmente un problema en cuanto a cómo crear las categorías y los foros por la lista de categorías. La única manera que puedes ver haciendo esto es por medio de 2 bucles...una dentro de otra. El primer bucle sería para las categorías y el segundo dentro de ella, sería que los foros dentro de las categorías. ¿Hay otra manera, mejor de hacer esto, o se trata de la mejor manera?
Im no es realmente un problema en cuanto a cómo crear las categorías y los foros por la lista de categorías. La única manera que puedes ver haciendo esto es por medio de 2 bucles...una dentro de otra. El primer bucle sería para las categorías y el segundo dentro de ella, sería que los foros dentro de las categorías. ¿Hay otra manera, mejor de hacer esto, o se trata de la mejor manera?
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
- Anonymous
- Bot


- Registrado: 25 Feb 2008
- Mensajes: ?
- Loc: Ozzuland
- Status: Online
Abril 1st, 2011, 10:25 am
- SpooF
- ٩๏̯͡๏۶


- Registrado: May 22, 2004
- Mensajes: 3415
- Loc: Richland, WA
- Status: Offline
¿Quieres decir que para cuando usted los está mostrando?
Como en esta página: foro /
No veo ninguna razón para no utilizar un bucle anidado.
Como en esta página: foro /
No veo ninguna razón para no utilizar un bucle anidado.
#define NULL (::rand() % 2)
- Bogey
- Bogey


- Registrado: Jul 14, 2005
- Mensajes: 8211
- Loc: USA
- Status: Offline
- Bogey
- Bogey


- Registrado: Jul 14, 2005
- Mensajes: 8211
- Loc: USA
- Status: Offline
Tengo otro problema aquí...éste me tiene desconcertado sin embargo.
Tengo el trabajo de SQL, la matriz se genera al igual que lo quiero, pero estoy recibiendo algunos mensajes de aviso...No sé de qué se trata.
Las advertencias me (Bueno, técnicamente la "Advertencia", pero que arroja la misma dos veces...)
Y el PHP es...
También tengo la sensación de que podría hacer que funcionen un poco más corto pero hacer lo mismo, pero no puede llegar a averiguar cómo...
Esa función me da la siguiente matriz
[EDIT] Bueno, me las arreglé para solucionar el problema...appearantly si no hay resultados para tomar a continuación, hay obviamente nada que recorrer {} SMILIES_PATH / icon_lol.gif "alt =": lol: "title =" Laughing ">
Tengo el trabajo de SQL, la matriz se genera al igual que lo quiero, pero estoy recibiendo algunos mensajes de aviso...No sé de qué se trata.
Las advertencias me (Bueno, técnicamente la "Advertencia", pero que arroja la misma dos veces...)
Quote:
Advertencia: Argumento no válido suministrados para foreach () en C: \ wamp \ www \ CMS \ includes \ foro. php en la línea 51
Advertencia: Argumento no válido suministrados para foreach () en C: \ wamp \ www \ CMS \ includes \ foro. php en la línea 51
Advertencia: Argumento no válido suministrados para foreach () en C: \ wamp \ www \ CMS \ includes \ foro. php en la línea 51
Y el PHP es...
PHP Código: [ Select ]
<?php
/*
* forum.php
*
* Initiates the functions needed for the forum.
*/
class forum {
function forum()
{
global $db, $tpl;
// Making sure that the SQL doesn't cache results here...
$db->set_opts(array('cache_results' => false));
// Checking if there are any categories available
$sql = $db->build_key_query(array('SELECT' => '*',
'FROM' => FORUM_CAT));
if($db->num_rows($sql) == 0)
{
$tpl->error = true;
$tpl->errorMsg = "There are no categories available yet.";
}
else
{
// Initiating the forums array
$tpl->forums = array();
// The SQL to retrieve the categories from the database
$cat_sql = $db->build_key_query(array('SELECT' => '*',
'FROM' => FORUM_CAT));
// Setting the required loop variables
$inc = 0;
// The loops to get the categories and forums
foreach($db->fetch_rowset($cat_sql) as $ckey => $cvalue)
{
// The category information
$tpl->cats[$ckey] = $cvalue;
// The SQL to retrieve the forums for the categories from the database
$forums_sql = $db->build_key_query(array('SELECT' => '*',
'FROM' => FORUM_FORUMS,
'WHERE' => 'catID = ' . $cvalue['catID']));
// Looping through the forums and retrieving them
foreach($db->fetch_rowset($forums_sql) as $fkey => $fvalue)
{
// Setting the forums array
$tpl->cats[$inc]['forum'][$fkey] = $fvalue;
}
// Increasing the loop increment variable
++$inc;
}
}
}
}
/*
* forum.php
*
* Initiates the functions needed for the forum.
*/
class forum {
function forum()
{
global $db, $tpl;
// Making sure that the SQL doesn't cache results here...
$db->set_opts(array('cache_results' => false));
// Checking if there are any categories available
$sql = $db->build_key_query(array('SELECT' => '*',
'FROM' => FORUM_CAT));
if($db->num_rows($sql) == 0)
{
$tpl->error = true;
$tpl->errorMsg = "There are no categories available yet.";
}
else
{
// Initiating the forums array
$tpl->forums = array();
// The SQL to retrieve the categories from the database
$cat_sql = $db->build_key_query(array('SELECT' => '*',
'FROM' => FORUM_CAT));
// Setting the required loop variables
$inc = 0;
// The loops to get the categories and forums
foreach($db->fetch_rowset($cat_sql) as $ckey => $cvalue)
{
// The category information
$tpl->cats[$ckey] = $cvalue;
// The SQL to retrieve the forums for the categories from the database
$forums_sql = $db->build_key_query(array('SELECT' => '*',
'FROM' => FORUM_FORUMS,
'WHERE' => 'catID = ' . $cvalue['catID']));
// Looping through the forums and retrieving them
foreach($db->fetch_rowset($forums_sql) as $fkey => $fvalue)
{
// Setting the forums array
$tpl->cats[$inc]['forum'][$fkey] = $fvalue;
}
// Increasing the loop increment variable
++$inc;
}
}
}
}
- <?php
- /*
- * forum.php
- *
- * Initiates the functions needed for the forum.
- */
- class forum {
- function forum()
- {
- global $db, $tpl;
- // Making sure that the SQL doesn't cache results here...
- $db->set_opts(array('cache_results' => false));
- // Checking if there are any categories available
- $sql = $db->build_key_query(array('SELECT' => '*',
- 'FROM' => FORUM_CAT));
- if($db->num_rows($sql) == 0)
- {
- $tpl->error = true;
- $tpl->errorMsg = "There are no categories available yet.";
- }
- else
- {
- // Initiating the forums array
- $tpl->forums = array();
- // The SQL to retrieve the categories from the database
- $cat_sql = $db->build_key_query(array('SELECT' => '*',
- 'FROM' => FORUM_CAT));
- // Setting the required loop variables
- $inc = 0;
- // The loops to get the categories and forums
- foreach($db->fetch_rowset($cat_sql) as $ckey => $cvalue)
- {
- // The category information
- $tpl->cats[$ckey] = $cvalue;
- // The SQL to retrieve the forums for the categories from the database
- $forums_sql = $db->build_key_query(array('SELECT' => '*',
- 'FROM' => FORUM_FORUMS,
- 'WHERE' => 'catID = ' . $cvalue['catID']));
- // Looping through the forums and retrieving them
- foreach($db->fetch_rowset($forums_sql) as $fkey => $fvalue)
- {
- // Setting the forums array
- $tpl->cats[$inc]['forum'][$fkey] = $fvalue;
- }
- // Increasing the loop increment variable
- ++$inc;
- }
- }
- }
- }
También tengo la sensación de que podría hacer que funcionen un poco más corto pero hacer lo mismo, pero no puede llegar a averiguar cómo...
Esa función me da la siguiente matriz
Código: [ Select ]
Array
(
[0] => Array
(
[catID] => 2
[catName] => News and Announcements
[catDescription] => News and Announcements
[forums] => 1
[forum] => Array
(
[forumID] => 1
[catID] => 2
[forumName] => Policies and Procedures
[forumDescription] => All policies relating to hosting provided, and abuse/support procedures are housed within
[topics] => 0
[posts] => 0
[lastPoster] =>
)
)
[1] => Array
(
[catID] => 3
[catName] => Support Center
[catDescription] => Support Center
[forums] => 0
)
[2] => Array
(
[catID] => 4
[catName] => On-Topic Discussion
[catDescription] => On-Topic Discussion
[forums] => 0
)
)
(
[0] => Array
(
[catID] => 2
[catName] => News and Announcements
[catDescription] => News and Announcements
[forums] => 1
[forum] => Array
(
[forumID] => 1
[catID] => 2
[forumName] => Policies and Procedures
[forumDescription] => All policies relating to hosting provided, and abuse/support procedures are housed within
[topics] => 0
[posts] => 0
[lastPoster] =>
)
)
[1] => Array
(
[catID] => 3
[catName] => Support Center
[catDescription] => Support Center
[forums] => 0
)
[2] => Array
(
[catID] => 4
[catName] => On-Topic Discussion
[catDescription] => On-Topic Discussion
[forums] => 0
)
)
- Array
- (
- [0] => Array
- (
- [catID] => 2
- [catName] => News and Announcements
- [catDescription] => News and Announcements
- [forums] => 1
- [forum] => Array
- (
- [forumID] => 1
- [catID] => 2
- [forumName] => Policies and Procedures
- [forumDescription] => All policies relating to hosting provided, and abuse/support procedures are housed within
- [topics] => 0
- [posts] => 0
- [lastPoster] =>
- )
- )
- [1] => Array
- (
- [catID] => 3
- [catName] => Support Center
- [catDescription] => Support Center
- [forums] => 0
- )
- [2] => Array
- (
- [catID] => 4
- [catName] => On-Topic Discussion
- [catDescription] => On-Topic Discussion
- [forums] => 0
- )
- )
[EDIT] Bueno, me las arreglé para solucionar el problema...appearantly si no hay resultados para tomar a continuación, hay obviamente nada que recorrer {} SMILIES_PATH / icon_lol.gif "alt =": lol: "title =" Laughing ">
PHP Código: [ Select ]
<?php
/*
* forum.php
*
* Initiates the functions needed for the forum.
*/
class forum {
function forum()
{
global $db, $tpl;
// Making sure that the SQL doesn't cache results here...
$db->set_opts(array('cache_results' => false));
// Checking if there are any categories available
$sql = $db->build_key_query(array('SELECT' => '*',
'FROM' => FORUM_CAT));
if($db->num_rows($sql) == 0)
{
$tpl->error = true;
$tpl->errorMsg = "There are no categories available yet.";
}
else
{
// Initiating the forums array
$tpl->forums = array();
// The SQL to retrieve the categories from the database
$cat_sql = $db->build_key_query(array('SELECT' => '*',
'FROM' => FORUM_CAT));
// Setting the required loop variables
$inc = 0;
// The loops to get the categories and forums
foreach($db->fetch_rowset($cat_sql) as $ckey => $cvalue)
{
// The category information
$tpl->cats[$ckey] = $cvalue;
// The SQL to retrieve the forums for the categories from the database
$forums_sql = $db->build_key_query(array('SELECT' => '*',
'FROM' => FORUM_FORUMS,
'WHERE' => 'catID = ' . $cvalue['catID']));
// Checking if the following forum has any results
if($tpl->cats[$ckey]['forums'] > 0)
{
// Looping through the forums and retrieving them
foreach($db->fetch_rowset($forums_sql) as $fkey => $fvalue)
{
// Setting the forums array
$tpl->cats[$inc]['forum'][$fkey] = $fvalue;
}
}
// Increasing the loop increment variable
++$inc;
}
}
}
}
/*
* forum.php
*
* Initiates the functions needed for the forum.
*/
class forum {
function forum()
{
global $db, $tpl;
// Making sure that the SQL doesn't cache results here...
$db->set_opts(array('cache_results' => false));
// Checking if there are any categories available
$sql = $db->build_key_query(array('SELECT' => '*',
'FROM' => FORUM_CAT));
if($db->num_rows($sql) == 0)
{
$tpl->error = true;
$tpl->errorMsg = "There are no categories available yet.";
}
else
{
// Initiating the forums array
$tpl->forums = array();
// The SQL to retrieve the categories from the database
$cat_sql = $db->build_key_query(array('SELECT' => '*',
'FROM' => FORUM_CAT));
// Setting the required loop variables
$inc = 0;
// The loops to get the categories and forums
foreach($db->fetch_rowset($cat_sql) as $ckey => $cvalue)
{
// The category information
$tpl->cats[$ckey] = $cvalue;
// The SQL to retrieve the forums for the categories from the database
$forums_sql = $db->build_key_query(array('SELECT' => '*',
'FROM' => FORUM_FORUMS,
'WHERE' => 'catID = ' . $cvalue['catID']));
// Checking if the following forum has any results
if($tpl->cats[$ckey]['forums'] > 0)
{
// Looping through the forums and retrieving them
foreach($db->fetch_rowset($forums_sql) as $fkey => $fvalue)
{
// Setting the forums array
$tpl->cats[$inc]['forum'][$fkey] = $fvalue;
}
}
// Increasing the loop increment variable
++$inc;
}
}
}
}
- <?php
- /*
- * forum.php
- *
- * Initiates the functions needed for the forum.
- */
- class forum {
- function forum()
- {
- global $db, $tpl;
- // Making sure that the SQL doesn't cache results here...
- $db->set_opts(array('cache_results' => false));
- // Checking if there are any categories available
- $sql = $db->build_key_query(array('SELECT' => '*',
- 'FROM' => FORUM_CAT));
- if($db->num_rows($sql) == 0)
- {
- $tpl->error = true;
- $tpl->errorMsg = "There are no categories available yet.";
- }
- else
- {
- // Initiating the forums array
- $tpl->forums = array();
- // The SQL to retrieve the categories from the database
- $cat_sql = $db->build_key_query(array('SELECT' => '*',
- 'FROM' => FORUM_CAT));
- // Setting the required loop variables
- $inc = 0;
- // The loops to get the categories and forums
- foreach($db->fetch_rowset($cat_sql) as $ckey => $cvalue)
- {
- // The category information
- $tpl->cats[$ckey] = $cvalue;
- // The SQL to retrieve the forums for the categories from the database
- $forums_sql = $db->build_key_query(array('SELECT' => '*',
- 'FROM' => FORUM_FORUMS,
- 'WHERE' => 'catID = ' . $cvalue['catID']));
- // Checking if the following forum has any results
- if($tpl->cats[$ckey]['forums'] > 0)
- {
- // Looping through the forums and retrieving them
- foreach($db->fetch_rowset($forums_sql) as $fkey => $fvalue)
- {
- // Setting the forums array
- $tpl->cats[$inc]['forum'][$fkey] = $fvalue;
- }
- }
- // Increasing the loop increment variable
- ++$inc;
- }
- }
- }
- }
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
- Bigwebmaster
- Site Admin


- Registrado: Dic 20, 2002
- Mensajes: 8926
- Loc: Seattle, WA & Phoenix, AZ
- Status: Online
buen partido, antes de que yo veía en su resolución que buscaba más a errores sintácticos, pero parece que terminó siendo un error lógico.
Ozzu Hosting - Want your website on a fast server like Ozzu?
- Rabid Dog
- Web Master


- Registrado: May 21, 2004
- Mensajes: 3229
- Loc: South Africa
- Status: Offline
Quote:
Advertencia: Argumento no válido suministrados para foreach () en C: \ wamp \ www \ CMS \ includes \ forum.php en la línea 51
bastante auto explanitory
Watch me grow
Página 1 de 1
Para responder a este tema que necesita para ingresar o registrarse. Es gratis.
Publicar Información
- Total de mensajes en este tema: 6 mensajes
- Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 124 invitados
- No puede abrir nuevos temas en este Foro
- No puede responder a temas en este Foro
- No puede editar sus mensajes en este Foro
- No puede borrar sus mensajes en este Foro
- No puede enviar adjuntos en este Foro
