Visualizzazione dei risultati da 1 a 6 su 6
  1. #1
    Utente di HTML.it
    Registrato dal
    Nov 2011
    Messaggi
    8

    Aiuto per modifica query

    Ciao a tutti, premetto che sono alle prime armi in php e in SQL, comunque,
    sto cercando di apportare una modifica ad un file in php dove ho cambiato la tabella e i campi di una query dove ho aggiunto anche "ORDER BY", purtroppo mi da un errore: la variabile in uscita "$aup_topay" risulta "0", se tolgo "ORDER BY" invece mi viene un valore a caso e non l'ultimo della lista che č quello che mi interessa; forse c'entra qualcosa la riga "$db->next_record()"?;
    la query č questa:

    $q ="SELECT order_total FROM #__{vm}_orders WHERE user_id=$aup_vendoruserid ORDER BY order_id DESC";
    $db->query($q);
    $db->next_record();
    $aup_cprice = $db->f("order_total");
    $aup_cprice= round($aup_cprice,2);
    $aup_topay = $aup_cprice * $paypcentage / 100 / $aupoint;
    qualcuno mi puoi dare una mano per favore?

    Ho provato ad eseguire la query direttamente in phpadmin e mi da esattamente la tabella selezionata ed ordinata, quindi mi viene da pensare che l'errore dovrebbe stare nel metodo con cui viene preso il primo campo della tabella.
    Ma dove?

  2. #2
    cosa č quel #__{vm}_orders ?????

  3. #3
    Utente di HTML.it
    Registrato dal
    Nov 2011
    Messaggi
    8

    E' il nome della tabella interessata

    Come ho detto nel titolo č il nome della tabella interessata, che fa parte della query che ho testato e funziona, quello che credo che non vā č il resto, perchč la variabile finale non viene riempita con l'ultimo valore inserito nella tabella.

  4. #4
    e il codice di $db->next_record(); ?

  5. #5
    Utente di HTML.it
    Registrato dal
    Nov 2011
    Messaggi
    8

    Fa parte del codice originario che č:

    Questa č la parte di codice in cui c'č la query modificata:


    $aupoint = 1; // As AUP doesn't care about decimals, we recommend setting the smallest unit the currency can handle
    $naming = 0 ; // 0 for username , 1 for realname
    $profileman = 0 ; // 0 for Community Builder, 1 for Jomsocial
    $profileitemid = '89' ; // Set here your own user profiles itemid
    $paypcentage = 100; // here 90 goes to the vendor so finally only 10 to the site owner.
    // End parameters

    if($naming==0) $naming = 'username';
    elseif ($naming==1) $naming = 'name';
    $aup_download_id = $db->f("download_id");
    $aup_file_name = $db->f("file_name");
    $aup_clientid = $db->f("user_id");
    $aup_productid = $db->f("product_id");
    /// Here we get the naming of the customer:
    $q="SELECT ".$naming." FROM #__users WHERE id='".$aup_clientid."'";
    $db->query($q);
    $clientnaming = $db->loadResult();

    if($profileman==0)
    $clientprofileurl = JRoute::_('index.php?option=com_comprofiler&task=u serProfile&user='.$aup_clientid.'&Itemid='.$profil eitmeid);
    elseif($profileman==1)
    $clientprofileurl = JRoute::_('index.php?option=com_community&view=pro file&userid='.$aup_clientid.'&Itemid='.$profileite mid);
    // we get the first part of the sku from the file name which corresponds to the vendor userid
    $aup_exploded = explode(".",$aup_file_name);
    $aup_vendoruserid = $aup_exploded[0];
    // we get the shopper group of the customer to determine the price he paid the product
    // so we don't reward too much the vendor if the customer had a special price from his shoppergroup
    $q ="SELECT shopper_group_id FROM #__{vm}_shopper_vendor_xref WHERE user_id='$aup_clientid'";
    $db->query($q);
    $db->next_record();
    $aup_shoppergroup = $db->f("shopper_group_id");

    // Mia modifica
    $q ="SELECT order_total FROM #__{vm}_orders WHERE user_id=$aup_vendoruserid ORDER BY order_id DESC";
    $db->query($q);
    $db->next_record();
    $aup_cprice = $db->f("order_total");
    $aup_cprice= round($aup_cprice,2);
    $aup_topay = $aup_cprice * $paypcentage / 100 / $aupoint;


    ////////////// Payment via AUP API//////////////////////
    $informationdata = ''.$aup_file_name.' - Acquirente: '.$clientnaming.'';
    $referencekey = 'Download ID: '.$aup_download_id;
    $api_AUP = JPATH_SITE.DS.'components'.DS.'com_alphauserpoints '.DS.'helper.php';
    if ( file_exists($api_AUP))
    {
    require_once ($api_AUP);

    $aupid = AlphaUserPointsHelper::getAnyUserReferreID( $aup_vendoruserid );
    if ( $aupid ) AlphaUserPointsHelper::newpoints( 'plgaup_vm_payment2vendor', $aupid, $referencekey , $informationdata , $aup_topay );
    }
    // decrement the download_max to limit the number of downloads
    $q ="UPDATE `#__{vm}_product_download` SET";
    $q .=" `download_max`=`download_max` - 1";
    $q .=" WHERE download_id = '" .$download_id. "'";
    $db->query($q);
    $db->next_record();
    }
    if ($end_date=="0") {
    // Set the Download Expiry Date, so the download can expire after DOWNLOAD_EXPIRE seconds
    $end_date=time('u') + DOWNLOAD_EXPIRE;
    $q ="UPDATE #__{vm}_product_download SET";
    $q .=" end_date=$end_date";
    $q .=" WHERE download_id = '" . $download_id . "'";
    $db->query($q);
    $db->next_record();
    }

  6. #6
    Utente di HTML.it
    Registrato dal
    Nov 2011
    Messaggi
    8

    Scoperto l'errore

    Ho scoperto che la query č sintatticamente esatta e che l'errore č nella struttura logica del database, nel senso che il valore del risultato che sembrava casuale era invece dovuto alla struttura dei dati della tabella.
    Per ottenere il giusto risultato ho individuato un'altra strada che necessita solo una query su due tabelle in relazione tra loro con un campo.
    Pertanto, grazie veramente per l'aiuto che comunque mi ha indicato la giusta strada per la soluzione.
    Ciao.
    Piero.

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.