Programación de un foro

  • Bogey
  • Bogey
  • Genius
  • Avatar de Usuario
  • Registrado: Jul 14, 2005
  • Mensajes: 8211
  • Loc: USA
  • Status: Offline

Nota Abril 1st, 2011, 10:25 am

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?
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Abril 1st, 2011, 10:25 am

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • Avatar de Usuario
  • Registrado: May 22, 2004
  • Mensajes: 3415
  • Loc: Richland, WA
  • Status: Offline

Nota Abril 1st, 2011, 11:42 am

¿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.
#define NULL (::rand() % 2)
  • Bogey
  • Bogey
  • Genius
  • Avatar de Usuario
  • Registrado: Jul 14, 2005
  • Mensajes: 8211
  • Loc: USA
  • Status: Offline

Nota Abril 1st, 2011, 12:15 pm

Sí, así. Yo no sabía si había una mejor manera ya que hay. Gracias.
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • Bogey
  • Bogey
  • Genius
  • Avatar de Usuario
  • Registrado: Jul 14, 2005
  • Mensajes: 8211
  • Loc: USA
  • Status: Offline

Nota Abril 1st, 2011, 10:20 pm

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...)
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

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;
            }
        }
    }
}
  1. <?php
  2.  
  3. /*
  4.  * forum.php
  5.  *
  6.  * Initiates the functions needed for the forum.
  7.  */
  8.  
  9. class forum {
  10.  
  11.     function forum()
  12.     {
  13.         global $db, $tpl;
  14.        
  15.         // Making sure that the SQL doesn't cache results here...
  16.         $db->set_opts(array('cache_results' => false));
  17.        
  18.         // Checking if there are any categories available
  19.         $sql = $db->build_key_query(array('SELECT'    => '*',
  20.                                           'FROM'      => FORUM_CAT));
  21.  
  22.         if($db->num_rows($sql) == 0)
  23.         {
  24.             $tpl->error = true;
  25.             $tpl->errorMsg = "There are no categories available yet.";
  26.         }
  27.         else
  28.         {
  29.             // Initiating the forums array
  30.             $tpl->forums = array();
  31.        
  32.             // The SQL to retrieve the categories from the database
  33.             $cat_sql = $db->build_key_query(array('SELECT'    => '*',
  34.                                                   'FROM'      => FORUM_CAT));
  35.            
  36.             // Setting the required loop variables
  37.             $inc = 0;
  38.            
  39.             // The loops to get the categories and forums
  40.             foreach($db->fetch_rowset($cat_sql) as $ckey => $cvalue)
  41.             {
  42.                 // The category information
  43.                 $tpl->cats[$ckey] = $cvalue;
  44.                
  45.                 // The SQL to retrieve the forums for the categories from the database
  46.                 $forums_sql = $db->build_key_query(array('SELECT'    => '*',
  47.                                                          'FROM'      => FORUM_FORUMS,
  48.                                                          'WHERE'     => 'catID = ' . $cvalue['catID']));
  49.            
  50.                 // Looping through the forums and retrieving them
  51.                 foreach($db->fetch_rowset($forums_sql) as $fkey => $fvalue)
  52.                 {
  53.                     // Setting the forums array
  54.                     $tpl->cats[$inc]['forum'][$fkey] = $fvalue;
  55.                 }
  56.                
  57.                 // Increasing the loop increment variable
  58.                 ++$inc;
  59.             }
  60.         }
  61.     }
  62. }

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
    )

)
  1. Array
  2. (
  3.   [0] => Array
  4.     (
  5.       [catID] => 2
  6.       [catName] => News and Announcements
  7.       [catDescription] => News and Announcements
  8.       [forums] => 1
  9.       [forum] => Array
  10.         (
  11.           [forumID] => 1
  12.           [catID] => 2
  13.           [forumName] => Policies and Procedures
  14.           [forumDescription] => All policies relating to hosting provided, and abuse/support procedures are housed within
  15.           [topics] => 0
  16.           [posts] => 0
  17.           [lastPoster] =>
  18.         )
  19.     )
  20.   [1] => Array
  21.     (
  22.       [catID] => 3
  23.       [catName] => Support Center
  24.       [catDescription] => Support Center
  25.       [forums] => 0
  26.     )
  27.   [2] => Array
  28.     (
  29.       [catID] => 4
  30.       [catName] => On-Topic Discussion
  31.       [catDescription] => On-Topic Discussion
  32.       [forums] => 0
  33.     )
  34. )


[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;
            }
        }
    }
}
  1. <?php
  2.  
  3. /*
  4.  * forum.php
  5.  *
  6.  * Initiates the functions needed for the forum.
  7.  */
  8.  
  9. class forum {
  10.  
  11.     function forum()
  12.     {
  13.         global $db, $tpl;
  14.        
  15.         // Making sure that the SQL doesn't cache results here...
  16.         $db->set_opts(array('cache_results' => false));
  17.        
  18.         // Checking if there are any categories available
  19.         $sql = $db->build_key_query(array('SELECT'    => '*',
  20.                                           'FROM'      => FORUM_CAT));
  21.  
  22.         if($db->num_rows($sql) == 0)
  23.         {
  24.             $tpl->error = true;
  25.             $tpl->errorMsg = "There are no categories available yet.";
  26.         }
  27.         else
  28.         {
  29.             // Initiating the forums array
  30.             $tpl->forums = array();
  31.        
  32.             // The SQL to retrieve the categories from the database
  33.             $cat_sql = $db->build_key_query(array('SELECT'    => '*',
  34.                                                   'FROM'      => FORUM_CAT));
  35.            
  36.             // Setting the required loop variables
  37.             $inc = 0;
  38.            
  39.             // The loops to get the categories and forums
  40.             foreach($db->fetch_rowset($cat_sql) as $ckey => $cvalue)
  41.             {
  42.                 // The category information
  43.                 $tpl->cats[$ckey] = $cvalue;
  44.                
  45.                 // The SQL to retrieve the forums for the categories from the database
  46.                 $forums_sql = $db->build_key_query(array('SELECT'    => '*',
  47.                                                          'FROM'      => FORUM_FORUMS,
  48.                                                          'WHERE'     => 'catID = ' . $cvalue['catID']));
  49.            
  50.                 // Checking if the following forum has any results
  51.                 if($tpl->cats[$ckey]['forums'] > 0)
  52.                 {
  53.                     // Looping through the forums and retrieving them
  54.                     foreach($db->fetch_rowset($forums_sql) as $fkey => $fvalue)
  55.                     {
  56.                         // Setting the forums array
  57.                         $tpl->cats[$inc]['forum'][$fkey] = $fvalue;
  58.                     }
  59.                 }
  60.                
  61.                 // Increasing the loop increment variable
  62.                 ++$inc;
  63.             }
  64.         }
  65.     }
  66. }
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • Avatar de Usuario
  • Registrado: Dic 20, 2002
  • Mensajes: 8926
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Online

Nota Abril 2nd, 2011, 3:19 pm

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
  • Web Master
  • Avatar de Usuario
  • Registrado: May 21, 2004
  • Mensajes: 3229
  • Loc: South Africa
  • Status: Offline

Nota Abril 24th, 2011, 12:46 pm

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 ;) Estoy bastante seguro de los mapas foreach a una función que requiere un valor con el fin de proceso. Esto habría dado lugar a una excepción argumento no válido en Java y C #. Tenga en cuenta que es una advertencia y no un error. Por lo tanto, no es fatal sólo lo que le permite conocer los argumentos que pasó a foreach no son válidos.
Watch me grow

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
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC