hello there,
im very new to this php malarky and have been asked if i would take a look at repairing a site that was recently messed with by the old coder.
i didnt make nor code this site and my skills are limited
ive managed to plod my way through using common sense and google but ive been stuck on the following error for almost a week now and we could really do with this being sorted to reopen up our community....

the error i recieve is as follows:

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /homepages/2/d398538194/htdocs/headtohead/instellingen.inc on line 710

now the code on line 710 is

while ($row = mysql_fetch_row($result)) {

now from what i can guess i think its struggling to fetch the info from the row in the database table its pointing at....
if any1 can help me that would be brilliant..
i have error_reporting (-1) active at the top of the script and have tried multiple things to sort this issue but to no avail....
as i said im very new to php so any help would be greatly appreciated..
any ideas? need more info just ask :D

Recommended Answers

All 24 Replies

Member Avatar for diafol

The query will probably be wrong. Include the whole code block (query to end of loop).

function show_not_played_fixtures($league="", $wide="small"){

	if ($league=="")$league_id = get_league_id($league);

	

	$weeknr = get_league_weeknr($league);

	$sql = "SELECT league_id, hometeam_id, awayteam_id, game_id, week_nr ".

			"FROM fixtures_result ".

			"WHERE home_result IS NULL ";

			if ($league!="all"){

				$sql .= "&& league_id='" . mysql_real_escape_string($league) . "' AND week_nr < $weeknr ";

			}

			$sql .= "&& fixture_ignore='no' ";

			

			$sql .= "ORDER BY week_nr";

			//echo $sql;

	$result = mysql_query($sql);
	

	$colourclass = "fixturesLightRow";

	while ($row = mysql_fetch_row($result)) {

		$hometeam = get_team_information($row[1]);

		$awayteam = get_team_information($row[2]);

		$league = urlencode(get_league_name($row[0]));

		$hometeamname = urlencode($hometeam[1]);

		$awayteamname = urlencode($awayteam[1]);

		

		$user_id = get_current_user_id($hometeam[0], $league_id);

		$user_name_home = get_user_name($user_id);

		

		$user_id = get_current_user_id($awayteam[0], $league_id);

		$user_name_away = get_user_name($user_id);

		

		if ($user_name_home != 'No User' AND $user_name_away != 'No User') {

		?>

i hope this is the part u meant - line 34 above is line 710 in the code

with a error like this there usaly an error in the myslq query
post that part
problebly look something like

$query="SELECT ....FROM ... WHERE ....";
$result=mysql_query($query);

ah that would be lines 9 to 29 from above

$sql = "SELECT league_id, hometeam_id, awayteam_id, game_id, week_nr ".
 
"FROM fixtures_result ".
 
"WHERE home_result IS NULL ";
 
if ($league!="all"){
 
$sql .= "&& league_id='" . mysql_real_escape_string($league) . "' AND week_nr < $weeknr ";
 
}
 
$sql .= "&& fixture_ignore='no' ";
 
 
 
$sql .= "ORDER BY week_nr";
 
//echo $sql;
 
$result = mysql_query($sql);
Member Avatar for diafol

Using:

$sql = "SELECT league_id, hometeam_id, awayteam_id, game_id, week_nr FROM fixtures_result WHERE home_result IS NULL";
if ($league!="all"){
	$sql .= " AND league_id='" . mysql_real_escape_string($league) . "' AND week_nr < $weeknr";
}
$sql .= " AND fixture_ignore='no' ORDER BY week_nr";

Echo out the query before you run it:

echo $sql;

Does it show what you thought?
If so, copy it from the screen and paste it into the SQL box in phpmyadmin. See if you get an error.
If not, chase some loose ends with regard to the variables used in the sql statement

kk i think i done this right and i ran the query window in phpmyadmin and it gave me the following error

SELECT league_id, hometeam_id, awayteam_id, game_id, week_nr
FROM fixtures_result
WHERE home_result IS NULL && league_id = 'premiership'
AND week_nr & lt;

&& fixture_ignore = 'no' ORDER BY week_nr LIMIT 0 , 30

#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 '&& fixture_ignore = 'no' ORDER BY week_nr  LIMIT 0, 30' at line 1
Member Avatar for diafol
AND week_nr & lt;

That seems to be your problem

AND week_nr < $weeknr

Somehow you've got messed up html encoding for '<' ( &lt; ) and the $weeknr value is missing. OK, so follow up those issues.

EDIT
====
Is that the code output you get to the screen or just the code you ran?
Did you use the code I gave in my previous posts? Try that instead.

nope i used wht i had sry
kk ive ran it with the above code and got the following from the run query

SQL query: Documentation

$sql = "SELECT league_id, hometeam_id, awayteam_id, game_id, week_nr FROM fixtures_result WHERE home_result IS NULL"

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 '$sql = "SELECT league_id, hometeam_id, awayteam_id, game_id, week_nr FROM fixtur' at line 1
Member Avatar for diafol

Run it without the '$sql = "' and the ending '"'!

phpmyadmin SQL box will only take SQL - it won't take php at all

ok the line i used to run it was

$sql = "SELECT league_id, hometeam_id, awayteam_id, game_id, week_nr FROM fixtures_result WHERE home_result IS NULL";

if that is the correct $sql u meant it returns

#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 '$sql = "SELECT league_id, hometeam_id, awayteam_id, game_id, week_nr FROM fixtur' at line 1

did i run the correct piece? sry im a noob at this lol

Member Avatar for diafol

Copy:

SELECT league_id, hometeam_id, awayteam_id, game_id, week_nr FROM fixtures_result WHERE home_result IS NULL

into the SQL box and run it.

ok sry bout tht lol

i did that and it didnt return an error
showed me results from the tbl and each row

Full Texts league_id hometeam_id awayteam_id game_id week_nr
Edit Delete 1 1 2 2 1
Edit Delete 1 3 4 3 2
Edit Delete 1 5 6 4 3
Edit Delete 1 7 8 5 4
Edit Delete 1 9 10 6 5
Edit Delete 1 11 12 7 6
Edit Delete 1 13 14 8 7
Edit Delete 1 15 16 9 8
Edit Delete 1 17 18 10 9
Edit Delete 1 19 20 11 10

thats the outputted result

Member Avatar for diafol

OK, so what's wrong? Is it sorted?

no the error now reads

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /homepages/2/d398538194/htdocs/headtohead/instellingen.inc on line 706

which is this line

while ($row = mysql_fetch_row($result)) {

im not totally sure wht the problem is but as u said above im guessing its todo with getting the info from the table.
all the tables exist and match there names exactly

in your testing you missed a part of the query
Add

AND league_id=`[I] a possible value for $league[/I]` AND week_nr < [I] a possible vaule for $weeknr[/I] AND fixture_ignore='no' ORDER BY week_nr

ahh cheers for that bit :D
kk i added and then used the following query

SELECT league_id, hometeam_id, awayteam_id, game_id, week_nr FROM fixtures_result WHERE home_result IS NULL
AND league_id=` a possible value for $league` AND week_nr < a possible vaule for $weeknr AND fixture_ignore='no' ORDER BY week_nr

it then outputted

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 'possible vaule for $weeknr AND fixture_ignore = 'no' ORDER BY week_nr LIMIT 0, ' at line 1

im not sure if im doing it right - but i think thats how you meant.
sry im beng so much hard work :(

Member Avatar for diafol

Tell me you didn't run that query as was. :(

Are you giving the error from phpmyadmin or from your php page?

i did - i did say i was very new to this lol

that error is str8 off the sql query - not the php page

ok at

a possible value for $league

put in a value that the php varible $league might have

do the same for

a possible vaule for $weeknr

but with the php variable $weeknr

oki doki feel thick now lol sry

kk done that and i got

#1054 - Unknown column '$league_id' in 'where clause'

as the sql error from phpmyadmin

would that mean that in the table "fixtures_result" its suggesting there isnt a row called "league_id" cause if so - there is a row called that..

is the colum called $league_id or maybe league_id ?

the column in the table is called league_id

nope just checked everything over.
all the code pointing to tables are spelt correctly and exist
if its the < $weeknr bit - then i dont really know where to start to work that bit out
thanks for all your help so fair though people
appreciated

ok sorry for the quick post.
i edited abit of the code and the error seems to have gone - just giving me undefined variable now but i can work through those i think..... just to add though
original code was

function show_not_played_fixtures($league="", $wide="small"){
if ($league=="")$league_id = get_league_id($league);
$weeknr = get_league_weeknr($league);
$sql = "SELECT league_id, hometeam_id, awayteam_id, game_id, week_nr ".
"FROM fixtures_result ".
"WHERE home_result IS NULL ";
if ($league!="all"){
$sql .= "&& league_id='" . mysql_real_escape_string($league) . "' AND week_nr < $weeknr ";
}
$sql .= "&& fixture_ignore='no' ";
$sql .= "ORDER BY week_nr";

and changed it to this

function show_not_played_fixtures($league="", $wide="small"){
if ($league=="")$league_id = get_league_id($league);
$weeknr = get_league_weeknr($league);
$sql = "SELECT league_id, hometeam_id, awayteam_id, game_id, week_nr ".
"FROM fixtures_result ".
"WHERE home_result IS NULL ";
if ($league!="all"){
$sql .= "AND league_id='" . mysql_real_escape_string($league) . "' AND week_nr < $weeknr ";
}
"AND fixture_ignore='no' ";
"ORDER BY week_nr";

basically all i did was remove $sql .= from the start of AND fixture_ignore and ORDER BY and the error went away..
thanks for the help and i hope this in someway helps others too

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.