Visualizzazione dei risultati da 1 a 10 su 10

Discussione: aggiungere valore

  1. #1

    aggiungere valore

    Salve a tutti,

    devo aggiungere un secondo valore a questo script per inoltrare oltre al valore letterale della sottocategoria anche un valore numerico per fare un confronto in una Select su mysql.

    Codice PHP:
    <?php
    $cat_id
    =$_GET['cat_id'];
    require 
    "config.php";
    $q=mysql_query("select * from hsubcat_it where idcat='$cat_id'");
    echo 
    mysql_error();
    $myarray=array();

    $str="";

    while(
    $nt=mysql_fetch_array($q)){
    $str=$str "\"$nt[subcategoria]\"".",";
    // dovrei riuscire a passare il seguente valore . "\"$nt[objectID]\"".",";
    }
    $str=substr($str,0,(strLen($str)-1)); // Removing the last char , from the string

    echo "new Array($str)";


    //

    ?>

    grazie mille per eventualil suggerimenti.

  2. #2
    Utente di HTML.it L'avatar di Luke70
    Registrato dal
    Jul 1999
    Messaggi
    767
    in che senso devi "aggiungere" un secondo valore?
    Devi leggere un altro $_GET?
    Devi inserire un secondo confronto nella query?
    Devi "stampare" un altro valore?

  3. #3
    attualmente passo il valore subcategoria che visualizza nel menu il nome della sottocategoria. Però devo inserire un secondo confronto per la query ...

  4. #4
    Se aggiungo un valore nt nel menu a tendina mi stampa sia la sottocategoria (subcategoria) che il numero del campo associato (objectID)... io invece devo avere la stampa della sottocategoria e inviare il valore numerico per effettuare la query di confronto...

    Codice PHP:
    <?php
    $cat_id
    =$_GET['cat_id'];
    require 
    "config.php";
    $q=mysql_query("select * from hsubcat_it where idcat='$cat_id'");
    echo 
    mysql_error();
    $myarray=array();

    $str="";

    while(
    $nt=mysql_fetch_array($q)){
    //$str=$str . "\"$nt[subcategoria]\"".",";
    $str=$str "\"$nt[objectID]\"".","."\"$nt[subcategoria]\"".",";
    }
    $str=substr($str,0,(strLen($str)-1)); // Removing the last char , from the string

    echo "new Array($str)";


    //

    ?>

  5. #5
    Utente di HTML.it L'avatar di Luke70
    Registrato dal
    Jul 1999
    Messaggi
    767
    non vedo da nessuna parte una select con le sue option

    Se provi a scriverle basta assegnare
    '<option value="'.$nt[objectID].'">'.$nt[subcategoria].'</option>'

  6. #6
    right!

    la select è in un altro file...

    Codice PHP:
    <script type="text/javascript">
    function AjaxFunction(cat_id)
    {
    var httpxml;
    try
      {
      // Firefox, Opera 8.0+, Safari
      httpxml=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
              try
                            {
                        httpxml=new ActiveXObject("Msxml2.XMLHTTP");
                        }
                  catch (e)
                        {
                    try
                  {
                  httpxml=new ActiveXObject("Microsoft.XMLHTTP");
                  }
                    catch (e)
                  {
                  alert("Your browser does not support AJAX!");
                  return false;
                  }
                }
      }
    function stateck() 
        {
        if(httpxml.readyState==4)
          {

    var myarray=eval(httpxml.responseText);
    // Before adding new we must remove previously loaded elements
    for(j=document.testform.subcat.options.length-1;j>=0;j--)
    {
    document.testform.subcat.remove(j);
    }


    for (i=0;i<myarray.length;i++)
    {
    var optn = document.createElement("OPTION");
    optn.text = myarray[i];
    //optn.value = myarray[i];
    document.testform.subcat.options.add(optn);



          }
        }
        var url="dd.php";
    url=url+"?cat_id="+cat_id;
    url=url+"&sid="+Math.random();
    httpxml.onreadystatechange=stateck;
    httpxml.open("GET",url,true);
    httpxml.send(null);
      }
    </script>

    <form name="testform" method='POST' action='mainck.php'>

    Categoria 
      <select name=cat onChange="AjaxFunction(this.value);">
    <option value=''><-- Seleziona --></option>
    <?php
    require "config.php";// connection to database 
    $q=mysql_query("select * from hcat_it ");
    while(
    $n=mysql_fetch_array($q)){
    echo 
    "<option value=$n[idcat]>$n[categoria]</option>";
    }
    }
    ?>
    </select>

    <select name=subcat>

    </select>
    <input name=ID type=hidden value=ID /><input type=submit value=CERCA>
    </form>

  7. #7
    Ho provato ma sapevo già che avrebbe funzionato a inserire il doppio valore in questo modo...

    Codice PHP:

    <?php
    $cat_id
    =$_GET['cat_id'];
    require 
    "config.php";
    $q=mysql_query("select * from hsubcat_it where idcat='$cat_id'");
    echo 
    mysql_error();
    $myarray=array();

    $str="";

    while(
    $nt=mysql_fetch_array($q)){
    //$str=$str . "\"$nt[subcategoria]\"".",";
    //$str=$str . "\"$nt[objectID]\"".",";
    $str=$str "<option value=$nt[objectID]>$nt[subcategoria]</option>".",";
    }
    $str=substr($str,0,(strLen($str)-1)); // Removing the last char , from the string
    echo "new Array($str)";


    //

    ?>
    ma niente da fare...

  8. #8
    esiste una soluzione per concatenare $nt[subcategoria] . $nt[objectID] facendo in modo però che venga stampato subcategoria nel menu select?


  9. #9
    neanche così riesco ad assegnare un valore option alla select subcategoria ...

    Codice PHP:
    <?php
    $cat_id
    =$_GET['cat_id'];

    require 
    "config.php";
    $q=mysql_query("select * from hsubcat_it where idcat='$cat_id'");
    echo 
    mysql_error();
    $myarray=array();


    $str="";

    while(
    $nt=mysql_fetch_array($q)){
    //$str2=$str2 . "\"$nt[subcategoria]\"".",";
    //$str=$str . "\"$nt[objectID]\"".",";

    //$str=$str . "<option value=$nt[objectID]>$nt[subcategoria]</option>".",";
    $str=$str ."\"<option value='.$nt[objectID].'>'.$nt[subcategoria].'</option>".",";
    }
    $str=substr($str,0,(strLen($str)-1)); // Removing the last char , from the string

    echo "new Array($str)";



    //

    ?>

  10. #10
    Continuo con i miei esperimenti...

    in questo modo funziona a metà... perché nel menu select mi stampa in successione sia il valore subcategoria che quello objectID invece io vorrei che il valore objectID fosse nascosto all'utente...


    Codice PHP:

    <?php
    $cat_id
    =$_GET['cat_id'];

    require 
    "config.php";
    $q=mysql_query("select * from hsubcat_it where idcat='$cat_id'");
    echo 
    mysql_error();
    $myarray=array();


    $str="";

    while(
    $nt=mysql_fetch_array($q)){
    //$str2=$str2 . "\"$nt[subcategoria]\"".",";
    $str=$str "\"$nt[subcategoria]\"".","."\"$nt[objectID]\"".",";

    //$str=$str . "<option value=$nt[objectID]>$nt[subcategoria]</option>".",";
    //$str=$str ."\"<option value='.$nt[objectID].'>'.$nt[subcategoria].'</option>".",";
    }
    $str=substr($str,0,(strLen($str)-1)); // Removing the last char , from the string

    echo "new Array($str)";



    //

    ?>

    qualcuno che mi illumina?

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.