Visualizzazione dei risultati da 1 a 10 su 10
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2008
    Messaggi
    11

    [mysql php] selezionare valori mysql con php

    ciao a tutti ho uan tabella di questo tipo:
    bundle_id subproduct_id subproduct_qty referredto_id
    17 13 1 1
    17 1 1 1
    17 4 1 1
    16 4 1 1

    io in pratica devo selezionare tutti i valori in cui referredto_id sia uguale a una certa variabile (facciamo l'esempio qui di 1), però devono essere raggruppati per arrary relativamente a bundle_id. mi spiego meglio...per richiamarci all'esempio tutti i bundle_id = 17 devono essere messi nelle stesso array[0], quelli uguali a 16 nell'array[1], ecc...
    mi potete aiutare con il codice magari essendo cosi gentili da scriverlo? grazie mille!

  2. #2
    Utente di HTML.it L'avatar di oronze
    Registrato dal
    Jun 2001
    Messaggi
    3,543
    non ho tempo per scriverti il codice ma posso rimandarti qui:
    http://www.w3schools.com/sql/sql_groupby.asp

    No ai layout tabellari!

    Insulto libero: http://forum.html.it/forum/showthread.php?s=&postid=12524872#post12524872

  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2008
    Messaggi
    11
    ciao forse non sono riuscito a spiegarmi bene...io ho necessità che tutte le righe in cui bundle_id è uguale vengano mese nello stesso array (sarà quindi un array che conterrà altri array in ui array [0] -> ( array [0] (bundle_id=>17...) array [1] (bundle_id=>17...) ecc...) array [1] ( array [0] (bundle_id=>16...). il group by non va bene perchè fa un "riassunto"...prego chi mi sappia aiutare di essere cosi cortese da darmi una mano visto che questo fatot mi sta bloccando il lavoro. grazie!

  4. #4
    Nonostante la seconda spiegazione ancora nn riesco a capire che devi fare

  5. #5
    Utente di HTML.it
    Registrato dal
    Oct 2008
    Messaggi
    11
    in pratica devo fare in modo che tutti i record in cui bundle_id ha come valore ad esempio "x" siano messi nell'array [0], quelli che hanno come valore "y" siano messi nell'array [1], ecc...
    non va bene usare group by poichè restituisce solo un risultato, a me servono tutti...

  6. #6
    Utente di HTML.it L'avatar di oronze
    Registrato dal
    Jun 2001
    Messaggi
    3,543
    e se tu fai...
    Codice PHP:
    $query mysql_query("SELECT * FORM tabella");
    $array = Array();
    $arrayX = Array();
    $arrayY = Array();
    while(
    $r=mysql_fetch_assoc($query)){
    if (
    $r['bundle_id'] == numeroX$arrayX[] = $r;
    else if (
    $r['bundle_id'] == numeroY$arrayY[] = $r;
    }
    $array[0] = $arrayX;
    $array[1] = $arrayY

    No ai layout tabellari!

    Insulto libero: http://forum.html.it/forum/showthread.php?s=&postid=12524872#post12524872

  7. #7
    Utente di HTML.it
    Registrato dal
    Oct 2008
    Messaggi
    11
    si ma numeroX e numeroY non li conosco e non sono dei valori fissi, il senso è che tutte le righe in cui bundle_id ha lo stesso valore devono essere messe nello stesso array

  8. #8
    Fai que cicli uno dentro l'altro

    Tutti i record raggruppati per bundle_id
    array_bundle_id=array()
    Tutti i record con bundle_id del ciclo 1
    array_bundle_id=$id
    Fine secondo ciclo
    Fine primo ciclo

  9. #9
    Utente di HTML.it
    Registrato dal
    Oct 2008
    Messaggi
    11
    sto impazzendo, non riesco assolutamente a venrine a capo! allora il codice è questo:
    while ($bundle_data = tep_db_fetch_array($bundle_query)) {
    if ($bundle_data['products_bundle'] == "yes") {
    echo "
    » " . $bundle_data['subproduct_qty'] . " x " . $bundle_data['products_name'] . "";
    echo "
    » " . $bundle_data['products_name'] . "";
    $bundle_query_nested = tep_db_query("SELECT pd.products_name, pb.*, p.products_bundle, p.products_id, p.products_price FROM products p INNER JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON p.products_id=pd.products_id INNER JOIN " . TABLE_PRODUCTS_BUNDLES . " pb ON pb.subproduct_id=pd.products_id WHERE pb.bundle_id = " . $bundle_data['products_id'] . " and language_id = '" . (int)$languages_id . "'");
    while ($bundle_data_nested = tep_db_fetch_array($bundle_query_nested)) {
    echo "
    " . $bundle_data_nested['subproduct_qty'] . " x " . $bundle_data_nested['products_name'] . "";
    echo "
    " . $bundle_data_nested['products_name'] . "";
    $bundle_sum += $bundle_data_nested['products_price']*$bundle_data_nested['subproduct_qty'];
    }
    } else {
    echo "<tr><td class=main valign=top>" ;
    echo '' . tep_image(DIR_WS_IMAGES . $bundle_data['products_image'], $bundle_data['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="1" vspace="1"') . '' ;
    echo "</td><td class=main >&raquo; " . $bundle_data['subproduct_qty'] . " x " . $bundle_data['products_name'] . '</td><td align = right class=main>' . $currencies->display_price($bundle_data['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . "</td></tr>";
    $bundle_sum += $bundle_data['products_price']*$bundle_data['subproduct_qty'];
    }
    }



    e la query è questa...
    $bundle_query = tep_db_query(" SELECT pd.products_name, pb.*, p.products_bundle, p.products_id, p.products_price, p.products_image FROM products p INNER JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON p.products_id=pd.products_id INNER JOIN " . TABLE_PRODUCTS_BUNDLES . " pb ON pb.subproduct_id=pd.products_id WHERE pb.referredto_id = " . $HTTP_GET_VARS['products_id'] . " and language_id = '" . (int)$languages_id . "'");


    e la tabella quella che ho riportato nel primo intervento. Devo fare in modo che tutti i record con bundle_id uguale (ad esempio x) vengano inseriti nella stessa <table> in html, che quindi poi questa venga chiusa </table> e che se ne apra una nuova (con ad esempio i bundle_id uguali a y) e via dicendo...

  10. #10
    Utente di HTML.it
    Registrato dal
    Oct 2008
    Messaggi
    11
    up

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.