Programmation d'un forum
- Bogey
- Bogey


- Inscription: Juil 14, 2005
- Messages: 8211
- Loc: USA
- Status: Offline
Pour le moment, j'ai pris place un projet de programme d'un forum comme une expérience d'apprentissage dans les deux, la programmation PHP et le dépannage (depuis theres lié à des problèmes que je courrais partout)...et je suis tombé sur celui que j'ai besoin d'aide.
Im ce n'est pas vraiment un problème dans la mesure où la façon de créer les catégories et les forums par liste de catégories. La seule façon je peux voir qui est fait à l'aide de 2 boucles...un dans l'autre. La première boucle serait pour les catégories et la seconde à l'intérieur de celui-ci, serait pour les forums à l'intérieur des catégories. Y at-il une autre façon, mieux de le faire, ou est-ce la meilleure façon?
Im ce n'est pas vraiment un problème dans la mesure où la façon de créer les catégories et les forums par liste de catégories. La seule façon je peux voir qui est fait à l'aide de 2 boucles...un dans l'autre. La première boucle serait pour les catégories et la seconde à l'intérieur de celui-ci, serait pour les forums à l'intérieur des catégories. Y at-il une autre façon, mieux de le faire, ou est-ce la meilleure façon?
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
- Anonymous
- Bot


- Inscription: 25 Feb 2008
- Messages: ?
- Loc: Ozzuland
- Status: Online
Avril 1st, 2011, 10:25 am
- SpooF
- ٩๏̯͡๏۶


- Inscription: Mai 22, 2004
- Messages: 3415
- Loc: Richland, WA
- Status: Offline
Vous voulez dire pour quand vous les afficher?
Par exemple sur cette page: forum /
Je ne vois aucune raison de ne pas utiliser une boucle imbriquée.
Par exemple sur cette page: forum /
Je ne vois aucune raison de ne pas utiliser une boucle imbriquée.
#define NULL (::rand() % 2)
- Bogey
- Bogey


- Inscription: Juil 14, 2005
- Messages: 8211
- Loc: USA
- Status: Offline
- Bogey
- Bogey


- Inscription: Juil 14, 2005
- Messages: 8211
- Loc: USA
- Status: Offline
J'ai un autre problème ici...celui-ci m'a déconcerté bien.
J'ai obtenu le travail SQL, le tableau est généré juste comme je le veux, mais Im obtenir des mises en garde...Je ne sais pas ce qu'ils font.
Les avertissements je reçois (Eh bien, techniquement son «Avertissement» mais il jette deux fois le même...)
Et le PHP est...
J'ai aussi un sentiment que je pourrais faire cette fonction un peu plus court mais toujours faire la même chose, mais je ne parviens pas à comprendre comment...
Cette fonction me donne le tableau suivant
[EDIT] Bon, j'ai réussi à résoudre le problème...appearantly s'il n'y a pas de résultats à prendre alors il n'y a évidemment rien à parcourir {SMILIES_PATH} / icon_lol.gif "alt =": lol: "title =" Laughing ">
J'ai obtenu le travail SQL, le tableau est généré juste comme je le veux, mais Im obtenir des mises en garde...Je ne sais pas ce qu'ils font.
Les avertissements je reçois (Eh bien, techniquement son «Avertissement» mais il jette deux fois le même...)
Quote:
Attention: Invalid argument fourni pour foreach () in C: \ wamp \ www \ CMS \ includes \ forum. php à la ligne 51
Attention: Invalid argument fourni pour foreach () in C: \ wamp \ www \ CMS \ includes \ forum. php à la ligne 51
Attention: Invalid argument fourni pour foreach () in C: \ wamp \ www \ CMS \ includes \ forum. php à la ligne 51
Et le PHP est...
PHP Code: [ 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;
- }
- }
- }
- }
J'ai aussi un sentiment que je pourrais faire cette fonction un peu plus court mais toujours faire la même chose, mais je ne parviens pas à comprendre comment...
Cette fonction me donne le tableau suivant
Code: [ 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] Bon, j'ai réussi à résoudre le problème...appearantly s'il n'y a pas de résultats à prendre alors il n'y a évidemment rien à parcourir {SMILIES_PATH} / icon_lol.gif "alt =": lol: "title =" Laughing ">
PHP Code: [ 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


- Inscription: Déc 20, 2002
- Messages: 8926
- Loc: Seattle, WA & Phoenix, AZ
- Status: Offline
Bonne prise, avant que je regardé votre résolution que je cherchais plus à des erreurs de syntaxe, mais il ressemble a fini par être une erreur de logique.
Ozzu Hosting - Want your website on a fast server like Ozzu?
- Rabid Dog
- Web Master


- Inscription: Mai 21, 2004
- Messages: 3229
- Loc: South Africa
- Status: Offline
Quote:
Attention: Invalid argument fourni pour foreach () in C: \ wamp \ www \ CMS \ includes \ forum.php à la ligne 51
jolie auto explanitory
Watch me grow
Page 1 sur 1
Pour répondre à ce sujet, vous devez vous connecter ou vous enregistrer. Il est gratuit.
Afficher de l'information
- Total des messages de ce sujet: 6 messages
- Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 117 invités
- Vous ne pouvez pas poster de nouveaux sujets
- Vous ne pouvez pas répondre aux sujets
- Vous ne pouvez pas éditer vos messages
- Vous ne pouvez pas supprimer vos messages
- Vous ne pouvez pas joindre des fichiers
