Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11
  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2005
    Messaggi
    29

    [php-mysql] problemi con while

    Salve a tutti come da titolo ho dei problemi con while...

    Vi spiego la situazione, voglio estrarre dal 2 tabelle sul database i risultati per poi metterli in un output, ma adesso sorge il problema, nella visualizzazione mi viene scritta la stessa informazione per più volte -_-

    Vi passo il codice :
    Codice PHP:
        // Includo il Tpl delle news
        
    include(INCPATH."temp/news.tpl");
                
    // Records Query
                
    $count mysql_query("SELECT COUNT(id) FROM cute_news WHERE date < ".time());
                
    $res_count mysql_fetch_row($count);
                
    // Numero di Records
                
    $tot_records $res_count[0];
                
    // Records per Page
                
    $per_page 7;
                
    // Total Page
                
    $tot_pages ceil($tot_records $per_page);
                
    // Current Page
                
    $current_page = (!$_GET['page']) ? : (int)$_GET['page'];
                
    // LIMIT Param
                
    $primo = ($current_page 1) * $per_page;
                
    // WHILE Per visualizzare i Records
                
    $query_lim mysql_query("SELECT * FROM cute_news WHERE date < ".time()." LIMIT $primo$per_page");
                if (
    mysql_num_rows($query_lim) == 0) {
                } else {
                    while(
    $news mysql_fetch_array($query_lim)) {
                    
    $query_txt mysql_query("SELECT * FROM cute_story WHERE post_id ='".$news['id']."'");
                        while(
    $txt mysql_fetch_array($query_txt)) {
                            
    $news_body $news_body;
                            
    $news_body str_replace("{title}"$news['title'], $news_body);
                            
    $news_body str_replace("{author}"$news['author'], $news_body);
                            
    $news_body str_replace("{date}", (date('d-m-Y'$news['date'])), $news_body);
                            
    $news_body str_replace("{news}"$txt['short'], $news_body);
                if(
    $_SESSION[permission]) {     $news_body str_replace("{logged}"$txt['full'], $news_body); 
                } else {    
    $news_body str_replace("{logged}"''$news_body); }
                            
    $news_body str_replace("{comments}"$news['comments'], $news_body);
                            echo 
    $news_body;
                        }
                    }
                    
    $paginazione "<div align=\"right\">";
                    
    // Visualizzazione delle Pagine con gli OPTION
                    
    $paginazione "<select onChange=\"MM_jumpMenu('parent',this,0)\" name=\"menu\">\n";
                    for(
    $i 1$i <= $tot_pages$i++) {
                    if(
    $i == $current_page) {
                    
    $paginazione .= "<option value=\"?id=news&amp;page=$i\" selected=\"selected\">Pagina $i</option>\n";
                    } else {
                    
    $paginazione .= "<option value=\"?id=news&amp;page=$i\">Pagina $i</option>\n";
                    }}
                    
    $paginazione .= "</select>";
                    
    $paginazione .= "</div>"
    Spero che possiate aiutarmi

    Ciao Davide

  2. #2
    Utente di HTML.it L'avatar di kodode
    Registrato dal
    Sep 2002
    Messaggi
    1,896
    quali sono i valori che si ripetono? quelli della tabella cute_news o cute_story?
    i record sono esatti (senza doppioni intendo)?
    hai provato a far eseguire la query direttamente sul db (magari con phpMyAdmin)?

  3. #3
    Utente di HTML.it
    Registrato dal
    Apr 2005
    Messaggi
    29
    è strano se con phpmyadmin uso la funzione cerca ed uso il where che dovrebbe usare php mi trova il risultato giusto, e non ci sono doppioni -_-

    già che ci sono posto il codice delle tabelle

    codice:
    CREATE TABLE `cute_news` (
      `date` int(11) NOT NULL,
      `author` varchar(255) NOT NULL,
      `title` varchar(255) NOT NULL,
      `short` int(11) NOT NULL,
      `full` int(11) NOT NULL default '0',
      `avatar` varchar(255) NOT NULL,
      `category` varchar(255) NOT NULL,
      `url` varchar(255) NOT NULL,
      `id` int(11) NOT NULL auto_increment,
      `views` int(11) NOT NULL default '0',
      `comments` int(11) NOT NULL default '0',
      `hidden` tinyint(1) NOT NULL default '0',
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
    
    INSERT INTO `cute_news` VALUES (1186244546, 'dosky', 'Test', 9, 0, '', '', 'test', 1, 40, 2, 0);
    INSERT INTO `cute_news` VALUES (1186248652, 'dosky', '2° Test oo', 5, 0, '', '', '2-test-oo', 2, 0, 0, 0);
    INSERT INTO `cute_news` VALUES (1186262387, 'dosky', 'Test', 4, 5, '', '', 'test-3', 3, 1, 0, 0);
    
    -----------------------------------------------------------
    
    CREATE TABLE `cute_story` (
      `post_id` int(11) NOT NULL,
      `short` text NOT NULL,
      `full` text NOT NULL,
      PRIMARY KEY  (`post_id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    
    
    INSERT INTO `cute_story` VALUES (1, 'News Test', '');
    INSERT INTO `cute_story` VALUES (2, 'TEEST', '');
    INSERT INTO `cute_story` VALUES (3, 'Test', 'Prova');
    Non so se è utile, ma non so priprio cosa non va -_-

  4. #4
    Utente di HTML.it L'avatar di kodode
    Registrato dal
    Sep 2002
    Messaggi
    1,896
    quali sono i valori che si ripetono? quelli della tabella cute_news o cute_story?

    non fare "cerca" su phpMyAdmin ma usando "sql"

  5. #5
    Utente di HTML.it
    Registrato dal
    Apr 2005
    Messaggi
    29
    ma cosa dovrei scrivere nel sql?

  6. #6
    Utente di HTML.it L'avatar di kodode
    Registrato dal
    Sep 2002
    Messaggi
    1,896
    per la terza e ultima volta:

    quali sono i valori che si ripetono? quelli della tabella cute_news o cute_story?

  7. #7
    Utente di HTML.it
    Registrato dal
    Apr 2005
    Messaggi
    29
    dovrebbro essere quelli in cute_story

  8. #8
    Utente di HTML.it L'avatar di kodode
    Registrato dal
    Sep 2002
    Messaggi
    1,896
    fatti stampare la query generata dal codice e la provi su phpMyAdmin:

    Codice PHP:
    // Includo il Tpl delle news 
        
    include(INCPATH."temp/news.tpl"); 
                
    // Records Query 
                
    $count mysql_query("SELECT COUNT(id) FROM cute_news WHERE date < ".time()); 
                
    $res_count mysql_fetch_row($count); 
                
    // Numero di Records 
                
    $tot_records $res_count[0]; 
                
    // Records per Page 
                
    $per_page 7
                
    // Total Page 
                
    $tot_pages ceil($tot_records $per_page); 
                
    // Current Page 
                
    $current_page = (!$_GET['page']) ? : (int)$_GET['page']; 
                
    // LIMIT Param 
                
    $primo = ($current_page 1) * $per_page
                
    // WHILE Per visualizzare i Records 
                
    $query_lim mysql_query("SELECT * FROM cute_news WHERE date < ".time()." LIMIT $primo$per_page"); 
                if (
    mysql_num_rows($query_lim) == 0) { 
                } else { 
                    while(
    $news mysql_fetch_array($query_lim)) { 
                    
    $query_txt mysql_query("SELECT * FROM cute_story WHERE post_id ='".$news['id']."'"); 
                        while(
    $txt mysql_fetch_array($query_txt)) { 
                            
    $news_body $news_body
                            
    $news_body str_replace("{title}"$news['title'], $news_body); 
                            
    $news_body str_replace("{author}"$news['author'], $news_body); 
                            
    $news_body str_replace("{date}", (date('d-m-Y'$news['date'])), $news_body); 
                            
    $news_body str_replace("{news}"$txt['short'], $news_body); 
                if(
    $_SESSION[permission]) {     $news_body str_replace("{logged}"$txt['full'], $news_body); 
                } else {    
    $news_body str_replace("{logged}"''$news_body); } 
                            
    $news_body str_replace("{comments}"$news['comments'], $news_body); 
                            echo 
    $news_body
                        } 
                    } 
                    
    $paginazione "<div align=\"right\">"
                    
    // Visualizzazione delle Pagine con gli OPTION 
                    
    $paginazione "<select onChange=\"MM_jumpMenu('parent',this,0)\" name=\"menu\">\n"
                    for(
    $i 1$i <= $tot_pages$i++) { 
                    if(
    $i == $current_page) { 
                    
    $paginazione .= "<option value=\"?id=news&page=$i\" selected=\"selected\">Pagina $i</option>\n"
                    } else { 
                    
    $paginazione .= "<option value=\"?id=news&page=$i\">Pagina $i</option>\n"
                    }} 
                    
    $paginazione .= "</select>"
                    
    $paginazione .= "</div>";
    echo 
    "
    query_txt :"
    .$query_txt."
    "

    quindi copi la query, vai su phpMyAdmin e nell'area sql incolli ed esegui....

  9. #9
    Utente di HTML.it
    Registrato dal
    Apr 2005
    Messaggi
    29
    Mi restituisce Resource id #19

    E nella query nel sql mi seleziona tutti gli id

    ma la cosa che mi sembra un po' strana è il fatto che la news me la seleziona s l'id è giusto ma la mette 3 volte

  10. #10
    Utente di HTML.it L'avatar di kodode
    Registrato dal
    Sep 2002
    Messaggi
    1,896
    questa riga
    Codice PHP:
    echo "
    query_txt :"
    .$query_txt."
    "

    cosa ti stampa?

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.