Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 14

Discussione: Leggere da db..

  1. #1

    Leggere da db..

    sera,
    se uno crea una tabella in questo modo:
    (non fate caso al nome della tabella, non leggo con Flash)

    CREATE TABLE `flash_news` (
    `id` smallint(5) NOT NULL auto_increment,
    `author` varchar(60) NOT NULL default '',
    `timestamp` int(10) NOT NULL default '0',
    `title` varchar(200) NOT NULL default '',
    `body` text NOT NULL,
    PRIMARY KEY (`id`)
    ) TYPE=MyISAM;

    è sufficiente per poi decidere si stamapre l'id=1 in un determinato posto di una pagina e così via per gli altri?


    e se si, come..

    o è necessario aggiugere dell'altro? :master:
    Interactive Html/CSS/JS Playground | @webbeloz ( cip..cip! )
    Mechanics & Expert Tuning Fix Z3 Roadster Community

  2. #2
    Si è sufficiente.
    Prima di tutto devi inserire dei dati nell tabela creata (con una query INSERT oppure direttamente da phpmyadmin)

    Successivamente devi fare una quesry del tipo SELECT id FROM flash_news WHERE (condizione)

    poi la scrivi in un array

    $array=mysql_fetch_row(nome query)

    e infine scrivi il dato dell'array..

    sono stato molto stringato...se ti serve una spiegazione più "profonda" chiedi pure
    http://embracesblog.mine.nu
    http://wiki.ubuntu-it.org/AndreaOlivato

  3. #3
    Originariamente inviato da Crypt
    Si è sufficiente.
    Prima di tutto devi inserire dei dati nell tabela creata (con una query INSERT oppure direttamente da phpmyadmin)

    Successivamente devi fare una quesry del tipo SELECT id FROM flash_news WHERE (condizione)

    poi la scrivi in un array

    $array=mysql_fetch_row(nome query)

    e infine scrivi il dato dell'array..

    sono stato molto stringato...se ti serve una spiegazione più "profonda" chiedi pure
    è già qualcosa..
    ok per scrivere da phpmyadmin!

    ma se io ho una cosa del genere:
    codice:
    <?php
    #***********************************
    #  XML OUTPUT
    #***********************************
    
    
    include('admin/functions.php');
    connect('tennisco_','','tennisco_parse','localhost');
    $query = 'SELECT id, author, title, body, FROM_UNIXTIME(timestamp, \'%M %D %Y\') date
     					FROM flash_news
     					LIMIT 20';
    
    $result = mysql_query($query);
    
    
     $nl = "\r\n";
    
     	echo '<?xml version="1.0" encoding="ISO-8859-1"?>' . $nl;
      echo '<ROOT>' . $nl;
    
     while($r = mysql_fetch_array($result)){
    
     	echo '<news id="' . $r['id'] . '" title="' . stripslashes2($r['title']) . '" date="' . $r['date'] . '" author="' . stripslashes2($r['author']) . '">' . $nl;
    	echo '<body><![CDATA[' . stripslashes2($r['body']) . ']]></body>' . $nl;
     	echo '</news>' . $nl;
    
     }
    
     echo '</ROOT>' . $nl;
    
     ?>
    come la posso adattare per vedere qualcosa?
    troppo difficile?
    Interactive Html/CSS/JS Playground | @webbeloz ( cip..cip! )
    Mechanics & Expert Tuning Fix Z3 Roadster Community

  4. #4
    Se vuoi semplicemente vedere cosa stampa basta che aggiungi
    codice:
    echo
    "
    id =".$result[0]."
    
    author =".$result[1]."
    
    title =".$result[2]."
    
    body =".$result[3]."
    
    ";
    inserendolo prima di
    }

    echo '</ROOT>' . $nl;
    http://embracesblog.mine.nu
    http://wiki.ubuntu-it.org/AndreaOlivato

  5. #5
    Originariamente inviato da Crypt
    Se vuoi semplicemente vedere cosa stampa basta che aggiungi
    codice:
    echo
    "
    id =".$result[0]."
    
    author =".$result[1]."
    
    title =".$result[2]."
    
    body =".$result[3]."
    
    ";
    inserendolo prima di
    }

    echo '</ROOT>' . $nl;
    in questo modo però mi restituisce solo questo:
    id =
    author =
    title =
    body =
    id =
    author =
    title =
    body =
    id =
    author =
    title =
    body =
    id =
    author =
    title =
    body =
    id =
    author =
    title =
    body =
    id =
    author =
    title =
    body =

    non i contenuti però..
    Interactive Html/CSS/JS Playground | @webbeloz ( cip..cip! )
    Mechanics & Expert Tuning Fix Z3 Roadster Community

  6. #6
    Scusa...distrazione mia

    prima di quel codice inserisci

    $result=mysql_fetch_row($result);
    http://embracesblog.mine.nu
    http://wiki.ubuntu-it.org/AndreaOlivato

  7. #7
    credo di aver risolto..

    grazie
    Interactive Html/CSS/JS Playground | @webbeloz ( cip..cip! )
    Mechanics & Expert Tuning Fix Z3 Roadster Community

  8. #8
    non è tutto apposto..
    come da code, in questo modo si stampano tutti gli id.. cioè tutte le voci presenti! oppure con piccola modifica si potrebbe stampare solo un id e le rispettive voci..

    se invece di avere tutti gli id insieme, volessi visualizzare un id per ogni <div>.. come dovrei fare?

    :master:
    Interactive Html/CSS/JS Playground | @webbeloz ( cip..cip! )
    Mechanics & Expert Tuning Fix Z3 Roadster Community

  9. #9
    riUP !!
    riporto tutto per avere + chiaro il problema..
    con il code che metto sotto vado a leggere delle news

    codice:
    <?php
    #***********************************
    #  XML OUTPUT
    #***********************************
    
    
    include('admin/functions.php');
     connect('tennisco_','','tennisco_parse',
    'localhost');
    $query = 'SELECT id, author, title, body, FROM_UNIXTIME(timestamp, '%M %D %Y') date
     					FROM flash_news
     					LIMIT 20';
    
    $result = mysql_query($query);
    
    
     $nl = "\r\n";
    
     	echo '<?xml version="1.0" encoding="ISO-8859-1"?>' . $nl;
      echo '<ROOT>' . $nl;
    
     #***while($r = mysql_fetch_array($result)){
    
     	echo '<news id="' . $r['id'] . '" title="' . stripslashes2($r['title']) . '" date="' . $r['date'] . '" author="' . stripslashes2($r['author']) . '">' . $nl;
    	echo '<body><![CDATA[' . stripslashes2($r['body']) . ']]></body>' . $nl;
     	echo '</news>' . $nl;
    
    $result=mysql_fetch_row($result);
    
     #***}
    
     echo '</ROOT>' . $nl;
    
     ?>

    questa la tabella
    CREATE TABLE `flash_news` (
    `id` smallint(5) NOT NULL auto_increment,
    `author` varchar(60) NOT NULL default '',
    `timestamp` int(10) NOT NULL default '0',
    `title` varchar(200) NOT NULL default '',
    `body` text NOT NULL,
    PRIMARY KEY (`id`)
    ) TYPE=MyISAM;

    mentre con:
    <?PHP
    echo
    $result[3];
    ?>
    mi stampo appunto il 'body' e fin quì tutto bene..

    La mia domanda è:
    come faccio a leggere/stampare il campo 'body' di ciascun 'id' ?

    spero sia chiaro..
    Interactive Html/CSS/JS Playground | @webbeloz ( cip..cip! )
    Mechanics & Expert Tuning Fix Z3 Roadster Community

  10. #10
    no eh!?
    Interactive Html/CSS/JS Playground | @webbeloz ( cip..cip! )
    Mechanics & Expert Tuning Fix Z3 Roadster Community

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.