SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    cheshire
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php displays in the browser in the wrong order

    Hi
    I have two queries in a script. Both work OK and their output is
    diplayed in tables in the browser. However, it comes out in an order
    I wasn't expecting. I would like it like this:

    statement 1
    table 1
    statement 2
    table 2
    link

    instead I get...
    statement 1
    statement 2
    table 1
    link
    table 2

    It looks bad like this as you can imagine

    the last bit of the script is below:
    PHP Code:
     // Request the scores for id=$userid from the testscores table
     
    $Query "SELECT testname, testscore FROM $TableName WHERE id='$userid'";
     
    $result mysql_query($Query); 
     if (!
    $result) {
     echo(
    "<P>Error performing query: " .
     
    mysql_error() . "</P>");
     exit();
     }

    //Request the max score, min score and average score from testscores table
    $query2="SELECT testname, MAX(testscore) AS maxScore, MIN(testscore) AS minScore, AVG(testscore) AS averageScore FROM $TableName WHERE class='10B' GROUP BY testname";
    $result2=mysql_query($query2) or die ("Can not execute query:" mysql_error());

     
    // Display the test name and test score if the form has not been submitted
    if ("SUBMIT"!==$addscore){
    print (
    "<P> Here are all your scores in our database: </P>\n");
    // Create a table.
    print ("<TABLE BORDER=1 WIDTH=\"75%\" CELLSPACING=2 CELLPADDING=2 ALIGN=CENTER>\n");
    print (
    "<TR ALIGN=CENTER VALIGN=TOP>\n");
    print (
    "<TD ALIGN=CENTER VALIGN=TOP>Test Name</TD>\n");
    print (
    "<TD ALIGN=CENTER VALIGN=TOP>Test Score</TD>\n");
    print (
    "</TR>\n");
    //Fetch the results from the database.
     
    while ( $row mysql_fetch_array($result) ) {
    print (
    "<TR ALIGN=CENTER VALIGN=TOP>\n");
    print (
    "<TD ALIGN=CENTER VALIGN=TOP>" $row[testname] . "</TD>\n");
    print (
    "<TD ALIGN=CENTER VALIGN=TOP>" $row[testscore] . "</TD>\n");
    print (
    "</TR>\n");
     }
    }

     
    // Display the class max, min and avg for each test if the form has not been submitted
    if ("SUBMIT"!==$addscore){
    print (
    "<P> Here are the max, min and avg scores for class 10B  </P>\n");
    // Create a table.
    print ("<TABLE BORDER=1 WIDTH=\"75%\" CELLSPACING=2 CELLPADDING=2 ALIGN=CENTER>\n");
    print (
    "<TR ALIGN=CENTER VALIGN=TOP>\n");
    print (
    "<TD ALIGN=CENTER VALIGN=TOP>Test Name</TD>\n");
    print (
    "<TD ALIGN=CENTER VALIGN=TOP>Max Score</TD>\n");
    print (
    "<TD ALIGN=CENTER VALIGN=TOP>Min Score</TD>\n");
    print (
    "<TD ALIGN=CENTER VALIGN=TOP>Avg Score</TD>\n");
    print (
    "</TR>\n");
    //Fetch the results from the database.
     
    while ( $row2 mysql_fetch_array($result2) ) {
    print (
    "<TR ALIGN=CENTER VALIGN=TOP>\n");
    print (
    "<TD ALIGN=CENTER VALIGN=TOP>" $row2[testname] . "</TD>\n");
    print (
    "<TD ALIGN=CENTER VALIGN=TOP>" $row2[maxScore] . "</TD>\n");
    print (
    "<TD ALIGN=CENTER VALIGN=TOP>" $row2[minScore] . "</TD>\n");
    printf ("<TD ALIGN=CENTER VALIGN=TOP>%01.1f"$row2[averageScore]); print ("</TD>\n");
    print (
    "</TR>\n");
     }
    }


    // When clicked, this link will load this page
     // with the score submission form displayed.
    $UserName=urlencode($UserName);
    $logondetails=urlencode($logondetails);
     echo(
    "<P><A HREF='$PHP_SELF?addscore=1&UserName=$UserName&logondetails=$logondetails'>" .
     
    "Add a Test Score!</A></P>");
     

    mysql_close($link);
    ?> 
    </body>
    </html>

  2. #2
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, what to statement 1,2 etc relate to in the code?
    same thing for table 1,2.
    kinda hard to help ya w/o knowing exactly what it is/isn't doing.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*


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
  •