Deviant Logo

php/sql question: is the following possible to query a mysql database to echo who has the max totalmark?

post details top
Jun 8th, 2010
post details top


$sqlquery2 = “SELECT fname, surname, max(exam + project + participation) AS totalmark FROM details”;
$results2 = mysql_query($sqlquery2);

I can’t store totalmark as an extra column in the database which would make it alot easier.
mark – what would i put in column name:

if ( $results2["columnname"] > $max )
{
$max = $results["columnname"];
};

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

1 Comment

  • Marc

    It’s not really necessary to use all of the globals provided as you can make them with your own functions.

    first connect because you can’t query without a connect.
    you also need to select a database.

    < ?php
    $max = 0; set the checking variable

    $con = mysql_connect("host", "user", "pass");
    mysql_select_db("your databse", $con); select your database using the $con connection
    $query = "SELECT * FROM tablename"; get all the info so that you can compare.
    $information = mysql_query($query, $con); get the information

    while ( $results = mysql_fetch_assoc($information) ) this is where the information is retreived
    {

    if ( $results["columnName"] > $max )
    {
    $max = $results["columnName"];
    };

    };

    print $max;
    ?>

    done!

    See you don’t need to remember all the superglobals if you really understand the code!

    UPDATE: FOR THE COLUMN NAME MAKE IT ANYTHING YOU LIKE. I personally would name it totalNumber or max.

    It doesn’t matter as long as you are consistent.

Leave a Reply

Search

  • Partner links