.dsy:it.
Show 150 posts per page

.dsy:it. (http://www.dsy.it/forum/)
- Tech (http://www.dsy.it/forum/forumdisplay.php?forumid=189)
-- [PHP] ma le tabelle come si dovrebbe gestirle? (http://www.dsy.it/forum/showthread.php?threadid=19481)


Posted by maynard80 on 13-05-2005 12:43:

[PHP] ma le tabelle come si dovrebbe gestirle?

e tabelle html come si dovrebbe gestirle? cioè se ho un centinaio di tuple da stampare secondo una certa query secondo voi è giusto costruire la tabella tramite stringhe php o è meglio costruire tabelle con pezzi di codice php?

nel senso:

PHP:

function stampaRosa(){
         $color1 = '#DDFFDD'; 
        $color2 = '#DDCAFF'; 
        $color  = '#5533dd';
        $count=1;
        $query = "SELECT giocatori.cognome,giocatori.ruolo FROM giocatori,utente_has_giocatori where utente_has_giocatori.utente_nick='alex' and giocatori.cognome=utente_has_giocatori.giocatori_cognome";
        $res = mysql_query($query);
        if ($res)
            echo "<br><br>GIOCATORI presenti nella ROSA: ".mysql_num_rows($res)."";
        if (!$res) {
            echo "Errore nella query richiesta.\n";
         exit;
         } 
           
        echo "<table><tr><td bgcolor='$color' width='160'><b>Cognome</b></td><td bgcolor='$color'  width='160'><b>Ruolo</b></td></tr>";
        while ($row = mysql_fetch_array($res)) {
            if($count%2)
                $color=$color1;
            else
                $color=$color2;
            echo"<form action='iframe4.php' method='post' enctype='multipart/form-data'>"; 
            printf ("<tr>");
            printf ("<td bgcolor='$color'> $count) %s</td><td bgcolor='$color'>%s</td>", $row[0], $row[1]);
            $selezione=$row[0];
            printf ("<td><input type='hidden' value='$selezione' name='venduto'><input type='submit' value='Vendi !'></td></tr>");
            printf ("</tr>");
            $count++;
            echo "</form>";
            }  
        echo "</table>";
        }




da uno a 10 quanto fa schifo? (il php lo studio da una settimana)

se volete sorridere un po' sul codice brutto ve lo permetto, ma a patto che inserite un consiglio serio almeno :D

__________________
msn Messenger: giamma80 at tiscali.it
ATHENA !


Posted by Alf on 13-05-2005 12:51:

Potresti fare un for da 1 a mysql_num_rows($res) (per esempio invece del while)

:)

__________________
(\ /)
( . .)
c('')('') This is Bunny!
Help her succeed in world domination by copy and pasting her in
your signature.


Posted by maynard80 on 13-05-2005 14:27:

ok, ma il mio quesito interessa l'uso delle tabelle, secondo voi la funzione php deve ritornare una stringa da usare da una tabella html, oppure va bene fare tutto in php?

__________________
msn Messenger: giamma80 at tiscali.it
ATHENA !


Posted by Alf on 13-05-2005 14:33:

Mhh ora ho bene al tua domanda.

Non saprei non ci vedo molta differenza.
Cosa credi di fare quando fai echo ???
Dai in pasto all'html (al servr web) un codice html no ?

Cmq come penseresti di creare "una stringa da usare da una tabella html" ???

La tabella o la crei dinamicamente oppure la crei statica (sapendo pero' quante sono le righe).

Ma nel secondo caso mi pare un po' inutile usare php

__________________
(\ /)
( . .)
c('')('') This is Bunny!
Help her succeed in world domination by copy and pasting her in
your signature.


Posted by maynard80 on 14-05-2005 12:03:

gia che ci siamo, se condo voi dove sta l'errore in questa query?

code:
UPDATE utente SET budget = ( (SELECT budget from utente where nick='$utente') -(select valore from giocatori where cognome='$comprato') ) WHERE nick='$utente'



utente(nick,psw,budget)
giocatori(cognome,ruolo,valore)

__________________
msn Messenger: giamma80 at tiscali.it
ATHENA !


Posted by Drake83 on 14-05-2005 12:16:

Originally posted by maynard80
gia che ci siamo, se condo voi dove sta l'errore in questa query?

code:
UPDATE utente SET budget = ( (SELECT budget from utente where nick='$utente') -(select valore from giocatori where cognome='$comprato') ) WHERE nick='$utente'



utente(nick,psw,budget)
giocatori(cognome,ruolo,valore)


comincia col dire che errore ti segnala.magari è piu' facile capire se è errore di sintassi o semantico.

__________________
"io non sono come gli altri Robin Hood, io non ballo coi lupi"
"ogni mattina come narciso si specchia nel ruscello retrovisore", "ci sono mille modi per chiamare dio...dio,allha,adta,arauffa,crisma..afjasf...tanto non ti risponde"

Corrado Guzzanti è il mio Dio.
Roberto Saviano eroe nazionale.


Posted by korn on 16-05-2005 09:03:

Un paio di appunti veloci:

- perché avresti messo enctype='multipart/form-data' in una form che passa soltanto un campo testuale?

- ma soprattutto, perché fare una form per ogni tupla? Sarebbe più elegante e pulito fare una form globale, così da alleggerire il codice e permettere eventualmente selezioni multiple.

- $selezione=$row[0]; è inutile, potresti semplicemente fare value='" . $row[0] . "'.

- ultima cosa, per i valori delle proprietà dei tag HTML sarebbe meglio utilizzare i doppi apici, per farlo dentro una stringa PHP usa \".

__________________
» Collect some stars to shine for you, and start today ‘cause there are only a few. _ (In Flames)
» Don't stop for nothing, it's full speed or nothing! I'm taking down, you know, whatever is in my way! _ ('tallica)
» I am my own god, I do as I please. _ (Pain)
» Ninetynine, ninetynine knives! Ninetynine knives inside! Nobody gets out alive! _ (The Haunted)
Web: http://www.negativesignal.com - ICQ# 171585477 - Death to software patents! And TCPA too! "e uno!", diceva il boia.


Posted by maynard80 on 16-05-2005 10:21:

query SQL:

code:
UPDATE utente SET budget = ( ( SELECT budget FROM utente WHERE nick = 'alex' ) - ( SELECT valore FROM giocatori WHERE cognome = 'zola' ) ) WHERE nick = 'alex'

Messaggio di MySQL:

#1093 - You can't specify target table 'utente' for update in FROM clause


dove sbaglio? le tabelle sono
utente(nick,psw,budget)
giocatori(cognome,ruolo,valore)

__________________
msn Messenger: giamma80 at tiscali.it
ATHENA !


Posted by korn on 17-05-2005 08:34:

Originally posted by maynard80
query SQL:

code:
UPDATE utente SET budget = ( ( SELECT budget FROM utente WHERE nick = 'alex' ) - ( SELECT valore FROM giocatori WHERE cognome = 'zola' ) ) WHERE nick = 'alex'

Messaggio di MySQL:

#1093 - You can't specify target table 'utente' for update in FROM clause


dove sbaglio? le tabelle sono
utente(nick,psw,budget)
giocatori(cognome,ruolo,valore)


Nel momento in cui fai un UPDATE non hai bisogno di fare una SELECT per leggere valori dalla stessa tabella, ad esempio se dovessi incremetare un campo numerico potresti fare UPDATE tabella SET campo = (campo+10);.

Nel tuo caso quindi la soluzione dovrebbe essere questa (non posso testarla in questo momento, ma in genere uso query simili e funzionano correttamente):


UPDATE utente SET budget = budget - (

SELECT valore
FROM giocatori
WHERE cognome = 'zola' )

WHERE nick = 'alex';


Attenzione però, perché le versioni di MySQL precedenti alla 4 non supportano le sottoquery, quindi assicurati di averne una aggiornata.







E meno male che ComDig è fuffa.......... :asd:

__________________
» Collect some stars to shine for you, and start today ‘cause there are only a few. _ (In Flames)
» Don't stop for nothing, it's full speed or nothing! I'm taking down, you know, whatever is in my way! _ ('tallica)
» I am my own god, I do as I please. _ (Pain)
» Ninetynine, ninetynine knives! Ninetynine knives inside! Nobody gets out alive! _ (The Haunted)
Web: http://www.negativesignal.com - ICQ# 171585477 - Death to software patents! And TCPA too! "e uno!", diceva il boia.


All times are GMT. The time now is 22:10.
Show all 9 posts from this thread on one page

Powered by: vBulletin Version 2.3.1
Copyright © Jelsoft Enterprises Limited 2000 - 2002.