LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How do I output the result of a query in php? (https://www.linuxquestions.org/questions/programming-9/how-do-i-output-the-result-of-a-query-in-php-570760/)

orfiyus 07-19-2007 02:33 PM

How do I output the result of a query in php?
 
Hey

I have an input form that a user types text into. This input then gets stored in a variable and then various php functions are called to query the db to see if the input exists in it. Anyway I am trying to see if this is working correctly so I decided to output the result of the query to the screen to make sure it is working. However I can not understand how to do this. I am working with a similar example that does this but it is just a straight query that relies on other variables that are defined through the code. If someone can give me any help I would appreciate it.

Here are the code pieces I am working with. The first one is what works and I am trying to model the second one after it. I have put a comment on where I get confused in the second piece of code.

Thanks

Code:

//query
$query = "select strike,opn_int from surfaces where undl_indx = $undl_indx and expire_date = ".$_SESSION['opt_exd_vals'][$opt_indx]." and call_put = '".$_SESSION['opt_cp_vals'][$opt_indx]."'";
$parsed = ociparse($db_conn, $query);
$succ = ociexecute($parsed);
        if ($succ){
                $nrows = ocifetchstatement($parsed, $rset);
                //prints results of array to the screen
                for ($indx = 0; $indx < $nrows; $indx++){
                        $strike = $rset['STRIKE'][$indx];
                        $open_int = $rset['OPN_INT'][$indx];
                        $selected = ($strike == $_SESSION['opt_strk_vals'][$opt_indx])?"selected":"";
                        echo("<option value=$strike $selected>$strike</option>\n");
                        //echo("open interest is $open_int ");
                        if ($open_int < 0)
                                echo " (inserted)";
                        else
                                echo " ";
                       
                }
        }

Here is what I put

Code:

//text field
echo("<input type=text name=opt_qty value=".$_SESSION['opt_qty_vals'][$opt_indx]." onBlur='submit();' class='qty_input'>");
echo("</td>");
//store user input
$user_input_strike = $_SESSION['opt_qty_vals'][$opt_indx];
$query1 = "select strike from surfaces where undl_indx = $undl_indx and and expire_date = ".$_SESSION['opt_exd_vals'][$opt_indx]." and call_put = '".$_SESSION['opt_cp_vals'][$opt_indx]." and strike = $user_input_strike";
$parsed1 = ociparse($db_conn, $query1);
$succ1 = ociexecute($parsed);
        if ($succ1)
        {
                $nrows = ocifetchstatement($parsed1, $rset);
                for ($indx = 0; $indx < $nrows; $indx++) {
                        $user_input_result = $rset['STRIKE'][$indx];
                        //this is the part where I get confused. I dont understand how to define this properly.
                        $selected = ($user_input_result == $_SESSION['opt_qty_vals'][$opt_indx])?"selected":"";
                        echo(<"option value = $user_input_result $selected>$user_input_result</option>\n");
                }
        }



All times are GMT -5. The time now is 12:42 PM.