Pages

Thursday, March 6, 2014

How to Display MySQL Data With PHP

PHP can pull information from a MySQL database by linking to the database, setting a query and performing a PHP operation. The query can be anything that updates, amends or selects data from the database. Output of the information can then be placed on a Web page, or output as a PHP dialogue or JavaScript function. The most common method is to output data to a Web page using HTML, but occasionally other display outputs are used.

Instructions

    1

    Perform a query by connecting to the database, calling the query and then checking the result. The following is an example script utilizing an HTML form:

    form name="invoice_form" method="POST" action="Invoices.php" class="formcss">

    $invoutput";

    Data in a table:

    echo "";

    echo "$invoutput";

    Via a JavaScript dialogue box:

    echo "";

    3

    Display MySQL data with echo and printf. The following examples demonstrate how echo and printf are used to display information.

    echo:

    echo "Invoice number is $invoutput\n";

    printf:

    printf allows more options in terms of formatting the numbers, but this example shows a simple case:

    printf("Invoice number is %d\n",$invoutput);

0 comments:

Post a Comment