MySQL Code Failure

EnverexEnverex Worcester, UK Icrontian
edited June 2003 in Internet & Media
Could anyone tell me what is wrong with this code?

[PHP]
<?
// 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."%'";
$SQL_Result=mysql_db_query($DB_Name, $SQL);
$SQL_Result_Array=mysql_fetch_array($SQL_Result);
$Total=$SQL_Result_Array;
// Create a new SELECT Query with the ORDER BY clause and without the COUNT(*)
$SQL="SELECT * FROM 123 WHERE Name LIKE '%".$_REQUEST."%' ORDER BY Name";
// Append a LIMIT clause to the SQL statement
if (empty($_GET))
{
$res=0;
$SQL.=" LIMIT $res, $Per_Page";
}else
{
$res=$_GET;
$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;
$Description=$SQL_Array;
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."\"><;<; 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."\">$c</A> \n";
}
}
if ($res>=0 && $res<$Total)
{
$Res1=$res+$Per_Page;
if ($Res1<$Total)
{
echo " <A HREF=\"test.php?res=$Res1&k=".$_REQUEST."\">Next Page >></A>";
}
}
}
// Close Database Connection
mysql_close($Connection);
?>
[/PHP]

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

Comments

  • EnverexEnverex Worcester, UK Icrontian
    edited June 2003
    Figured it out myself, thanks for the erm... help.

    NS
Sign In or Register to comment.