Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    [PHP-Javascript]inserimento occorrenze.

    avrei questo codice javascript

    codice:
    <script language="JavaScript" type="text/JavaScript">
    <!--
    var FiltersEnabled = 0; // se non vuoi usare transizioni o filtri in nessuno dei tips impostala a 0
    Text[8]=["Incolla","prova.
    : HTML.it."];
    Style[5]=["white","black","#000099","#E8E8FF","","","left","left","","","","sticky","","",200,"",2,2,10,10,"","","","",""];
    
    applyCssFilter();
    
    
    //-->
    </script>
    praticamente dovrei stamapre X volte l'array Text[$i];

    non so proprio come fare

    cioè l'ipotetico codice dovrebbe fare una cosa tipo questa
    codice:
    $sel="selezione db";
    while($rec=mysql_fetch_array($sel))
    {
     $text[$i]="text[$i]= "blalblabla"
    }
    così da avere in Text[$i] i dati prelevati da database.

  2. #2

    .....

    Ciao.
    Se capito bene questo potrebbe
    esserti utile:
    Codice PHP:
    <?php
    $db
    =mysql_connect('localhost','','') or die('Error connecting to the server');
          
    mysql_select_db('blogial') or die('Error selecting database');
          
    $result=mysql_query('SELECT cat_name FROM categories') or die ('Error performing query'); 

            function 
    createJavaScript($dataSource,$arrayName='rows'){
          
    // validate variable name
          
    if(!is_string($arrayName)){
            die(
    'Invalid variable name');
          }

        
    // initialize JavaScript string
          
    $javascript='<script>var '.$arrayName.'=[];';

        
    // check if $dataSource is a file or a result set
          
    if(is_file($dataSource)){
           
            
    // read data from file
            
    $row=file($dataSource);

            
    // build JavaScript array
            
    for($i=0;$i<count($row);$i++){
              
    $javascript.=$arrayName.'['.$i.']="'.trim($row[$i]).'";';
    $javascript.="\n";
            }
          }

          
    // read data from result set
          
    else
          {
            
    $i 0;
              
    $tempOutput='';

              while(
    $row=mysql_fetch_array($dataSource,MYSQL_NUM))
                {
                   
    $tempOutput.= $arrayName.'['.$i.']'."=\"".trim($row[0]).'";';
                
    $tempOutput.= "\n";
    $i++;
              }
              
    $javascript.= $tempOutput;
                
            
          }

          
    $javascript.='</script>'."\n";
     
          
    // return JavaScript code
          
    return $javascript;
        }
    echo 
    createJavaScript('news.txt','news');
    ?>
    <html>

    <head>

    <title>CLIENT-SIDE NEWS TICKER</title>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <script language="javascript">

    var numNews,counter;

    // count number of news

    numNews=news.length;

    // initialize news counter

    counter=0;

    createNewsDiv=function(){

    // create news containing <div> element

    var newsDiv=document.createElement('div');

    newsDiv.id='news';

    // insert news <div> into document structure

    //document.body.appendChild(newsDiv);
    document.getElementById('po').appendChild(newsDiv);
    }

    rotateNews=function(){

    // get news containing <div>

    var newsDiv=document.getElementById('news');

    if(!newsDiv){return;}

    // create new <div> element

    var div=document.createElement('div');

    div.id='news';

    // create paragraph for each news line

    var p=document.createElement('p');

    // style 

     element

    p.style.fontFamily='Verdana';

    p.style.fontSize='11px';

    p.style.fontWeight='bold';

    p.style.color='#c00';

    if(counter==numNews){counter=0;}

    p.appendChild(document.createTextNode(news[counter]));

    // insert paragraph into <div> news

    div.appendChild(p);

    // replace old <div> node with new <div> node

    newsDiv.parentNode.replaceChild(div,newsDiv);

    counter++;

    // rotate news every 10 seconds

    setTimeout('rotateNews()',1*1000);

    }
    timing = function()
    {

    //setTimeout('rotateNews()',1*1000);
    }

    // execute functions when page is loaded

    window.onload=function(){

    if(document.getElementById){

    createNewsDiv();
    rotateNews();




    }

    }

    </script>

    <style type="text/css">

    /*define style for news container*/

    #news {

    background: #eee;

    padding: 2px 0px 2px 10px;

    border: 1px solid #000;

    }

    </style>

    </head>

    <body>
    <div id="po"></div>

    </body>

    </html>
    Come vedi lo snippet fa anche dell'altro
    ma penso che per darti lo spunto possa
    andare.

    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  3. #3

    ........

    Se non ti torna guarda qui

    PHP and JavaScript Interaction: Storing Data in the Client, part 1

    forza Alejandro Gervasio gli farei un monumento





    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

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.