Visualizzazione dei risultati da 1 a 8 su 8

Discussione: cicli..

  1. #1

    cicli..

    come posso fare per dire qui di eseguire il "do" se trova qualcosa altrimenti deve scrivere "nessun evento presente" ?

    codice:
    <?php do { ?><h3><?php echo $row_eventi['d']; ?>/<?php echo $row_eventi['m']; ?>/<?php echo $row_eventi['y']; ?> - <?php echo $row_eventi['title']; ?>
              
    
              </h3>
            <?php  $body = stripslashes(str_replace("\n", "
    ", $row_eventi['text']));
    	   echo $body; ?>
    
    
            <?php } while ($row_eventi = mysql_fetch_assoc($eventi)); ?>

  2. #2
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,508
    Perché complicarti la vita con un do-while?
    In questi casi si fa così
    Codice PHP:
    $eventi mysql_query(.....);

    if(
    mysql_num_rows($eventi) < 1)
    {
        echo 
    "Non ci sono eventi";
    }
    else
    {
        while(
    $row_eventi mysql_fetch_assoc($eventi))
        {
            
    //il contenuto del tuo attuale do
        
    }


  3. #3
    avevo provato ma mi da' questo errore

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

    codice:
    
    <?php if(mysql_num_rows($eventi) < 1)
    {
        echo "Non ci sono eventi";
    }
    else
    {
        while($row_eventi = mysql_fetch_assoc($eventi))
        {  ?><h3><?php echo $row_eventi['d']; ?>/<?php echo $row_eventi['m']; ?>/<?php echo $row_eventi['y']; ?> - <?php echo $row_eventi['title']; ?>
              
    
              </h3>
            <?php  $body = stripslashes(str_replace("\n", "
    ", $row_eventi['text']));
    	   echo $body; ?>
    
    
            <?php } } ?></p>

  4. #4
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,508
    Stando al testo, l'errore non è nel codice postato, ma nella query, c'è un qualche errore di sintassi, ma non so dirti quale dato che non l'hai postata.

  5. #5
    non ci possono essere errori perchè con il DO viene eseguito tutto regolarmente nel caso in cui contenga delle righe...

    codice:
    $colname_eventi = "-1";
    if (isset($_GET['cat'])) {
      $colname_eventi = $_GET['cat'];
    }
    mysql_select_db($database_server, $server);
    $query_eventi = sprintf("SELECT m, d, y, title, text, priv FROM cai_calendar_mssgs WHERE priv = %s", GetSQLValueString($colname_eventi, "text"));
    $eventi = mysql_query($query_eventi, $server) or die(mysql_error());
    $row_eventi = mysql_fetch_assoc($eventi);
    $totalRows_eventi = mysql_num_rows($eventi);
    
    $categoria = $row_eventi['priv'];
    
    mysql_select_db($database_server, $server);
    $query_cat = "SELECT * FROM cai_categorie WHERE idcategorie = $categoria";
    $cat = mysql_query($query_cat, $server) or die(mysql_error());
    $row_cat = mysql_fetch_assoc($cat);
    $totalRows_cat = mysql_num_rows($cat);

  6. #6
    Utente di HTML.it L'avatar di bstefano79
    Registrato dal
    Feb 2004
    Messaggi
    2,520
    prova a fare un'echo delle query

    Codice PHP:
    $colname_eventi "-1";
    if (isset(
    $_GET['cat'])) {
      
    $colname_eventi $_GET['cat'];
    }
    mysql_select_db($database_server$server);
    $query_eventi sprintf("SELECT m, d, y, title, text, priv FROM cai_calendar_mssgs WHERE priv = %s"GetSQLValueString($colname_eventi"text"));
    echo 
    "Query Eventi ".$query_eventi."
    "
    ;
    $eventi mysql_query($query_eventi$server) or die(mysql_error());
    $row_eventi mysql_fetch_assoc($eventi);
    $totalRows_eventi mysql_num_rows($eventi);

    $categoria $row_eventi['priv'];

    mysql_select_db($database_server$server);
    $query_cat "SELECT * FROM cai_categorie WHERE idcategorie = $categoria";
    echo 
    "Query Cat ".$query_cat."
    "
    ;
    $cat mysql_query($query_cat$server) or die(mysql_error());
    $row_cat mysql_fetch_assoc($cat);
    $totalRows_cat mysql_num_rows($cat); 
    e poi posta l'output

  7. #7
    Query Eventi SELECT m, d, y, title, text, priv FROM cai_calendar_mssgs WHERE priv = '2'
    Query Cat SELECT * FROM cai_categorie WHERE idcategorie =
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

  8. #8
    ovvio che se non trova una riga sopra non troverà mai il campo priv!

    come posso ovviare al problema?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.