Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Return my SQL query back to my html page.

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #168884
    ben_foyster
    Participant

    Hey Guys,

    I was hoping you could help.

    I have wrote a query in php for a mysql database. Now the query works and outputs fine but it outputs to a new page. How to I get it to output to the html page with the form on it?

    Thanks

    Ben

    <?php
    

    // remove these style tags to remove the large font size
    echo ‘<style type=”text/css”> table {font-size: x-large} </style>’;

    // Accept a parameter called “BUILDING” from a form.
    $BUILDING = $_POST[‘BUILDING’];
    echo ‘

    Parameter value was: ‘.$BUILDING.’

    ‘;
    echo ‘<br/><br/>’;

    // Connect to the Oracle database
    require(‘x_connect.php’);

    // Specify SQL STATEMENT CONTAINING A BIND VARIABLE
    $query1 = ‘SELECT “FirstName”, “LastName”, “WorkPhone”
    From “tbl_Staff”
    INNER JOIN “tbl_Space”
    ON “tbl_Staff”.”OfficeID” = “tbl_Space”.”RoomNo”
    INNER JOIN “tbl_Buildings”
    ON “tbl_Space”.”BuildingID” = “tbl_Buildings”.”BuildingID”
    WHERE “tbl_Buildings”.”Name” = :BUILDING’;

    // Parse the query containing a bind variable.
    $stmt = oci_parse($conn, $query1);

    // Bind the value into the parsed statement.
    oci_bind_by_name($stmt, ‘:BUILDING’, $BUILDING);

    // Execute the completed statement.
    oci_execute($stmt);

    // Search for buidling name and building items then output building items
    echo “<table border=’1′ cellpadding=’5′>\n”;
    while ($row = oci_fetch_array($stmt, OCI_ASSOC+OCI_RETURN_NULLS)) {
    echo “<tr>\n”;
    foreach ($row as $item) {
    echo ” <td>” . ($item !== null ? htmlentities($item, ENT_QUOTES) : ” “) . “</td>\n”;
    }
    echo “</tr>\n”;
    }
    echo “</table>\n”;

    // Release the statement variable and close the connection
    oci_free_statement($stmt);
    oci_close($conn);

    // Show the SQL
    echo ‘

    SQL statement executed was: </br>’.$query1.’

    ‘;
    ?>

    #168888
    Alen
    Participant

    Wrap your code with the ` (the key above the tab on your keyboard). Or create a Gist on github.com. So we can see the code better.

    #168891
    __
    Participant

    How to I get it to output to the html page with the form on it?

    PHP cannot do that. PHP is long gone by the time your user fills out the form.

    You can use ajax to call your PHP script, and bring the output back to your current page. Various javascript libraries (like jQuery) have methods that make working with ajax easier.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Back End’ is closed to new topics and replies.