I have very limited use of using MySql - but I am trying to fix this code and it seems to be corrent. But I am still getting the error.
The website is a web directory, and the code itself checks to see the websites that arent linking back to the site. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/imedia/public_html/uk-webdirectory.info/admin/linkchecker.php on line 34 This is Line 34

$total=mysql_num_rows($return);

This is Lines 32 - 35

$query="SELECT * FROM dir_site_list WHERE site_sponsor='N' AND site_live='Y'ORDER BY site_id LIMIT $start,$limit";
$return=mysql_query($query,$link);
$total=mysql_num_rows($return);
$sess_id="PHPSESSID=".session_id();

I have searched the net and tried various other methods that were posted on this forum and others and still I get the same error.

Any help and expertise would be much appreciated.

The error is because there is something wrong in your query. Print the query, execute it in mysql console or phpmyadmin. (Also post it here) :)

change this :
$return=mysql_query($query,$link);

to:
$return=mysql_query($query);

change this :
$return=mysql_query($query,$link);

to:
$return=mysql_query($query);

That definitely wouldn't matter. Thats because mysql_query can take an optional parameter of link identifier (the variable used to 'open' the connection).

k...nav...
thanks for indiacating........

The error is because there is something wrong in your query. Print the query, execute it in mysql console or phpmyadmin. (Also post it here) :)

I am not sure what you mean by printing the query, but I did test the first line and then the group of lines and the results were.

Tested:
$total=mysql_num_rows($return);

MySQL said: 
#1064 - 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 '$TOTAL=mysql_num_rows($return)' at line 1

Tested:
$query="SELECT * FROM dir_site_list WHERE site_sponsor='N' AND site_live='Y'ORDER BY site_id LIMIT $start,$limit";
$return=mysql_query($query,$link);
$total=mysql_num_rows($return);
$sess_id="PHPSESSID=".session_id();

MySQL said: Documentation
#1064 - 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 '$query="SELECT * FROM dir_site_list WHERE site_sponsor='N' AND site_live='Y'ORDE' at line 1

Where can I find the manual and version of MySQL I have and any ideas on how to fix it. I really appreciate anything you can tell me, as I am a newbie at this. Usually I just install scripts, not edit them. :)

$query="SELECT * FROM dir_site_list WHERE site_sponsor='N' AND site_live='Y' ORDER BY site_id LIMIT $start,$limit"; 
echo $query;

Tell us what it prints.

It's reply is practically the same as before I think.

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 '$query="SELECT * FROM dir_site_list WHERE site_sponsor='N' AND site_live='Y' ORD' at line 1

Can you post your updated code ? echo $query; should print out the query. But anyway, post your complete code.

What do you mean by updated code? Also I am confused about print out the query, do you mean its response to the query I run in phpmyadmin?

Did you want me to post the whole page?

Umm.. Post the whole page.. I ll tell you what to do next..

<?php
ini_set("max_execution_time", "30000");


# choose a banner

include_once('../includes/db_connect.php');
?>
<?php
ini_set("max_execution_time", "30000");

session_start();

# remove members from the mailing list when they click from within the newsletter
check_admin();


if (isset($HTTP_GET_VARS['mode']) && $HTTP_GET_VARS['mode']=='delete') {
	$id=$HTTP_GET_VARS['id'];
	$query="DELETE FROM dir_site_list WHERE site_id = $id";
	$return=mysql_query($query,$link);
}

$query="SELECT * FROM dir_site_list WHERE site_sponsor='N' AND site_live='Y'ORDER BY site_id LIMIT $start,$limit";
$return=mysql_query($query);
$TOTAL=mysql_num_rows($return);
$sess_id="PHPSESSID=".session_id();
include("$CONST_INCLUDE_ROOT/Templates/maintemplate.header.inc.php");
?>


<?php include('../includes/admin_header.php'); ?>
<?php
while ($sql_array=mysql_fetch_object($return)) {

	$linkback_url="http://$sql_array->site_linkback";
	$linkback_url=trim($linkback_url);

	print("Checking:$sql_array->site_id> <a href='$linkback_url' target='blank'>$linkback_url</a>");
	flush();
	$contents="";

	if (@$fp=fopen($linkback_url,'r')) {
	$chktime=time();
		while(!feof($fp))
		{
		  $contents.= fread($fp,1024);
		  if (time() >= $chktime+3) break;
		}
		fclose($fp);

		if (strstr($contents,$CONST_LINK_ROOT)) {
			$test_result="<font color='green'>Passed</font>";
		} else {
			$test_result="<font color='red'>Failed</font> -> <a href='linkchecker.php?mode=delete&id=$sql_array->site_id&start=$start&limit=$limit'><font color='red'>[Delete]</font></a>";
		}

		print(" -> $test_result<br>");
	} else {
		print(" -> <a href='linkchecker.php?mode=delete&id=$sql_array->site_id&start=$start&limit=$limit'><font color='red'>Failed to open</font></a><br>");
	}

	flush();

}


print("<br>Link Checking Complete");
mysql_close($link);
?>
<p><input type="button" onClick="location.href='linkchecker.php?start=<?php echo $start ?>&limit=<?php echo $limit ?>&<?php echo $sess_id ?>'" value="Refresh" name="btnRefresh">&nbsp;
<input type="button" onClick="location.href='linkchecker.php?start=<?php echo $start+30 ?>&limit=<?php echo $limit ?>&<?php echo $sess_id ?>'" value="Next" name="btnNext"></p>
<p>&nbsp;</p>

<?include("$CONST_INCLUDE_ROOT/Templates/maintemplate.footer.inc.php");?>

Okay.. You have some errors in your script.
1.

SELECT * FROM dir_site_list WHERE site_sponsor='N' AND site_live='Y' ORDER BY site_id LIMIT ,

When you execute the script for the 1st time, no LIMIT is set. That is, $start and $limit will be empty. Thats the reason you are getting the error.
2. There has to be a whitespace between site_live='Y' and ORDER in the query

$query="SELECT * FROM dir_site_list WHERE site_sponsor='N' AND site_live='Y'ORDER BY site_id LIMIT $start,$limit";

3. Since you aren't assigning or calculating $start and $limit, you always get this error.
My suggestion is to ask the person who did this script for you to give you a working pagination script!

Okay.. You have some errors in your script.
1.

When you execute the script for the 1st time, no LIMIT is set. That is, $start and $limit will be empty. Thats the reason you are getting the error.
2. There has to be a whitespace between site_live='Y' and ORDER in the query

3. Since you aren't assigning or calculating $start and $limit, you always get this error.
My suggestion is to ask the person who did this script for you to give you a working pagination script!

The unfortunate thing about asking the person who did it, is that I can no longer have contact, and have since emailed but unfortunately on a long sabatical travelling. :(

This could sound cheeky, but would you have any advice on how to fix it that it can at least work for now. OKAY, I am cheeky.

Thanks for all your help.

You can initialise $start and $limit value. Try the following script. If it works, then, Yay! If it doesn't, then you can post your question in php forum. There are many people who loves to write scripts ! You might get help from any one of them!

<?php
ini_set("max_execution_time", "30000");


# choose a banner

include_once('../includes/db_connect.php');
?>
<?php
ini_set("max_execution_time", "30000");

session_start();

# remove members from the mailing list when they click from within the newsletter
check_admin();

$start = isset($_REQUEST['start']) ? $_REQUEST['start']:"0";
$limit = 10; // how many records you want to show per page

if (isset($HTTP_GET_VARS['mode']) && $HTTP_GET_VARS['mode']=='delete') {
	$id=$HTTP_GET_VARS['id'];
	$query="DELETE FROM dir_site_list WHERE site_id = $id";
	$return=mysql_query($query,$link);
}

$query="SELECT * FROM dir_site_list WHERE site_sponsor='N' AND site_live='Y'ORDER BY site_id LIMIT $start,$limit";
$return=mysql_query($query);
$TOTAL=mysql_num_rows($return);
$sess_id="PHPSESSID=".session_id();
include("$CONST_INCLUDE_ROOT/Templates/maintemplate.header.inc.php");
?>


<?php include('../includes/admin_header.php'); ?>
<?php
while ($sql_array=mysql_fetch_object($return)) {

	$linkback_url="http://$sql_array->site_linkback";
	$linkback_url=trim($linkback_url);

	print("Checking:$sql_array->site_id> <a href='$linkback_url' target='blank'>$linkback_url</a>");
	flush();
	$contents="";

	if (@$fp=fopen($linkback_url,'r')) {
	$chktime=time();
		while(!feof($fp))
		{
		  $contents.= fread($fp,1024);
		  if (time() >= $chktime+3) break;
		}
		fclose($fp);

		if (strstr($contents,$CONST_LINK_ROOT)) {
			$test_result="<font color='green'>Passed</font>";
		} else {
			$test_result="<font color='red'>Failed</font> -> <a href='linkchecker.php?mode=delete&id=$sql_array->site_id&start=$start&limit=$limit'><font color='red'>[Delete]</font></a>";
		}

		print(" -> $test_result<br>");
	} else {
		print(" -> <a href='linkchecker.php?mode=delete&id=$sql_array->site_id&start=$start&limit=$limit'><font color='red'>Failed to open</font></a><br>");
	}

	flush();

}


print("<br>Link Checking Complete");
mysql_close($link);
?>
<p><input type="button" onClick="location.href='linkchecker.php?start=<?php echo $start ?>&limit=<?php echo $limit ?>&<?php echo $sess_id ?>'" value="Refresh" name="btnRefresh">&nbsp;
<input type="button" onClick="location.href='linkchecker.php?start=<?php echo $start+30 ?>&limit=<?php echo $limit ?>&<?php echo $sess_id ?>'" value="Next" name="btnNext"></p>
<p>&nbsp;</p>

<?include("$CONST_INCLUDE_ROOT/Templates/maintemplate.footer.inc.php");?>

Thank you very much for all your help and support, the code works perfectly. I will definitely be giving you more reputation later. :)

Great! :)

hi guys, whats the meaning of this error in my search.php form?

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampplite\htdocs\search1.php on line 52

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.