Visualizzazione dei risultati da 1 a 7 su 7

Discussione: Problema query select

  1. #1

    Problema query select

    Salve, avrei un piccolo problemino...

    ho un index che si compone di 3 template:
    Codice PHP:
     <td width="133" align="left" valign="top"> 
                <? require('../_include/template_sinistro.php');?>
              </td>
              
            <td width="504" align="center" valign="top"> 
              <? require('../_include/template_centro.php');?>
              </td>
              <td width="133" align="right" valign="top">
                <? require('../_include/template_destro.php');?>
              </td>
    Ora, nel template sinistro volevo far visualizzare in un riquadro un'immagine random e allora ho inserito questo in template_sinistro.php:

    Codice PHP:
    <?
    include("../_include/config.php");

    $query="Select * from flyer ORDER BY RAND()";
    $result=mysql_query($query) or die ("Query errata".$query);
    $array=mysql_fetch_array($result);
    ?>
    e poi gli facevo visualizzare la foto:
    Codice PHP:


    [url="javascript:popupfoto('<? print $array[id]?>');"][img]<?print $array[fotomini];?>[/img][/url]</p>
    .


    E fin qui tutto bene... peccato che nel template centrale ci sono altre informazioni che sarebbero da prendere in altre tabelle, e invece ora me le va a cercare nella tabella flyer.


    Scusate se la domanda sembra banale, ma sono proprio alle prime armi e non so dove sbattere la testa...

  2. #2
    Utente di HTML.it L'avatar di Avalox
    Registrato dal
    Nov 2003
    Messaggi
    302
    posta il codice del template centrale...


  3. #3

    template_centro.php

    Eccolo


    Codice PHP:
    <? 
    include("../_include/config.php");
    require (
    '../cal/gocal.php'); 

    $query1="Select * from home where id=1";
    $result1=mysql_query($query1) or die ("Query errata".$query1);
    $arnews1=mysql_fetch_array($result1);

    $query2="Select * from home where id=2 ";
    $result2=mysql_query($query2) or die ("Query errata".$query2);
    $arnews2=mysql_fetch_array($result2);

    $query3="Select * from home where id=3 ";
    $result3=mysql_query($query3) or die ("Query errata".$query3);
    $arnews3=mysql_fetch_array($result3);

    $query4="Select * from home where id=4 ";
    $result4=mysql_query($query4) or die ("Query errata".$query4);
    $arnews4=mysql_fetch_array($result4);

    $query5="Select * from home where id=5 ";
    $result5=mysql_query($query5) or die ("Query errata".$query5);
    $arnews5=mysql_fetch_array($result5);

    $query6="Select * from home where id=6 ";
    $result6=mysql_query($query6) or die ("Query errata".$query6);
    $arnews6=mysql_fetch_array($result6);

    $query7="Select * from home where id=7 ";
    $result7=mysql_query($query7) or die ("Query errata".$query7);
    $arnews7=mysql_fetch_array($result7);

    $query8="Select * from home where id=8 ";
    $result8=mysql_query($query8) or die ("Query errata".$query8);
    $arnews8=mysql_fetch_array($result8);

    $query17="Select * from home where id=17 ";
    $result17=mysql_query($query17) or die ("Query errata".$query17);
    $arnews17=mysql_fetch_array($result17);

    $query18="Select * from home where id=18 ";
    $result18=mysql_query($query18) or die ("Query errata".$query18);
    $arnews18=mysql_fetch_array($result18);
    ?>
    <style type="text/css">
    <!--
    .style1 {
        font-family: Verdana, Arial, Helvetica, sans-serif;
        font-size: 10px;
        color: #FFFFFF;
        font-weight: bold;
    }
    .style2 {color: #CE0000}
    -->
    </style>

    <table width="494" border="0" cellpadding="0" cellspacing="0" bgcolor="#CE0000">
      <tr> 
        <td height="4" colspan="2" align="center" valign="top">[img]../img/spacer.gif[/img]</td>
      </tr>
      <tr>
        <td height="0" colspan="2" align="center" valign="top">[img]/img/bserate.jpg[/img]</td>
      </tr>
      <tr> 
        <td width="50%" height="0" align="center" valign="top"> <table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#CC0000">
            <tr> 
              <td colspan="2" valign="bottom" bgcolor="#FFFFFF"> <? print '

    <font size="1" face="Verdana, Arial, Helvetica, sans-serif">[b]'
    .$arnews1[titolo].
                        [/b]</font></p>'
    ;
                    
    ?> </td>
            </tr>    
            <tr> 
              <td width="70" height="70"> <? print '[img]'.$arnews1[foto].'[/img] ';
                    
    ?> </td>
              <td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
                  <tr> 
                    <td height="0" valign="top"> <table width="100%" height="0" border="0" cellpadding="1" cellspacing="0" bgcolor="#FFFFFF">
                        <tr> 
                          <td height="64" valign="top" class="corpo10rosso"> <? print ''.$arnews1[testo].'';
                                
    ?> </td>
                        </tr>
                      </table></td>
                  </tr>
                  <tr> 
                    <td height="6" align="right" valign="bottom">[img]../img/angletabhome.gif[/img]</td>
                  </tr>
                </table></td>
            </tr>
          </table></td>

  4. #4
    Ovviamente ho dovuto ridurre un po' perchè c'erano troppi caratteri. Ma per completare la pagina basta prendere l'ultima porzione di codice (dall'array del TITOLO) e riperterla per ognuna delle query.

  5. #5
    Utente di HTML.it L'avatar di Avalox
    Registrato dal
    Nov 2003
    Messaggi
    302
    A prima vista il codice che hai postato sembra corretto.... bruttino come soluzione, ma corretto...

    E fin qui tutto bene... peccato che nel template centrale ci sono altre informazioni che sarebbero da prendere in altre tabelle, e invece ora me le va a cercare nella tabella flyer.
    Impossibile... nella select devi indicare la tabella dove andare a prendere le info, quindi l'errore è da ricercarsi in altri posti...

    Io inizierei con aggiungere gli apici agli array... poi guardiamo...
    Codice PHP:
    $arnews1['foto'

  6. #6

    Problema Risolto

    Ho capito tutto... gli apici non centrano, il problema è qui:

    Codice PHP:
              <?
    include("../_include/config.php");

    $query="Select * from dj ORDER BY nome";
    $result=mysql_query($query) or die ("Query errata".$query);
    $tot=mysql_num_rows($result);
    ?>


        <? require('../_include/template_superiore.php');?> 
          <table width="770" border="0" cellspacing="5" cellpadding="0">
            <tr> 
              <td width="133" align="right" valign="top"> 
                <? require('../_include/template_sinistro.php');?>
              </td>

              <td valign="top"> <table width=100% border=0 align="center" cellpadding="0" cellspacing="0" class="bordiform">
                  <tr> 
                    <td colspan=3 background="../img/sfondotitolo.gif">[img]../img/djtitle.gif[/img]</td>
                    <td width="58%" align=right background="../img/sfondotitolo.gif">[img]../img/djimg.jpg[/img]</td>
                  </tr>
                  <tr align="left" valign="top"> 
                    <td height="365" colspan=4> 
                      <table width="100%" height="0%" border="0" cellpadding="0" cellspacing="10" class="bordiform">
                        <?
                              $i
    =0;
                              while (
    $array=mysql_fetch_array($result)){
                          
    ?>
                        <tr> 
                          <td><? print'[url="../dj/infodj.php?cod='.$array[id].'"]DJ '.$array[nome].'[/url]';?> 
                          </td>
                        </tr>
                        <?
                            
    if ($i>1){
                            
                            
    $i=0;
                          
    ?>
                        <?
                            
    }else{
                            
    $i++;
                            }
                            }
                          
    ?>
                      </table>
                    </td>
                  </tr>    
                  <tr align="right" valign="bottom">
                    <td colspan="4">[img]../img/bordodx.gif[/img]</td>
                  </tr>
                </table>
                
              </td>
              <td width="120" align="right" valign="top">
              <? require('../_include/template_destro.php');?>
              </td>
            </tr>
              </table> 
              <? require('../_include/template_inferiore.php'); ?>
              
    <?
    mysql_free_result
    ($result);
    mysql_close();
    ?>
    Ho preso in esame un'altra pagina diversa dall'index. Qui vediamo che prima esegue la query SELECT e poi va a richiamare il template sinistro che contiene a sua volta un'altra query SELECT. Ecco che gli array successivi vengono fatti sulla query del template sinistro e non su quella di inizio pagina. Infatti ho provato a spostare la query così:

    Codice PHP:
        <? require('../_include/template_superiore.php');?> 
          <table width="770" border="0" cellspacing="5" cellpadding="0">
            <tr> 
              <td width="133" align="right" valign="top"> 
                <? require('../_include/template_sinistro.php');?>
              </td>
              <?
    include("../_include/config.php");

    $query="Select * from dj ORDER BY nome";
    $result=mysql_query($query) or die ("Query errata".$query);
    $tot=mysql_num_rows($result);
    ?>
    E ora funziona tutto!

    Grazie cmq per la disponibilità!

  7. #7
    Utente di HTML.it L'avatar di Avalox
    Registrato dal
    Nov 2003
    Messaggi
    302
    Infatti... era proprio quello che ti volevo far capire...

    Il problema dipende dal fatto che utilizzi $result per entrambe le query, ma con la seconda sovrascrivi il risultato della prima e quindi quando fai
    Codice PHP:
    while ($array=mysql_fetch_array($result)){ 
    non hai più i risultati che volevi...

    Comunque sei riuscito a trovare l'inghippo

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 © 2024 vBulletin Solutions, Inc. All rights reserved.