Jump to content

Query breaks code Need some help


devxtec

Recommended Posts

I just finished writing up a very basic script to read information from the database.

 

The following code is the original which works.

 

<?php
// This file relies on the parser file for its data.
// Setup Database Variables
$database = "####";
$server = "####";
$username = "####";
$password = "####";

// Update the database
exec('bash /srv/www/htdocs/patch_update/parser', $returnedval);
// echo $returnedval[0]; // Testing parser execution


// Connect to the db server
$connection = mysql_connect($server, $username, $password);
if (!$connection)
{
        die('Could not connect: ' . mysql_error());
        exit;
}

// Select the correct database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected)
{
        die ('Can\'t use customer : ' . mysql_error());
        exit;
}

// Check to see if form submission occured.
if(isset($submitted))
{

}
else
{
        $query = "SELECT nabp, date, patch FROM versions";
        $result = mysql_query($query);

        include "header.inc";
        while($row = mysql_fetch_assoc($result))
        {
                echo "\t\t<tr>\n";
                echo "\t\t\t<td>".$row["nabp"]."</td>\n";
                echo "\t\t\t<td>".$row["date"]."</td>\n";
                echo "\t\t\t<td>".$row["patch"]."</td>\n";
                echo "\t\t</tr>\n";
        }
        include "footer.inc";
}
?>

 

Now I want to change the way my data is outputted. So I changed my query from

 

SELECT nabp, date, patch FROM versions

 

to

 

SELECT nabp, date, patch FROM versions ORDER by nabp, DESC date

 

and it then displays this error.

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /srv/www/htdocs/patch_update/index.php on line 40

 

Line 40 is this

while($row = mysql_fetch_assoc($result))

 

 

Just FYI the script isn't complete yet as I still need to finish one IF statement but I can't do this until I get my query working again.

 

Any help would be greatly appreciated.

Link to comment
Share on other sites

DESC follows the col name

 

SELECT nabp, date, patch FROM versions ORDER by nabp, date DESC

 

Thanks for the quick reply. I totally didn't catch that I did that. Another pair of eyes always seems to help.

 

Thanks for the help. :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.