Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 13
  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    3,072

    condizione where per testo (utilizzando un zend)

    Ciao a tutti, ho un problema in Zend ma credo che il problema sia pių legato a PHP

    $row = $this->fetchRow('username = ' . $username);

    questa query funziona con valori int ma non per ricecercare una stringa


    so che per i testi dovrei usare ' ' ma mi chiedevo se in in questa struttura

    fetchRow('username = ' . $username);

    ci sia una soluzione, in zend, per ricercare un testo

    Grazie

  2. #2
    il problema non č legato nč a zend nč a php, ma a SQL: per cercare o confrontare stringhe dovresti ad esempio usare l'operatore LIKE opportunamente configurato:

    http://dev.mysql.com/doc/refman/5.0/...functions.html

    es: se vuoi cercare tutte le stringhe che iniziato i con una determinata stringa dovresti usare qualcosa del tipo:

    Codice PHP:
    $row $this->fetchRow("username LIKE '%{$username}' "); 

  3. #3
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    3,072
    Grazie mille!!!

    quindi senza like (ma con ricerca esatta) sarebbe:

    $row = $this->fetchRow("username = '{$username}' ");

    Corretto??


    ma perchč usare le parentesi graffe e non direttamente


    $row = $this->fetchRow("username = '$username' ");

    ??

    Grazie per l'aiuto

  4. #4
    quindi senza like (ma con ricerca esatta) sarebbe:
    $row = $this->fetchRow("username = '{$username}' "); Corretto??
    esatto!

    si va bene anche se parentesi: a volte mi viene da metterle per abitudine, ma in questo caso chiaramente funziona anche senza!

  5. #5
    Codice PHP:
    $row $this->fetchRow('username = ' $username); 
    ma per curiosita a parte che al limite sarebbe
    Codice PHP:
    $row $this->fetchRow('username = ?' $username); 
    ma dove la hai presa sta sintassi senza la select ?


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

  6. #6
    fetchRow č un metodo della classe Zend_Db_Table, anche se :

    "However, the deprecated usage of the fetchRow() and fetchAll() methods will continue to work without modification. "

  7. #7
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    3,072
    Deprecated?? ((

    e cosa uso in zend al posto del mio bel fetchRow??

    Grazie

  8. #8
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    3,072
    Cmq avevo giā provato con

    $row = $this->fetchRow('username = ?' , $username);

    ed ottengo:

    Message: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound


    questo invece:

    $row = $this->fetchRow("username = '$username' ");


    funziona alla grande!!!!!

  9. #9
    Originariamente inviato da maje
    fetchRow č un metodo della classe Zend_Db_Table, anche se :

    "However, the deprecated usage of the fetchRow() and fetchAll() methods will continue to work without modification. "
    dicevo per la sintassi

    Codice PHP:
    $row $bugs->fetchRow($bugs->select()->where('bug_id = ?'1)); 
    non mi sembra proprio uguale


    codice:
    However, the deprecated usage of the fetchRow() and fetchAll() methods will continue to work without modification. "
    si riferisce al plain sql non alla select e ci mancherebbe altro
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  10. #10
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    3,072
    Confusione....

    primo dubbio:
    fetchRow depreated oppure no????


    secondo dubbio:
    il tuo esempio con il passaggio parametri tramite ? non funziona, come da post precedente

    terzo dubbio:
    $row = $rows->fetchRow($rows->select()->where("username = '$username'"));
    nemmeno questo funziona...

    io ho

    public function getUser($username)
    {
    //$row = $this->fetchRow("username = '$username'");
    $row = $rows->fetchRow($rows->select()->where("username = '$username'"));

    ed ottengo:



    Notice: Undefined variable: rows in /Applications/MAMP/htdocs/backoffice/application/models/DbTable/Users.php on line 15

    Fatal error: Call to a member function fetchRow() on a non-object in /Applications/MAMP/htdocs/backoffice/application/models/DbTable/Users.php on line 15


    ovviamente non trova la variabile $rows ma infatti io non posso averla.....

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.