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
https://forums.phpfreaks.com/topic/94339-query-breaks-code-need-some-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.