[php] boucle je pense

opanis -  
fabrice11901 Messages postés 787 Statut Membre -
Bonjour,

Je me met actuellement au php et j'ai réussi a réliaser un script qui lorsque une date issue de la base de donnée correspoand a la date du jour les information liée a cette date s'affiche, mais lorsque aucune date ne correspond a la date du jour il s'affiche une erreur, je pense que je devrais réaliser des boucles mais je sais pas comment ça marche quelqu'un pourrais m'expliqué

$date = date("Y/m/d");
$query2 = "SELECT id,manifestation,organisateur,lieu,heure
FROM agenda where mdate='$date'";

$result2 = mysql_query($query2);

/* ici il manquait le $result, ben oui c logique
on fait un tableau à partir du resultat de la requête*/
while( $rows = mysql_fetch_array($result2)){
$tab['id'][] = $rows[0];
$tab['manifestation'][] = $rows[1];
$tab['organisateur'][] = $rows[2];
$tab['lieu'][] = $rows[3];
$tab['heure'][] = $rows[4];
}

<?php

foreach($tab['id'] as $key => $val){
if( $tab['manifestation'][$key] !== '' ){
echo" <ul>";
echo" <li>";

echo "<b>".$tab['manifestation'][$key].",</b>".$tab['lieu'][$key].",".$tab['heure'][$key]."";}
echo" </ul>";
echo" ";
}
?>

Merci de vos réponse

4 réponses

  1. PhP Messages postés 1774 Statut Membre 606
     
    Bonsoir,

    Ben c'est normal ! Tu dois tester si ta requête retourne au moins une ligne sinon $tab n'est pas défini.

    Ca donne

    <?php 
    $date = date("Y/m/d"); 
    $query2 = "SELECT id,manifestation,organisateur,lieu,heure 
    FROM agenda where mdate='$date'"; 
    
    $result2 = mysql_query($query2); 
    
    if (mysql_num_rows($result2) > 0) 
    { 
    
    	/* ici il manquait le $result, ben oui c logique 
    	on fait un tableau à partir du resultat de la requête*/ 
    	while( $rows = mysql_fetch_array($result2)){ 
    		$tab['id'][] = $rows[0]; 
    		$tab['manifestation'][] = $rows[1]; 
    		$tab['organisateur'][] = $rows[2]; 
    		$tab['lieu'][] = $rows[3]; 
    		$tab['heure'][] = $rows[4]; 
    	} 
    
    
    	
    	foreach($tab['id'] as $key => $val){ 
    		if( $tab['manifestation'][$key] !== '' ){ 
    			echo" <ul>"; 
    			echo" <li>"; 
    	
    			echo "<b>".$tab['manifestation'][$key].",</b>".$tab['lieu'][$key].",".$tab['heure'][$key]."";} 
    			echo" </ul>"; 
    			echo" "; 
    		}
    	}
    } 
    ?> 
    --
    PhP  
    Il y a 10 types de personnes dans le monde : ceux qui comprennent le binaire et les autres ...
    0
  2. fabrice11901 Messages postés 787 Statut Membre 64
     
    salut
    Oui c'était logique, si tu vérifis pas ça risque pas de marcher !
    0
  3. opanis Messages postés 6 Statut Membre
     
    cela marche bien quand je met sur une page a part mais kan je met le script dans la page d'accueil ça marche plus
    <html>

    <head><link rel="stylesheet" href="../../../Bureau/style.css" type="text/css">

    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>Nouvelle page 3</title>
    <link rel="STYLESHEET" type="text/css" href="../../../Bureau/stylesheet.css">
    </head>
    <body background="../../../Bureau/images/fond2.jpg" bgproperties="fixed">
    <p>

    <?php
    require( "config.inc.php" );
    $ok = connex_base( $hote, $login_base, $pwd, $base );
    if($ok){
    $query1 = "SELECT idm,mdate FROM jour ";

    $result1 = mysql_query($query1);

    /* ici il manquait le $result, ben oui c logique
    on fait un tableau à partir du resultat de la requête*/
    while( $rows = mysql_fetch_array($result1)){
    $tab['idm'][] = $rows[0];
    $tab['mdate'][] = $rows[1];

    }
    $date = date("Y/m/d");
    $query2 = "SELECT id,manifestation,organisateur,lieu,heure
    FROM agenda where mdate='$date'";

    $result2 = mysql_query($query2);

    /* ici il manquait le $result, ben oui c logique
    on fait un tableau à partir du resultat de la requête*/
    while( $rows = mysql_fetch_array($result2)){
    $tab['id'][] = $rows[0];
    $tab['manifestation'][] = $rows[1];
    $tab['organisateur'][] = $rows[2];
    $tab['lieu'][] = $rows[3];
    $tab['heure'][] = $rows[4];
    }

    $query3 = " SELECT lien FROM tambour where idtambour<=(idtambour)";
    $result3 = mysql_query($query3);

    while( $rows = mysql_fetch_array($result3)){
    $tab['lien'] = $rows[0];

    }
    ?>

    <table width="965" border="0" cellpadding="2">
    <tr>
    <td valign="top" width="712">

    <p align="left">  <font color="#3366FF">
    <?php

    foreach($tab['mdate'] as $key => $val){
    echo "<font color='#3366FF'><marquee align='middle' height='19' scrolldelay='120' width='450'><b> Bienvenue sur le site de- Dernière mise à jour le
    ".$tab['mdate'][$key]."</b></marquee> </font>";}
    ?>
    </font>
    </p>

    <font color="#3366FF">
    <p><img src="../../../Bureau/images/aujour.gif" width="175" height="36"></p>
    <table width="92%" border="0">
    <tr>
    <td width="11%" align="center" valign="top"><img src="http://perso0.free.fr/cgi-bin/meteo.pl?dep=77" border="0" align="middle"></td>
    <td width="89%">
    <?php
    foreach($tab['id'] as $key => $val){
    if( $tab['manifestation'][$key] !== '' ){
    echo" <ul>";
    echo" <li>";

    echo "<b>".$tab['manifestation'][$key].",</b>".$tab['lieu'][$key].",".$tab['heure'][$key]."";}
    echo" </ul>";
    echo" ";
    }
    ?>
    </td>
    </tr>
    </table>
    <hr align="center" width="50%">
    </font>
    </td>
    <td valign="top" width="251">
    <div align="left">
    <table border="0" width="99%" height="628">
    <tr>
    <td valign="middle" width="164">
    <div align="right">
    <table border="0" width="100%" height="100" cellspacing="0">
    <tr>
    <td width="100%">
    <p align="center"> <IMG
    src="../../../Bureau/images/Image8.gif" align="middle"></p>
    </td>
    </tr>
    <tr>
    <td width="100%" valign="middle" align="center"><?php include "calendrier.php"; ?>

    <?php

    $query = "SELECT dayofmonth(mdate) as mdate
    FROM agenda";

    $result = mysql_query($query);

    while ($row = mysql_fetch_array($result)) {

    $dateArray[] = $row['mdate'];

    }
    $query = "select * from moisactuel";
    $result = mysql_query($query);

    /* ici il manquait le $result, ben oui c logique
    on fait un tableau à partir du resultat de la requête*/
    while( $rows = mysql_fetch_array($result)){
    $tab['idmois'][] = $rows[0];
    $tab['mois'][] = $rows[2];
    }
    $mois = $tab['mois'][count($tab['mois'])-1];
    $an="06";

    echo build_calendar($mois,$an,$dateArray);

    $date = date("Y-M-d");

    $blogQuery = "SELECT title, content
    FROM agenda WHERE mDate = '$date'";

    $blogResult = mysql_query($blogQuery);

    ?>

    </td>
    </tr>
    <tr>
    <td width="100%">
    <p align="center">  </p>
    </td>
    </tr>
    <tr>
    <td width="100%" valign="middle" align="center">
    <table border="0" width="10%">
    <tr>
    <td width="100%"> </td>
    </tr>
    <tr>
    <td width="100%" valign="middle">
    </td>
    </tr>
    <tr>
    <td width="100%">  </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </div>
    </td>
    </tr>
    <tr>
    <td width="164" valign="middle">
    <table width="159" height="201" border="0" cellspacing="0">
    <tr>
    <td width="148" height="16"> <div align="center"><IMG
    src="../../../Bureau/images/tam.gif" align="middle"></div></td>
    </tr>
    <tr>
    <td width="148" height="24">
    <div align="center"><font color="#0066FF" size="2">au format pdf</font></div></td>
    </tr>
    <tr>

    </td>
    </tr>
    <tr>
    <td width="148" height="14"> </td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td width="164" height="21" valign="middle">
    <table border="0" width="95%">
    <tr>
    <td width="100%"> <IMG
    src="../../../Bureau/images/foru.gif" align="middle"></td>
    </tr>
    <tr>
    <td width="100%" align="center"> <div align="center"><a href="forum.htm"><b><font color="#3399FF">
    </font></b></a><a href="forum.htm"><b><font color="#3399FF"><img border="0" src="../../../Bureau/images/foum11.gif" align="middle"></font></b></a></div></td>
    </tr>
    <tr>
    <td width="100%">  </td>
    </tr>
    </table>
    </td>
    </tr>

    </table>
    <div align="center">
    </div>
    </DIV>

    </td>

    </tr>
    </table>

    </body>

    </html>
    0
  4. fabrice11901 Messages postés 787 Statut Membre 64
     
    oui mais quel est le message d'erreur donnée à l'écran?
    0