SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help in getting the value of one field to be used in mysql select query

    Hi,

    I need to get the process_id or process_name to select the reject type on the table reject_list. But I don't know how and is it possible that after I input the process_name I will get the value then it will be use in my select query to get the reject list.

    PHP Code:
    <?php
      session_start
    ();
      
    ob_start();
      
    date_default_timezone_set("Asia/Singapore");
      
    error_reporting(0);  
      include(
    'connection.php');
      
     
    //----QUERY FOR REJECT TYPE---//

    if(isset($_SESSION['process_name']) != '')
    {
        
        
    $process_id $_SESSION['process_id'];
        
    $sql_reject = ("SELECT reject_process_id, reject_acro FROM reject_list WHERE reject_process_id = '$process_id'");

    echo 
    $sql_reject;
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <title>Operator's Shift Report </title>
    <head>
    <link rel="stylesheet" type="text/css" href="op_report.css" />
    <link rel="stylesheet" type="text/css" href="calendar.css" />

    <script type="text/javascript" src="jquery.js"></script>
    <script type='text/javascript' src='jquery.autocomplete.js'></script>
    <link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />

    <script type="text/javascript">
    //----auto complete process name---//
    $().ready(function() {
        $("#process_name").autocomplete("get_process_list.php", {
           width: 205,
            matchContains: true,
            mustMatch: true,
            selectFirst: false
        });
        
        $("#process_name").result(function(event, data, formatted) {
            $("#process_id").val(data[1]);
        });
        
    });


    </script>
    </head>
    <body onload=document.getElementById("process_name").focus();>
    <form>
    <script type="text/javascript" src="calendar.js"> </script> 
    <div id="operators_report">
    <fieldset>
    <legend><h1>Operator's Shift Report</h1></legend>
    <table>
    <tr>
    <td>Process/td>
    <td><input type="text" name="process_name" id="process_name" value="" size="30"></td>
    <td>Supervisor/td>
    <td><input type="text" name="supervisor" id="supervisor" value="" size="30"></td>
    </tr>

    </table>
    </fieldset>
    </div>
    <input type="hidden" name="process_id" id="process_id" value="" />
    <input type="hidden" name="spv_id" id="spv_id" value="" />
    </form>
    </body>
    </html>
    Any help is highly appreciated.

    Thank you.
    Last edited by SpacePhoenix; Jul 2, 2013 at 00:44. Reason: placed php tags around php code

  2. #2
    SitePoint Addict bronze trophy vectorialpx's Avatar
    Join Date
    Dec 2012
    Location
    Bucharest
    Posts
    247
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    I think we need more details.

    1. What's with the $_SESSION['process_name']. When is it set?
    You have if(isset($_SESSION['process_name']) != '') and use $_SESSION['process_id']

    2. What do you mean by:
    after I input the process_name I will get the value then it will be use in my select query
    The autocomplete must work independently, get values from your "get_process_list.php".
    The input will work as a simple GET request (I can see that you have no method for your form).

    Now, I guess you want the autocomplete to return the name AND id so you can populate the #process_id.
    After you hit the submit you'll need to use $_REQUEST['process_id'] and not $_SESSION (??)

    However, I never used ".result" so I'd recommend to use
    Code:
        $("#process_name").autocomplete("get_process_list.php", {
           width: 205,
            matchContains: true,
            mustMatch: true,
            selectFirst: false,
            select: function(e, ui) {
                 $("#process_id").val(ui.item.id); // or ui.item.value
                 alert('debug: '+ui.item.id); // just for debug
            }
        });
    Also, make a dubug with your console or with some alerts to check values.

  3. #3
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you... I will try it later..

    I encountered problem in jquery:

    '1' is null or not an object if the field process_name has no value or the letter that I've type has no match in the database.

    Thank you

  4. #4
    SitePoint Addict bronze trophy vectorialpx's Avatar
    Join Date
    Dec 2012
    Location
    Bucharest
    Posts
    247
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by newphpcoder View Post
    I encountered problem in jquery:
    '1' is null or not an object if the field process_name has no value or the letter that I've type has no match in the database.
    Check the autocomplete structure - http://jqueryui.com/autocomplete/#remote
    For your autocomplete file:
    PHP Code:
    <?php

    // ...

    $SqlResult getFromSql( ... );
    /*
    // in the end $SqlResult should look like this
    $SqlResult = array(
        array( 'id' => 1, 'label' => 'lbl 1', 'value' => 'val1' ),
        // ....
        array( 'id' => 23, 'label' => 'lbl 23', 'value' => 'val23' ),
    );
    */
    echo json_encode($SqlResult);
    // ...

    ?>

  5. #5
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Hi newphpcoder,

    What autocomplete plugin are you using (could you post the URL)? It doesn't look like the jQuery UI one.

  6. #6
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I resolved my problem by this code:

    PHP Code:
    <?php
    ob_start
    ();
    include 
    "connection.php";
    $q strtolower($_GET["q"]);

    if (
    $q == '') {
       
    header("HTTP/1.0 404 Not Found"true404);   
    }

    //else (!$q) return;
    else{
    $sql "select process_id, process_name from process_list where process_name LIKE '$q%'";
    $rsd mysql_query($sql);

    $cnt mysql_num_rows($rsd);

        if(
    $cnt 0)
        {
            while(
    $rs mysql_fetch_array($rsd)) {
                
    $pid $rs['process_id'];
                
    $pname $rs['process_name'];
                echo 
    "$pname|$pid\n";
            }
            }
        else
        {
         
    header("HTTP/1.0 404 Not Found"true404);   
        }
    }

    ?>
    Thank you

  7. #7
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fretburner View Post
    Hi newphpcoder,

    What autocomplete plugin are you using (could you post the URL)? It doesn't look like the jQuery UI one.
    Hi,

    I tried to search it to google again, but I can find the exact website that I saw before. yah it does not like the jQueryUI.


    Thank you

  8. #8
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vectorialpx View Post
    I think we need more details.

    1. What's with the $_SESSION['process_name']. When is it set?
    You have if(isset($_SESSION['process_name']) != '') and use $_SESSION['process_id']

    2. What do you mean by:

    The autocomplete must work independently, get values from your "get_process_list.php".
    The input will work as a simple GET request (I can see that you have no method for your form).

    Now, I guess you want the autocomplete to return the name AND id so you can populate the #process_id.
    After you hit the submit you'll need to use $_REQUEST['process_id'] and not $_SESSION (??)

    However, I never used ".result" so I'd recommend to use
    Code:
        $("#process_name").autocomplete("get_process_list.php", {
           width: 205,
            matchContains: true,
            mustMatch: true,
            selectFirst: false,
            select: function(e, ui) {
                 $("#process_id").val(ui.item.id); // or ui.item.value
                 alert('debug: '+ui.item.id); // just for debug
            }
        });
    Also, make a dubug with your console or with some alerts to check values.
    1. In my process_name i use autocomplete to ge the process_name and process_id, by that I want to get the value if process_id so I can used in my query to get all reject_type for the process_id.
    I have no idea what syntax should I used to get all the reject type based on process_id.

    Thank you so much.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •