hi guys!
I got a problem when I want to display the array from the database and rank it. can someone fixed this problem:-

<?php
session_start();
include "mysql.php";
// you have already opened your db connection

$report_status = isset($_REQUEST['reportTotal']) ? $_REQUEST['reportTotal'] :"";

//$query = mysql_query("SELECT * FROM `supplier_report` "
//. "WHERE `report_value` = '" . $_SESSION['reportTotal'] ."'";
     $q= "select * from supplier_report where report_value='" .$_SESSION['reportTotal']."'" "order by report_value desc";
$result=mysql_query($q) or die(mysql_error());
$rank = 0;
$points = 0;
$rankIncrement = 1;
while ($user=mysql_fetch_array($result))
{
    if ($user['report_value'] == $points)
    {
        $rankIncrement;
    }
    else
    {
        $rank += $rankIncrement;
        $rankIncrement = 1;
    }

    echo "$rank";
	echo "<br>{$user['report_value']}</br>";
 
}
mysql_close();
?>

I got the error message which is:-
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Array order by report_value desc' at line 1.

is it because I used array? but I notice this problem when I put the session. can someone give me the right syntax include the session?

Recommended Answers

All 2 Replies

$q= "select * from supplier_report where report_value='" .$_SESSION['reportTotal']."'" "order by report_value desc";

Why do you have " " after the value?

This should be:

$q= "select * from supplier_report where report_value='" .$_SESSION['reportTotal']."' order by report_value desc";

oh! yes..
sorry about that. that's after i'm tried to fix the problem.
I run the syntax that u gave it to me.
Now, there is nothing displayed in the screen.
is it my coding error in anywhere?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.