Fork me on GitHub






un seul résultat avec foreach
Aspirant
Inscrit: 11/11/2010 14:56
Messages: 78
Je reviens vers vous pour une petite question.
dans une boucle foreach j'ai un seul resultat qui s'affiche j'ai cherché partout sur internet je trouve pas une reponse pour le problème.


$sql10 'SELECT * FROM ' $xoopsDB -> prefix'test_articles' ) . 'ORDER BY RAND() ';
$result10 $xoopsDB -> query$sql1010);
//$articles_arr10 = $xoopsDB -> fetchArray( $result10 );
$i 0;
while(
$articles_arr10 $xoopsDB -> fetchArray$result10 )){ 

$tags_exploded explode(" "$articles_arr10['title']);

foreach(
$tags_exploded as $v => $value) {
if (
strlen($value) > '5') {
$tags_exploded1 $value;
//echo $i;
//echo $value;
$articles1 "<a href='search.php?query=" $tags_exploded1 "&mid=8&action=showall&andor=AND'>" $tags_exploded1 "</a></br>";
$articles['test'] = "<a href='search.php?query=" $tags_exploded1 "&mid=8&action=showall&andor=AND'>" $tags_exploded1 "</a></br>";//affiche seulement un seul resultat
//echo $articles1;//affiche tous ce que je veux
//$xoopsTpl -> assign( 'articles11', $articles1 );//ça donne rien aussi un seul resultat
} } $i++; }


si je résume le but est de faire un système de tag en fonction des titres de mes articles avec
echo $articles1;//affiche tous ce que je veux
maintenant je veut faire un smarty de type <{$articles.test}> pour l'utiliser dans mon template en utilisant bien sûr
$articles['test'] = "<a href='search.php?query=" . $tags_exploded1 . "&mid=8&action=showall&andor=AND'>" . $tags_exploded1 . "</a></br>";//affiche seulement une seule resultat

j'ai un seul résultat qui s'affiche. c'est un peu bizarre pour moi je comprend pas pourquoi.

Posté le : 02/09/2012 16:58
Partager Twitter Partagez cette article sur GG+
Re: un seul résultat avec foreach
Admin Frxoops
Inscrit: 04/03/2011 09:10
De Lot
Messages: 2837
Dans ton code tu écrases au fur et a mesure la seul ligne que tu créer dans ton tableau.

J'aurai fais un code du genre

<?php
$list_tag 
= array();
$sql10 'SELECT * FROM ' $xoopsDB -> prefix'test_articles' ) . 'ORDER BY RAND() ';
$result10 $xoopsDB -> query$sql1010);
//$articles_arr10 = $xoopsDB -> fetchArray( $result10 );
$i 0;
while(
$articles_arr10 $xoopsDB -> fetchArray$result10 )){ 
    
$tags_exploded[$i] = explode(" "$articles_arr10['title']);
    
$i++;
}
foreach(
$tags_exploded as $value) {
    if (
strlen($value) > '5') {
        
$list_tag[] = '<a href="search.php?query=' $tags_exploded1 '&mid=8&action=showall&andor=AND">' $tags_exploded1 '</a></br>';
    }
}
$xoopsTpl->assign('article11',$list_tag);
?>


et dans le template, à l'endroit où les tags doivent être afficher

<{foreach item=tag from=$article11}> 
<{
$tag}>
<{/foreach}>


j'ai fais sa vite fait mais sa devrai fonctionner

Posté le : 02/09/2012 19:49
Partager Twitter Partagez cette article sur GG+
Re: un seul résultat avec foreach
Aspirant
Inscrit: 11/11/2010 14:56
Messages: 78
Merci Montuy 337513 pour ta reponse je vois ce que tu veux dire t'as raison.

j'ai changé avec ton code je tombe sur des liens avec Array .
search.php?query=Array&mid=8&action=showall&andor=AND
search.php?query=Array&mid=8&action=showall&andor=AND
search.php?query=Array&mid=8&action=showall&andor=AND
search.php?query=Array&mid=8&action=showall&andor=AND
search.php?query=Array&mid=8&action=showall&andor=AND
search.php?query=Array&mid=8&action=showall&andor=AND
search.php?query=Array&mid=8&action=showall&andor=AND

je pense qu'il y a un probleme avec explode, j'ai changé la ligne
$tags_exploded[$i] = explode(" "$articles_arr10['title']);


avec
$tags_exploded[$i] = $articles_arr10['title'];

j'ai comme resultat.


search.php?query=titre de mon article&mid=8&action=showall&andor=AND
search.php?query=titre de mon 3 eme article&mid=8&action=showall&andor=AND
search.php?query=titre de mon 999 article&mid=8&action=showall&andor=AND
search.php?query=titre par hazard&mid=8&action=showall&andor=AND


c'est pas trop pratique j'aimerai avoir comme sortie

search.php?query=titre&mid=8&action=showall&andor=AND
search.php?query=article&mid=8&action=showall&andor=AND
search.php?query=999&mid=8&action=showall&andor=AND
search.php?query=hazard&mid=8&action=showall&andor=AND



si tu peux vérifier encore une fois. merci.


Posté le : 04/09/2012 01:20
Partager Twitter Partagez cette article sur GG+
Re: un seul résultat avec foreach
Admin Frxoops
Inscrit: 04/03/2011 09:10
De Lot
Messages: 2837
j'ai oublié un foreach en route
<?php
$list_tag 
= array();
$sql10 'SELECT * FROM ' $xoopsDB -> prefix'test_articles' ) . 'ORDER BY RAND() ';
$result10 $xoopsDB -> query$sql1010);
//$articles_arr10 = $xoopsDB -> fetchArray( $result10 );
$i 0;
while(
$articles_arr10 $xoopsDB -> fetchArray$result10 )){ 
    
$tags_exploded[$i] = explode(" "$articles_arr10['title']);
    
$i++;
}
foreach(
$tags_exploded as $v) {
  foreach (
$v as $value){
    if (
strlen($value) > '5') {
        
$list_tag[] = '<a href="search.php?query=' $tags_exploded1 '&mid=8&action=showall&andor=AND">' $tags_exploded1 '</a></br>';
    }
  }
}
$xoopsTpl->assign('article11',$list_tag);
?>

Posté le : 04/09/2012 11:57
Partager Twitter Partagez cette article sur GG+
Re: un seul résultat avec foreach
Aspirant
Inscrit: 11/11/2010 14:56
Messages: 78
perfect plus un mot bravo.

ce bout de code nous évite d'installer le module tag avec des plugin et tables à créer dans la base donnée en fonction du module utilisé. pourquoi faire compliqué si on peut faire simple. je commence a adorer le php, il reste maintenant à changer les <title> du ficher search.php en fonction du tag pour l'indexation dans google. merci encore une fois à Montuy.
ps: si tu as une idée pour le <title> n’hésite surtout pas.

Posté le : 04/09/2012 23:19
Partager Twitter Partagez cette article sur GG+
Re: un seul résultat avec foreach
Aspirant
Inscrit: 11/11/2010 14:56
Messages: 78
Bonjour,

je viens de trouver la solution pour les <title>. il faut modifier le fichier search.php juste après

00209 case "showall"
00210 case 'showallbyuser':


il faut ajouter

$xoopsOption['xoops_pagetitle'] = implode(' '$queries) . ': ' $start ': ' _SR_SEARCHRESULTS;
.

Posté le : 09/09/2012 20:13
Partager Twitter Partagez cette article sur GG+

 Haut   Précédent   Suivant



Vous pouvez voir les sujets.
Vous ne pouvez pas débuter de nouveaux sujets.
Vous ne pouvez pas répondre aux contributions.
Vous ne pouvez pas éditer vos contributions.
Vous ne pouvez pas effacez vos contributions.
Vous ne pouvez pas ajouter de nouveaux sondages.
Vous ne pouvez pas voter en sondage.
Vous ne pouvez pas attacher des fichiers à vos contributions.
Vous ne pouvez pas poster sans approbation.

Propulsé avec XOOPS | Graphisme adapté par Tatane, Grosdunord, Montuy337513

104 Personne(s) en ligne (84 Personne(s) connectée(s) sur Forum) | Utilisateur(s): 0 | Invité(s): 104 | Plus ...