To talk on Icrontic, just register!

It only takes 30 seconds.

Have an account? Sign in:

Forgot?
Enverex
~-+-~
Enverex
5,852 Posts

MySQL Code Failure

Could anyone tell me what is wrong with this code?

PHP Code:
<?
// Set Script Variables
$DB_Host="localhost";
$DB_Name="amigagames";
$Per_Page=10;
// Open MySQL Connection
$Connection=mysql_connect($DB_Host);
// Run The Query Without a Limit to get Total result
$SQL="SELECT COUNT(*) AS Total FROM 123 WHERE Name LIKE '%".$_REQUEST['k']."%'";
$SQL_Result=mysql_db_query($DB_Name$SQL);
$SQL_Result_Array=mysql_fetch_array($SQL_Result);
$Total=$SQL_Result_Array['Total'];
// Create a new SELECT Query with the ORDER BY clause and without the COUNT(*)
$SQL="SELECT * FROM 123 WHERE Name LIKE '%".$_REQUEST['k']."%' ORDER BY Name";
// Append a LIMIT clause to the SQL statement
if (empty($_GET['res']))
   {
   
$res=0;
   
$SQL.=" LIMIT $res, $Per_Page";
   }else
   {
   
$res=$_GET['res'];
   
$SQL.=" LIMIT $res, $Per_Page";
   }
// Run The Query With a Limit to get result
$SQL_Result=mysql_db_query($DB_Name$SQL);
$SQL_Rows=mysql_num_rows($SQL_Result);
// Display Results using a for loop
for ($a=0$a $SQL_Rows$a++)
    {
    
$SQL_Array=mysql_fetch_array($SQL_Result);
    
$Product=$SQL_Array['Name'];
    
$Description=$SQL_Array['Description'];
    echo 
"$Name - $Description<BR><BR>";
    }
// Create Next / Prev Links and $res Value
if ($Total>0)
   {
   if (
$res<$Total && $res>0)
      {
      
$Res1=$res-$Per_Page;
      echo 
"<A HREF=\"test.php?res=$Res1&k=".$_REQUEST['k']."\"><;<; Previous Page</A> ";
      }
   
// Calculate and Display Page # Links
   
$Pages=$Total $Per_Page;
   if (
$Pages>1)
      {
      for (
$b=0,$c=1$b $Pages$b++,$c++)
          {
          
$Res1=$Per_Page $b;
          echo 
"<A HREF=\"test.php?res=$Res1&k=".$_REQUEST['k']."\">$c</A> \n";
          }
      }
   if (
$res>=&& $res<$Total)
      {
      
$Res1=$res+$Per_Page;
      if (
$Res1<$Total)
         {
         echo 
" <A HREF=\"test.php?res=$Res1&k=".$_REQUEST['k']."\">Next Page >></A>";
         }
      }
   }
// Close Database Connection
mysql_close($Connection);
?>
As it just produces the error -

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\http\ac\amiga\test.php on line 11

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\http\ac\amiga\test.php on line 27
Cheers,
NS
__________________ RetroTracks - Classic Computer and Game Music
Enverex
~-+-~
Enverex
5,852 Posts
Figured it out myself, thanks for the erm... help.

NS
Go Back   Icrontic Forums > Tech: Software > Web & Digital Media
Jump to
This Thread Search this Thread
Search this Thread:

Advanced Search


Current time: 5:27am (GMT)
Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Get Vanilla instead. Trust me.