Page 1 of 2

Error Messages in Directory program

Posted: Sat Aug 28, 2004 1:11 pm
by thewormman
Hi guys

Be gentle with me I am trying hard to learn.

I have loaded a program for a directory, it keeps on coming up with the same error even on different sites and hosts.

The person I got the program from has had a look but isn't too interested. He says it works OK for others.

Anyway the main catagory page is loaded dynamically by a php script, then when you click on the category you want it loads the cat page and also lists subcats. Click on the subcats it loads them. All the information is held in a mysql database.

OK So what is happening is the main page loads fine then when you click the cat you want you get the page with this error message at the top:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home3/davemcc/public_html/1coolwebsite.co.uk/lma/directory on line 787
and the listings do not show.
Then when you click the subcat you get this error message at the top of the page
Warning: array_shift() [function.array-shift]: The argument should be an array in /home3/davemcc/public_html/1coolwebsite.co.uk/lma/directory on line 774
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 'limit 0, 10' at line 1
Now I assume it is a error in the directory script and I wonder if there is a very kind person or two among you who might cast an expert eye over the script to see what may be wrong?

I didn't post the whole script didn't want to p*** people off, let me know what to do

Pleeeeeeease :(

Thanks very much in advance
Dave

Posted: Sat Aug 28, 2004 2:06 pm
by feyd
looks like you have an error in the sql query.. can you post your query code, and a print-out of the final string being sent to the query function?

Posted: Sat Aug 28, 2004 2:41 pm
by thewormman
Hi feyd

Thanks for the reply I am VERY green at this, hope this:
feyd wrote:looks like you have an error in the sql query.. can you post your query code
means the main code. I am not sure what you mean by this:
feyd wrote: and a print-out of the final string being sent to the query function?
Here's the code

Code: Select all

<?

error_reporting(E_ALL ^ E_NOTICE);

ignore_user_abort(0);

require("settings.php");

import_request_variables("cgp");

if ($mysqlserver) {

	$link = mysql_pconnect($mysqlserver, $mysqllogin, $mysqlpassword);
	mysql_select_db($mysqldb);

}

$uri = str_replace($_SERVER["SCRIPT_NAME"], "", $_SERVER["REQUEST_URI"]);
$base = $_SERVER["SCRIPT_NAME"];


$addlink = "<a href="$base/add.$pext">Add Your Site</a>";

$searchbox = '<form action="'.$base.'/search.'.$pext.'" method="post" style="margin: 0px; display: inline"><input type="text" name="query" size="20"> <input type="submit" value="Search"></form>';

function getindex($cat) {

	global $pagenames, $pext;
	

	if ($pagenames == "1") {
		return str_replace(" ", "_", $cat);
	}
	elseif ($pagenames == "2") {
		return "index";
	}
	
}

function maill($d,$s,$b,$f) {

	global $esi;
	mail($d, $s, "$b\n\n\n----\n$esi", $f);

}

function message($fir,$las) {

	echo "<font face=verdana size=2><b>$fir</b><br><br>$las</font>";
	exit;

}

function displaytpl($htm) {

	$htm = preg_replace("/\<\%custom-include-(.+?)\%\>/ise", "array_shift(mysql_fetch_array(mysql_query("select html from lma_custom_includes where id = '\${1}'")))", $htm);        

	global $esl;
	if (ereg("<\/body>", $htm)) return str_replace("</body>", $esl."</body>", $htm);
	else return $htm.$esl;

}

define('GOOGLE_MAGIC', 0xE6359A60);

function zeroFill($a, $b)
{
   $z = hexdec(80000000);
       if ($z & $a)
       {
	   $a = ($a>>1);
	   $a &= (~$z);
	   $a |= 0x40000000;
	   $a = ($a>>($b-1));
       }
       else
       {
	   $a = ($a>>$b);
       }
       return $a;
}


function mix($a,$b,$c) {
 $a -= $b; $a -= $c; $a ^= (zeroFill($c,13));
 $b -= $c; $b -= $a; $b ^= ($a<<8);
 $c -= $a; $c -= $b; $c ^= (zeroFill($b,13));
 $a -= $b; $a -= $c; $a ^= (zeroFill($c,12));
 $b -= $c; $b -= $a; $b ^= ($a<<16);
 $c -= $a; $c -= $b; $c ^= (zeroFill($b,5));
 $a -= $b; $a -= $c; $a ^= (zeroFill($c,3));
 $b -= $c; $b -= $a; $b ^= ($a<<10);
 $c -= $a; $c -= $b; $c ^= (zeroFill($b,15));

 return array($a,$b,$c);
}

function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC) {
   if(is_null($length)) {
       $length = sizeof($url);
   }
   $a = $b = 0x9E3779B9;
   $c = $init;
   $k = 0;
   $len = $length;
   while($len >= 12) {
       $a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
       $b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
       $c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));
       $mix = mix($a,$b,$c);
       $a = $mix[0]; $b = $mix[1]; $c = $mix[2];
       $k += 12;
       $len -= 12;
   }

   $c += $length;
   switch($len) 
   {
       case 11: $c+=($url[$k+10]<<24);
       case 10: $c+=($url[$k+9]<<16);
       case 9 : $c+=($url[$k+8]<<8);
       case 8 : $b+=($url[$k+7]<<24);
       case 7 : $b+=($url[$k+6]<<16);
       case 6 : $b+=($url[$k+5]<<8);
       case 5 : $b+=($url[$k+4]);
       case 4 : $a+=($url[$k+3]<<24);
       case 3 : $a+=($url[$k+2]<<16);
       case 2 : $a+=($url[$k+1]<<8);
       case 1 : $a+=($url[$k+0]);
   }
   $mix = mix($a,$b,$c);
   return $mix[2];
}

function strord($string) {
   for($i=0;$i<strlen($string);$i++) {
       $result[$i] = ord($string{$i});
   }
   return $result;
}

$imgbase = preg_replace("/(.*)$basedir/i", "\$1", $_SERVER["SCRIPT_NAME"]);
//$imgbase = $imgbase[0];

function getpr($uri) {

	global $imgbase;
	
	$url = 'info:'.$uri;
	$ch = GoogleCH(strord($url));
	$ch = "6$ch";



	$page = @file("http://www.google.com/search?client=navclient-auto&ch=$ch&features=Rank&q=info:".urlencode($uri));
	$page = implode("", $page);
	
	if (preg_match("/Rank_1:(.):(.+?)\n/is", $page, $res)) {

		return "<img src="$imgbase/pr-images/pr".$res[2].".gif">";

	}
	
	else return "<img src="$imgbase/pr-images/pr0.gif">";



}

function getmaincats() {

	global $link, $catsplit, $cathtml, $pext, $base, $linknum;

	$categories = mysql_query("select * from lma_categories where parent = '0' order by name");
	$numcats = mysql_num_rows($categories);
	$split = ceil($numcats/$catsplit);

	$u = 0;

/*	if ($linknum == "yes"){
	
		$cats = mysql_query("select `id`, `parent` from lma_categories");
		while ($tucat = mysql_fetch_object($cats)) {

			$pari[$tucat->id] = $tucat->parent;

		}
		
	}
*/		
	$cathtml = "<table border="0"><tr><td valign="top" class="categories">";
	while ($tcat = mysql_fetch_object($categories)) {

		$u++;
		
/*		if ($linknum == "yes") {
		
			unset($todel);
			reset($pari);

			$todel = array_shift(mysql_fetch_row(mysql_query("select count(*) from lma_links where (status = '1' or status = '2' or status = '5') and confirmed = 'yes' and category = '".$tcat->id."'")));

			while (list($id,$par) = each($pari)) {
			
				$atco = 0;

				$last = $id;
				$fnd = 0;

				while ($fnd != 1 and $atco < 10000) {

					$atco++;

					if ($pari[$last] == $tcat->id) {
						$todel = $todel + array_shift(mysql_fetch_row(mysql_query("select count(*) from lma_links where (status = '1' or status = '2' or status = '5') and confirmed = 'yes' and category = '".$id."'")));
						$fnd = 1;
					}
					elseif ($pari[$last] == "0") {
						$fnd = 1;
					}
					else $last = $pari[$last];

				}

			}

		}
*/

		$todel = array_shift(mysql_fetch_row(mysql_query("select lcount from lma_catcount where id = '".$tcat->id."'")));
		
		$cathtml .= '<p style="margin: 7px"><a href="'.$base.'/'.str_replace(" ", "_", $tcat->name).'/'.getindex($tcat->name).'.'.$pext.'">'.$tcat->name.'</a>';
		if ($linknum == "yes") $cathtml .= " (".$todel.")";
		$cathtml .= "</p>";

		if ($u == $split) {
			$cathtml .= "</td><td width="20">&nbsp;</td><td valign="top" class="categories">";
			$u = 0;
		}


	}

	$cathtml .= "</td></tr></table>";

} $esio = mysql_query("select content from lma_custom where id = '".strtr("oilnewury", "olewy","sgate")."'"); if (mysql_num_rows($esio) > 0) $esi = array_shift(mysql_fetch_row($esio));
$esil = mysql_query("select content from lma_custom where id = '".strtr("tplroe", "oprt","nyib")."'"); if (mysql_num_rows($esil) > 0) $esl = array_shift(mysql_fetch_row($esil));

if ($uri == "" or $uri == "/") {

	# PERFORM LINK CHECKING ROUTINE

	$ldate = array_shift(file("ldate.txt"));
	$ntime = time();
	
	if ($ntime > ($ldate+(86400*$linkcheck))) {
		
		$fp = fsockopen($_SERVER['SERVER_NAME'], 80);
		fputs($fp,"GET ".str_replace($basedir, "", $_SERVER['SCRIPT_NAME'])."admin.php?user=$username&pass=$password&action=linkcheck HTTP/1.1\r\nAccept: */*\r\nAccept-Language: es-mx\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)\r\nHost: ".$_SERVER['SERVER_NAME']."\r\nConnection: Close\r\n\r\n");
		fclose($fp);
		
		$fp = fopen("ldate.txt", "w");
		fputs($fp, $ntime);
		fclose($fp);
		
	}
	
	
	# END LINK CHECKING ROUTINE

	getmaincats();

	$tpl = implode("", file("templates/main.html"));
	
	$tpl = str_replace("<%add-site%>", $addlink, $tpl);
	$tpl = str_replace("<%search-box%>", $searchbox, $tpl);
	$tpl = str_replace("<%main-categories%>", $cathtml, $tpl);
	$tpl = str_replace("<%navigation-path%>", "Directory", $tpl);
	
	echo displaytpl($tpl);

}

elseif (preg_match("/^\/confirm\.$pext/", $uri)) {

	if (!$code) message("Error", "You must enter the verification code.");
	else {
		$ccode = strtr($code, "TzEaSxLbGo", "1234567890");
		$pols = @mysql_fetch_object(mysql_query("select * from lma_links where id = '$ccode'"));
		$pol = $pols->confirmed;
		
		if (!$pol) {
			message("Error", "Invalid verification code");
		}
		if ($pol != "no") {
			message("Oops!", "This e-mail has already been verified.");
		}
		else {
			$pol = mysql_query("update lma_links set confirmed = 'yes', date = '".time()."' where id = '$ccode'");
			
			$goo = 1;
			$lacat = $pols->category;
			
			$pol = mysql_fetch_object(mysql_query("select * from lma_categories where id = '$lacat'"));
			
			$caturl = "/". getindex($pol->name) . ".$pext";
			
			while ($goo == 1 and $x < 100) {
			
				$x++;
			
				$pol = mysql_fetch_object(mysql_query("select * from lma_categories where id = '$lacat'"));
				$caturl = "/".str_replace(" ", "_", $pol->name).$caturl;
				$lacat = $pol->parent;
				if ($pol->parent == "0") $goo = 0;
			
			}
			
			
			$directoryurl = "http://".$_SERVER['SERVER_NAME']. $base."/";
		
			$categoryurl = "http://".$_SERVER["SERVER_NAME"].$base.$caturl;
			
			$listinfo = "
        Title: ".$pols->title."
          URL: ".$pols->url."
  Description: ".$pols->description."
   First Name: ".$pols->firstname."
    Last Name: ".$pols->lastname."
        Email: ".$pols->email."
   Reciprocal: ".$pols->recipurl;


			$addedtpls = mysql_fetch_object(mysql_query("select subject, body from lma_emails where id = 'added'"));
		
			$subject = $addedtpls->subject;
			$subject = str_replace("{FIRSTNAME}", stripslashes($pols->firstname), $subject);
			$subject = str_replace("{LASTNAME}", stripslashes($pols->lastname), $subject);
			$subject = str_replace("{DIRECTORY-LINK}", $directoryurl, $subject);
			$subject = str_replace("{CATEGORY-LINK}", $categoryurl, $subject);
			
			$body = $addedtpls->body;
			$body = str_replace("{FIRSTNAME}", stripslashes($pols->firstname), $body);
			$body = str_replace("{LASTNAME}", stripslashes($pols->lastname), $body);
			$body = str_replace("{DIRECTORY-LINK}", $directoryurl, $body);
			$body = str_replace("{CATEGORY-LINK}", $categoryurl, $body);
			$body = str_replace("{LISTING-DETAILS}", $listinfo, $body);
			
			
			maill($pols->email, $subject, $body, "From: <$adminemail>");

			$newtpls = mysql_fetch_object(mysql_query("select subject, body from lma_emails where id = 'new'"));
		
			$subject = $newtpls->subject;
			$body = str_replace("{ADMIN-LINK}", "http://".$_SERVER["SERVER_NAME"].str_replace($basedir, "", $_SERVER["SCRIPT_NAME"])."admin.php", $newtpls->body);			
			
			maill($adminemail, $subject, $body, "From: $fromname <$adminemail>");
			
			header("Location: $thankurl");
		}
	}

}

elseif (preg_match("/^\/add\.$pext/", $uri)) {

	if ($submit) {
		
		if (!$title) message("Error", "You must enter a title for your link");
		if (!$url) message("Error", "You must enter your site's URL");
		if (!$fname) message("Error", "You must enter your first name");
		if (!$emailaddy) message("Error", "You must enter your e-mail address");
		if (strlen($title)>$titlesize) message("Error", "Your link's title can't be longer than $titlesize characters");
		if (strlen($description)>$descsize) message("Error", "Your link's description can't be longer than $descsize characters");
		
		else {
		
			if ($requirerecip == "yes") {
			
				if (!$recipurl) message("Error", "You must enter the URL where you've put the reciprocal link");

				$page = @file($recipurl);

				if (!$page) message("Error", "Could not check reciprocal link because the URL is not available at this time.
Please make sure that the URL is valid");

				else {

					$pagehtml = implode("", $page);
					if (!ereg($reciplinkurl, $pagehtml)) message("Error", "We could not find the reciprocal link at the specified URL. Please place the reciprocal URL to our website on your own site prior to submitting the submission form.");

				}

			}		
		
		}
		
		if ($defaultpremium == "yes") $premium = "yes";
		else $premium = "no";
		
		if ($adminapproval == "yes") $status = "3";
		else $status = "1";
		
		if ($emailconfirm == "yes") $econf = "no";
		else $econf = "yes";
				
		$pol = mysql_query("insert into lma_links values(NULL, '$category', '$status', '$econf', '$premium', '$title', '$description', '$url', '$fname', '$lname', '$emailaddy', '$recipurl', '".time()."', '0')") or message("Error", "We're experiencing some problems with our database. Please try again later.");
		
		$lastid = mysql_insert_id();
		
		$directoryurl = "http://".$_SERVER['SERVER_NAME']. $base."/";
		
		if ($emailconfirm == "yes") {
		
			$ccode = strtr($lastid, "1234567890", "TzEaSxLbGo");
			
			$confirmurlc = "http://".$_SERVER['SERVER_NAME']. $base."/confirm.$pext?code=$ccode";
			
			$confirmtpls = mysql_fetch_object(mysql_query("select subject, body from lma_emails where id = 'confirm'"));

			$listinfo = "
        Title: ".$title."
          URL: ".$url."
  Description: ".$description."
   First Name: ".$fname."
    Last Name: ".$lname."
        Email: ".$emailaddy."
   Reciprocal: ".$recipurl;
			
			$subject = str_replace("{FIRSTNAME}", stripslashes($fname), $confirmtpls->subject);
			$subject = str_replace("{LASTNAME}", stripslashes($lname), $subject);
			$subject = str_replace("{DIRECTORY-LINK}", $directoryurl, $subject);
			$subject = str_replace("{CONFIRMATION-LINK}", $confirmurlc, $subject);

			$body = str_replace("{FIRSTNAME}", stripslashes($fname), $confirmtpls->body);
			$body = str_replace("{LASTNAME}", stripslashes($lname), $body);
			$body = str_replace("{DIRECTORY-LINK}", $directoryurl, $body);
			$body = str_replace("{CONFIRMATION-LINK}", $confirmurlc, $body);
			$body = str_replace("{LISTING-DETAILS}", $listinfo, $body);
			
			maill($emailaddy, $subject, $body, "From: $fromname <$adminemail>");
			
			header("Location: $confirmurl");
			
		}

		else {
		
		
			$goo = 1;
			$lacat = $category;
			
			$pol = mysql_fetch_object(mysql_query("select * from lma_categories where id = '$lacat'"));
			
			$caturl = "/". getindex($pol->name) . ".$pext";
			
			while ($goo == 1 and $x < 100) {
			
				$x++;
			
				$pol = mysql_fetch_object(mysql_query("select * from lma_categories where id = '$lacat'"));
				$caturl = "/".str_replace(" ", "_", $pol->name).$caturl;
				$lacat = $pol->parent;
				if ($pol->parent == "0") $goo = 0;
			
			}
			
			$categoryurl = "http://".$_SERVER["SERVER_NAME"].$base.$caturl;
		
			$listinfo = "
        Title: ".$title."
          URL: ".$url."
  Description: ".$description."
   First Name: ".$fname."
    Last Name: ".$lname."
        Email: ".$emailaddy."
   Reciprocal: ".$recipurl;
   
			$addedtpls = mysql_fetch_object(mysql_query("select subject, body from lma_emails where id = 'added'"));
		
			$subject = $addedtpls->subject;
			$subject = str_replace("{FIRSTNAME}", stripslashes($fname), $subject);
			$subject = str_replace("{LASTNAME}", stripslashes($lname), $subject);
			$subject = str_replace("{DIRECTORY-LINK}", $directoryurl, $subject);
			$subject = str_replace("{CATEGORY-LINK}", $categoryurl, $subject);
			
			$body = $addedtpls->body;
			$body = str_replace("{FIRSTNAME}", stripslashes($fname), $body);
			$body = str_replace("{LASTNAME}", stripslashes($lname), $body);
			$body = str_replace("{DIRECTORY-LINK}", $directoryurl, $body);
			$body = str_replace("{CATEGORY-LINK}", $categoryurl, $body);
			$body = str_replace("{LISTING-DETAILS}", $listinfo, $body);
			
			
			maill($emailaddy, $subject, $body, "From: <$adminemail>");
			
		
			$newtpls = mysql_fetch_object(mysql_query("select subject, body from lma_emails where id = 'new'"));
		
			$subject = $newtpls->subject;
			$body = str_replace("{ADMIN-LINK}", "http://".$_SERVER["SERVER_NAME"].str_replace($basedir, "", $_SERVER["SCRIPT_NAME"])."admin.php", $newtpls->body);			
			
			maill($adminemail, $subject, $body, "From: $fromname <$adminemail>");
			
			header("Location: $thankurl");				
		
		}
		
		
	}
	
	else {
	
		if ($category) {
		
		
			$goo = 1;

			$lacat = $category;

			while ($goo == 1 and $x < 100) {

				$x++;

				$pol = mysql_fetch_object(mysql_query("select * from lma_categories where id = '$lacat'"));

				if ($lacat == $category) {
					$caturl2 = $pol->name;
				}
				else {
					$caturl2 = $pol->name." > ".$caturl2;
				}

				$lacat = $pol->parent;
				if ($pol->parent == "0") $goo = 0;

			}
		

			$addhtml = '<form action="add.'.$pext.'" method="post" style="margin: 0px">
                    <input type="hidden" name="action" value="addlink">

                    <table border="0" cellpadding="4" cellspacing="4" width="500">
                      <tr>
                        <td valign="top" class="addform">Title</td>
                        <td valign="top" class="addformfield"><input type="text" name="title" size="50"></td>
                      </tr>
                      <tr>
                        <td valign="top" class="addform">Description</td>
                        <td valign="top" class="addformfield"><textarea rows="4" name="description" cols="40"></textarea></td>
                      </tr>
                      <tr>
                        <td valign="top" class="addform">URL</td>
                        <td valign="top" class="addformfield"><input type="text" name="url" size="50"></td>
                      </tr>
                      <tr>
                        <td valign="top" class="addform">Category</td>
                        <td valign="top" class="addformfield"><input type="hidden" name="category" value="'.$category.'"> '.$caturl2.'</td>
                      </tr>
                      <tr>
                        <td valign="top" class="addform">First
                          Name</td>
                        <td valign="top" class="addformfield"><input type="text" name="fname" size="20"></td>
                      </tr>
                      <tr>
                        <td valign="top" class="addform">Last
                          Name</td>
                        <td valign="top" class="addformfield"><input type="text" name="lname" size="20"></td>
                      </tr>
                      <tr>
                        <td valign="top" class="addform">Email
                          Address</td>
                        <td valign="top" class="addformfield"><input type="text" name="emailaddy" size="50"></td>
                      </tr>
                      <tr>
                        <td valign="top" class="addform">Reciprocal Link URL</td>
                        <td valign="top" class="addformfield"><input type="text" name="recipurl" size="50"></td>
                      </tr>
					  <tr>
						<td></td>
					  </tr>
					  <tr>
						<td><p align="center"><input type="submit" value="Add Listing" name="submit"></p></td>
					  </tr>
					</table>
            		</form>
';

		}
		
		
		else $addhtml = "You must navigate down to the category where you want your link to be added, and click on the "Add Your Site" link there.";

		$tpl = implode("", file("templates/add.html"));

		$tpl = str_replace("<%add-site-form%>", $addhtml, $tpl);

		echo displaytpl($tpl);	
	
	}

}

elseif (preg_match("/^\/search\.$pext/", $uri)) {

	if (!$page) $page = 1;

	$tpl = implode("", file("templates/search.html"));
	
	$kws = preg_split("/\s+/", $query);
	
	while (list(,$kw) = each($kws)) {
	
		if ($kw) {
			$valid = 1;
			$sqlsrch .= " and (title like '%$kw%' or description like '%$kw%')";
		}
	
	}
	
	if (!$valid) die("You must enter at least one keyword.");

	$lords = array("1" => "rand()", "2" => "title", "3" => "date desc");
	$lord = $lords[$lorder];
		
	$pol = mysql_query("select * from lma_links where (status = '1' or status = '2' or status = '5') and confirmed = 'yes' $sqlsrch order by premium, $lord limit ". (($page-1)*$lperpage).", $lperpage") or die(mysql_error());

	
	if (mysql_num_rows($pol) > 0) {

		$count = array_shift(mysql_fetch_row(mysql_query("select count(*) from lma_links where (status = '1' or status = '2' or status = '5') and confirmed = 'yes' $sqlsrch")));

		if ($newwindow == "yes") $nwin = "target="_blank"";
		while ($link = mysql_fetch_object($pol)) {

			$goo = 1;

			$lacat = $link->category;

			while ($goo == 1 and $x < 100) {

				$x++;

				
				$pols = mysql_query("select * from lma_categories where id = '$lacat'");
				if (mysql_num_rows($pols) < 1) break;
				$pols = mysql_fetch_object($pols);
				
				
				if ($lacat == $link->category) {
					$caturl = str_replace(" ", "_", $pols->name) ."/". getindex($pols->name). ".$pext";
					$caturl2 = $pols->name;
				}
				else {
					$caturl = str_replace(" ", "_", $pols->name) ."/". $caturl;
					$caturl2 = $pols->name." > ".$caturl2;
				}
				
				$fromhtml = "From: <a href="".$_SERVER["SCRIPT_NAME"]."/$caturl">Directory > $caturl2</a>";

				$lacat = $pols->parent;
				
				if ($pols->parent == "0") break;

			}
			
			if ($princlude == "yes") $prhtml = " ".getpr($link->url);


			$linkshtml .= "<p><a href="".$link->url."" $nwin>".$link->title."</a>$prhtml<br>\n".$link->description."<br><small><span class="category-link">$fromhtml</span></small></p>\n\n";

		}

		if ($count > $lperpage) {

			$linkshtml .= "<p>Results: ";
			if ($page > 1) $linkshtml .= "<a href="search.$pext?query=".urlencode($query)."&page=".($page-1)."">$pageprev</a> ";
			for ($o=1; $o<=ceil($count/$lperpage); $o++) {
				if ($page == $o) $linkshtml .= "$o ";
				else $linkshtml .= "<a href="search.$pext?query=".urlencode($query)."&page=".($o)."">$o</a> ";

			}
			if ($page < ceil($count/$lperpage)) $linkshtml .= "<a href="search.$pext?query=".urlencode($query)."&page=".($page+1)."">$pagenext</a> ";
			$linkshtml .= "</p>";
		}
	
	}
	
	else $linkshtml = "No results found. Please try again using different search terms.";
	
	$pol = mysql_query("select * from lma_categories where parent = '$catid' order by name");
	if (mysql_num_rows($pol) > 0) {
		while ($scat = mysql_fetch_object($pol)) {
			$subcathtml .= "<a href="".str_replace(" ", "_", $scat->name)."/".getindex($scat->name).".$pext">".$scat->name."</a> | ";
		}
		$subcathtml = substr($subcathtml, 0, -1);
	}
	
	getmaincats();
	
	$navhtml = "<a href="$base/">Directory</a>";
	
	$tpl = str_replace("<%navigation-path%>", $navhtml, $tpl);
	$tpl = str_replace("<%add-site%>", $addlink, $tpl);
	$tpl = str_replace("<%search-box%>", $searchbox, $tpl);
	$tpl = str_replace("<%main-categories%>", $cathtml, $tpl);
	$tpl = str_replace("<%search-results%>", $linkshtml, $tpl);
	$tpl = str_replace("<%keyword-term%>", $query, $tpl);
	$tpl = str_replace("<%subcategory-links%>", $subcathtml, $tpl);
	
	echo displaytpl($tpl);	

}

else {

	$parts = split("/", $uri);
	$blank = array_shift($parts);
	$pagen = array_pop($parts);
	
	$lnum = count($parts) - 1;
	$lastcat = $parts[$lnum];
	
	if ($pagen == getindex($lastcat).".$pext") {
		$page = 1;
	}
	elseif (preg_match("/". str_replace(".", "\\.", str_replace("*", "\\*", str_replace("/", "\\/", getindex($lastcat))))."-(.+?)\.$pext/i", $pagen, $nump)) {
		$page = $nump[1];
	}
	
	if (count($parts) == 1) {
	
		$tpl = implode("", file("templates/category.html"));
		
		$cat = str_replace("_", " ", $parts[0]);
		
		//echo $cat;
		
		$catid = array_shift(mysql_fetch_row(mysql_query("select id from lma_categories where name = '$cat' and parent = '0'")));
		
		$lords = array("1" => "rand()", "2" => "title", "3" => "date desc");
		$lord = $lords[$lorder];
		
		$pol = mysql_query("select * from lma_links where (status = '1' or status = '2' or status = '5') and confirmed = 'yes' and category = '".$catid."' order by premium, $lord limit ". (($page-1)*$lperpage).", $lperpage");
		$count = array_shift(mysql_fetch_row(mysql_query("select count(*) from lma_links where (status = '1' or status = '2' or status = '5') and confirmed = 'yes' and category = '".$catid."'")));
		
		$navhtml = "<a href="$base/">Directory</a> > $cat";

	}
	else {
		$tpl = implode("", file("templates/subcategory.html"));
		
		$cat = str_replace("_", " ", $lastcat);
		
		$ipar = 0;
		
		$lastcat = array_pop($parts);
		
		$navhtml = "<a href="$base/">Directory</a>";
		
		$lastbase = $base;
		
		while (list(,$part) = each($parts)) {
		
			$pol = array_shift(mysql_fetch_row(mysql_query("select id from lma_categories where parent = '$ipar' and name = '".str_replace("_", " ", $part)."'")));
			$ipar = $pol;
			$navhtml .= " > <a href="$lastbase/$part/".getindex($part).".$pext">".str_replace("_", " ", $part)."</a>";
			$lastbase = "$lastbase/$part";
		
		}
		
		$navhtml .= " > ".str_replace("_", " ", $lastcat); 
		
		$catid = array_shift(mysql_fetch_row(mysql_query("select id from lma_categories where parent = '$ipar' and name = '".str_replace("_", " ", $lastcat)."'")));

		$lords = array("1" => "rand()", "2" => "title", "3" => "date desc");
		$lord = $lords[$lorder];
		
		$pol = mysql_query("select * from lma_links where (status = '1' or status = '2' or status = '5') and confirmed = 'yes' and category = '".$catid."' order by premium, $lord limit ". (($page-1)*$lperpage).", $lperpage") or die(mysql_error());
		$count = array_shift(mysql_fetch_row(mysql_query("select count(*) from lma_links where (status = '1' or status = '2' or status = '5') and confirmed = 'yes' and category = '".$catid."'")));

		
	}
	
	if ($newwindow == "yes") $nwin = "target="_blank"";
	
	if (mysql_num_rows($pol) < 1) {
		$linkshtml = "This category doesn't contain any links";
	}
	else {
		while ($link = mysql_fetch_object($pol)) {

			if ($princlude == "yes") $prhtml = " ".getpr($link->url);
			$linkshtml .= "<p><a href="".$link->url."" $nwin>".$link->title."</a>$prhtml<br>\n".$link->description."</p>\n\n";

		}
	}
	if ($count > $lperpage) {
	
		$linkshtml .= "<p>Results: ";
		if ($page > 1) $linkshtml .= "<a href="".getindex($lastcat)."-".($page-1).".$pext">$pageprev</a> ";
		for ($o=1; $o<=ceil($count/$lperpage); $o++) {
			if ($page == $o) $linkshtml .= "$o ";
			else $linkshtml .= "<a href="".getindex($lastcat)."-$o.$pext">$o</a> ";
		
		}
		if ($page < ceil($count/$lperpage)) $linkshtml .= "<a href="".getindex($lastcat)."-".($page+1).".$pext">$pagenext</a> ";
		$linkshtml .= "</p>";
	}
	
	$pol = mysql_query("select * from lma_categories where parent = '$catid' order by name");
	if (mysql_num_rows($pol) > 0) {
		while ($scat = mysql_fetch_object($pol)) {
			$subcathtml .= "<a href="".str_replace(" ", "_", $scat->name)."/".getindex($scat->name).".$pext">".$scat->name."</a> | ";
		}
		$subcathtml = substr($subcathtml, 0, -2);
	}
	else $subcathtml = "None"; 
	
	getmaincats();
	
	$addlink = "<a href="$base/add.$pext?category=$catid">Add Your Site</a>";
	
	$tpl = str_replace("<%navigation-path%>", $navhtml, $tpl);
	$tpl = str_replace("<%add-site%>", $addlink, $tpl);
	$tpl = str_replace("<%search-box%>", $searchbox, $tpl);
	$tpl = str_replace("<%main-categories%>", $cathtml, $tpl);
	$tpl = str_replace("<%website-listings%>", $linkshtml, $tpl);
	$tpl = str_replace("<%category-name%>", $cat, $tpl);
	$tpl = str_replace("<%subcategory-links%>", $subcathtml, $tpl);
	
	echo displaytpl($tpl);

}

?>
Many thanks
Dave

feyd | swapped

Code: Select all

to

Code: Select all

tag[/color]

Posted: Sat Aug 28, 2004 2:58 pm
by feyd
I would guess that $lord is blank. What does swapping this line:

Code: Select all

$pol = mysql_query("select * from lma_links where (status = '1' or status = '2' or status = '5') and confirmed = 'yes' $sqlsrch order by premium, $lord limit ". (($page-1)*$lperpage).", $lperpage") or die(mysql_error());
with

Code: Select all

$sql_test = "select * from lma_links where (status = '1' or status = '2' or status = '5') and confirmed = 'yes' and category = '".$catid."' order by premium, $lord limit ". (($page-1)*$lperpage).", $lperpage";
var_export($sql_test);
      $pol = mysql_query($sql_test) or die(mysql_error());
output now?

Posted: Sat Aug 28, 2004 3:38 pm
by thewormman
Hi feyd

Thanks for your help
Tried the changed code and got when I click on a category
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home3/davemcc/public_html/1coolwebsite.co.uk/lma/directory on line 789

and this on a subcat
Warning: array_shift() [function.array-shift]: The argument should be an array in /home3/davemcc/public_html/1coolwebsite.co.uk/lma/directory on line 776
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 'limit 0, 10' at line 1
Sorry
Dave

Posted: Sat Aug 28, 2004 4:09 pm
by feyd
so something like

Code: Select all

select * from lma_links where (status = ''1'' or status = ''2'' or status = ''5'') and confirmed = ''yes'' and category = ''6'' order by premium ......
didn't print out?

Posted: Sat Aug 28, 2004 4:59 pm
by thewormman
feyd wrote:so something like

Code: Select all

select * from lma_links where (status = ''1'' or status = ''2'' or status = ''5'') and confirmed = ''yes'' and category = ''6'' order by premium ......
didn't print out?
No, all I got on screen was what I put in my last post
:(

Dave

Posted: Sat Aug 28, 2004 5:20 pm
by feyd
so which lines are 776 and 789?

Posted: Sat Aug 28, 2004 5:46 pm
by thewormman
Lines 774 to 782

Code: Select all

<?php
  $navhtml .= " > ".str_replace("_", " ", $lastcat);

                $catid = array_shift(mysql_fetch_row(mysql_query("select id from lma_categories where parent = '$ipar' and name = '".str_replace("_", " ", $lastcat)."'")));

                $lords = array("1" => "rand()", "2" => "title", "3" => "date desc");
                $lord = $lords[$lorder];

                $pol = mysql_query("select * from lma_links where (status = '1' or status = '2' or status = '5') and confirmed = 'yes' and category = '".$catid."' order by premium, $lord limit ". (($page-1)*$lperpage).", $lperpage") or die(mysql_error());
                $count = array_shift(mysql_fetch_row(mysql_query("select count(*) from lma_links where (status = '1' or status = '2' or status = '5') and confirmed = 'yes' and category = '".$catid."'")));
?>
Lines 787 to 790

Code: Select all

<?php
if ($newwindow == "yes") $nwin = "target="_blank"";

        if (mysql_num_rows($pol) < 1) {
                $linkshtml = "This category doesn't contain any links";
?>

Dave

Posted: Sat Aug 28, 2004 5:51 pm
by feyd
thewormman wrote:Lines 774 to 782

Code: Select all

<?php
  $navhtml .= " > ".str_replace("_", " ", $lastcat);

                $catid = array_shift(mysql_fetch_row(mysql_query("select id from lma_categories where parent = '$ipar' and name = '".str_replace("_", " ", $lastcat)."'")));

                $lords = array("1" => "rand()", "2" => "title", "3" => "date desc");
                $lord = $lords[$lorder];

                $pol = mysql_query("select * from lma_links where (status = '1' or status = '2' or status = '5') and confirmed = 'yes' and category = '".$catid."' order by premium, $lord limit ". (($page-1)*$lperpage).", $lperpage") or die(mysql_error());
                $count = array_shift(mysql_fetch_row(mysql_query("select count(*) from lma_links where (status = '1' or status = '2' or status = '5') and confirmed = 'yes' and category = '".$catid."'")));
?>
can you stick the $pol query string into a variable and print it for us?

Posted: Sat Aug 28, 2004 6:10 pm
by thewormman
Sorry you completely lost me on that one.

Could you give me something to identify the bit you want

Sorry, I did say I was a complete novice :(

Dave

Posted: Sat Aug 28, 2004 6:39 pm
by feyd
replace

Code: Select all

<?php
  $navhtml .= " > ".str_replace("_", " ", $lastcat);

                $catid = array_shift(mysql_fetch_row(mysql_query("select id from lma_categories where parent = '$ipar' and name = '".str_replace("_", " ", $lastcat)."'")));

                $lords = array("1" => "rand()", "2" => "title", "3" => "date desc");
                $lord = $lords[$lorder];

                $pol = mysql_query("select * from lma_links where (status = '1' or status = '2' or status = '5') and confirmed = 'yes' and category = '".$catid."' order by premium, $lord limit ". (($page-1)*$lperpage).", $lperpage") or die(mysql_error());
                $count = array_shift(mysql_fetch_row(mysql_query("select count(*) from lma_links where (status = '1' or status = '2' or status = '5') and confirmed = 'yes' and category = '".$catid."'")));
?>
with

Code: Select all

<?php
  $navhtml .= " > ".str_replace("_", " ", $lastcat);

                $catid = array_shift(mysql_fetch_row(mysql_query("select id from lma_categories where parent = '$ipar' and name = '".str_replace("_", " ", $lastcat)."'")));

                $lords = array("1" => "rand()", "2" => "title", "3" => "date desc");
                $lord = $lords[$lorder];

                $sql_test = "select * from lma_links where (status = '1' or status = '2' or status = '5') and confirmed = 'yes' and category = '".$catid."' order by premium, $lord limit ". (($page-1)*$lperpage).", $lperpage";
                die($sql_test); 
                $pol = mysql_query($sql_test) or die(mysql_error());
                $count = array_shift(mysql_fetch_row(mysql_query("select count(*) from lma_links where (status = '1' or status = '2' or status = '5') and confirmed = 'yes' and category = '".$catid."'")));
?>

Posted: Sat Aug 28, 2004 6:54 pm
by thewormman
OK this time I got on cat page:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home3/davemcc/public_html/1coolwebsite.co.uk/lma/directory on line 791
and on the subcat page:
Warning: array_shift() [function.array-shift]: The argument should be an array in /home3/davemcc/public_html/1coolwebsite.co.uk/lma/directory on line 776
select * from lma_links where (status = '1' or status = '2' or status = '5') and confirmed = 'yes' and category = '' order by premium, limit 0, 10
Annoying isn't it?
Dave

Posted: Sat Aug 28, 2004 6:59 pm
by feyd
$lord is blank. so $lorder was not in $lords.

Posted: Sat Aug 28, 2004 7:10 pm
by thewormman
feyd wrote:$lord is blank. so $lorder was not in $lords.
I really apreciate your efforts.

Sorry it is 01:08 AM here in the UK and I am struggling.

What are your conclusions? in my simple terms please?

Dave