View Single Post
Old 29-09-2008, 11:53   #2
ciuhd
Junior Member
 
L'Avatar di ciuhd
 
Iscritto dal: May 2006
Città: cosenza
Messaggi: 14
Ciao!
A quanto ho capito a funzione che vuoi creare dato un $user_id e un codice oggetto $item a cui l'utente ha fatto un offerta deve restituire
true se è l'unica è più bassa
e false altrimenti...

Quote:
Il db è strutturato così:
id | user_bid | item | bid
Forse volevi dire la tabella...

Il problema è solo quello di interrogare il db in maniera opportuna.
Potresti impostare la funzione così:

Codice PHP:
function offertaVincente$user_bid,  $item ){

$query "SELECT  * from nomeTabella AS T1
WHERE T1.user_bid = 
$user_bid AND T1.item = $item 
AND T1.bid <= ALL ( SELECT T2.bid FROM nometabella AS T2
WHERE T1.item = T2.item AND T1.user_bid != T2.user_bid ) //è lofferta più bassa fatta sul determinato oggetto
AND NOT EXISTS ( SELECT * from nometabella AS T3    //ed è anche l'unica 
WHERE T1.item = T3.item AND T3.bid < T1.bid ) ;

$res = mysql_query($query);

if ( mysql_affected_rows( 
$res ) > 0 ) 
return true;

return false;


La query non l'ho provata ma dovrebbe funzionare, fammi sapere.
Per semplificare la query potresti ricorrere all'uso delle viste.
ciuhd è offline   Rispondi citando il messaggio o parte di esso