Jump to content

Recommended Posts

i have the following code but i am struggling to get the syntax correct on it as its throwing me a fetch row error

 

does any1 have any suggestions as to how this code should look to work properly pls?

any help would be appreciated

 

$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 ";

            }

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

            

            $sql .= "ORDER BY week_nr";

            //echo $sql;

    $result = mysql_query($sql); 

 

cheers in advance :D

Link to comment
https://forums.phpfreaks.com/topic/255487-syntax-help-needed/
Share on other sites

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 'AND fixture_ignore='no' ORDER BY week_nr' at line 1

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

Link to comment
https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309892
Share on other sites

SELECT league_id, hometeam_id, awayteam_id, game_id, week_nr FROM fixtures_result WHERE home_result IS NULL AND league_id='premiership' AND week_nr < AND fixture_ignore='no' ORDER BY week_nr   

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 'AND fixture_ignore='no' ORDER BY week_nr' at line 1

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

 

i hope this is what u mean? not gr8 at php atm

Link to comment
https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309903
Share on other sites

SELECT league_id, hometeam_id, awayteam_id, game_id, week_nr FROM fixtures_result WHERE home_result IS NULL AND league_id='premiership' AND week_nr < AND fixture_ignore='no' ORDER BY week_nr   

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 'AND fixture_ignore='no' ORDER BY week_nr' at line 1

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

 

i hope this is what u mean? not gr8 at php atm

 

okay, I see the issue now. Here in your SQL

 

SELECT league_id, hometeam_id, awayteam_id, game_id, week_nr FROM fixtures_result WHERE home_result IS NULL AND league_id='premiership' [b]AND week_nr < AND [/b]fixture_ignore='no' ORDER BY week_nr    

 

week_nr < AND is obviously not valid, and indicates that the $weeknr variable has not been assigned a value.

Link to comment
https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309905
Share on other sites

okay, I see the issue now. Here in your SQL

 

SELECT league_id, hometeam_id, awayteam_id, game_id, week_nr FROM fixtures_result WHERE home_result IS NULL AND league_id='premiership' [b]AND week_nr < AND [/b]fixture_ignore='no' ORDER BY week_nr    

 

week_nr < AND is obviously not valid, and indicates that the $weeknr variable has not been assigned a value.

 

ok thanks for that - how would i go about correcting that then??

im lost on it tbf been trying to figure it out for 3-4 days now lol

any help is appreciated :D

Link to comment
https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309907
Share on other sites

okay, I see the issue now. Here in your SQL

 

SELECT league_id, hometeam_id, awayteam_id, game_id, week_nr FROM fixtures_result WHERE home_result IS NULL AND league_id='premiership' [b]AND week_nr < AND [/b]fixture_ignore='no' ORDER BY week_nr    

 

week_nr < AND is obviously not valid, and indicates that the $weeknr variable has not been assigned a value.

the very first line that you posted is where you set $weeknr

 

$weeknr = get_league_weeknr($league);

 

so, either $league does not coincide with the function correctly, or something is going awry in the function itself. Can you post both the contents of the function and the value of $league

 

ok thanks for that - how would i go about correcting that then??

im lost on it tbf been trying to figure it out for 3-4 days now lol

any help is appreciated :D

Link to comment
https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309909
Share on other sites

kk i think i know which bits you need - if not just let me know and ill add them :D

 

function:

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 ";

		}

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



		$sql .= "ORDER BY week_nr";

		//echo $sql;

$result = mysql_query($sql);

 

im not 100% what u mean by value of $league

its a main table in the database that holds the different leagues that display on the site

other than that im not sure what u mean?

sry im not gr8 with php and still learning bits (or forgetting bits lol)

appreciate the help so far though

Link to comment
https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309911
Share on other sites

ok, a couple things.

 

1.

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

 

why are you passing a variable that is empty?

 

2.

$weeknr = get_league_weeknr($league);

 

the above line is the main issue, as $weeknr does not hold a value, which is why your query is failing.

In order to help you further, i need to see the contents of the function "get_league_weeknr"

Link to comment
https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309913
Share on other sites

The value of $weeknr comes from the get_league_weeknr() function. Apparently, that function is returning an empty value. Post that function definition as well. It would appear that you don't have php's error reporting set to show you errors. You should find and set the following directives in your php.ini file as follows, then restart Apache. After doing that, see what errors are reported when you run the script.

 

error_reporting = -1

display_errors = On

Link to comment
https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309915
Share on other sites

ah kk

 

1. i believe thats due to the fact we have a league selector drop down box

i didnt design the site nor code it - our old coder did and in a fit of anger messed with the code and done 1 lol

but im sure thats why

 

2. if im right u mean this bit

function get_league_weeknr($league_id){

$sql = "SELECT league_weeknr FROM league WHERE league_id='" . mysql_real_escape_string($league_id) . "'";	



$result = mysql_query($sql);

$row = mysql_fetch_array($result);

return $row[0];

}

 

hope that helps

 

@pikachu

i currently have mysql_error() set just below this code to display the problem

and i also have

<?php

error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

   ?>

set at the top of the page

which outputs the error message posted above

Link to comment
https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309919
Share on other sites

The above message isn't a php error, it's a MySQL error. If you're going to enable error reporting at runtime, it should be at the top of your script, and you should really use error_reporting(-1); so all possible errors are displayed.

 

While we're on that subject, is what you've posted above the actual code, copied and pasted, or is it "reconstructed"?

Link to comment
https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309923
Share on other sites

set it to -1 now and it gives the following error now

 

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

 

710 - 738 (driectly below above code

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') {

	?>

 

top of script yes

actual code also

Link to comment
https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309933
Share on other sites

set it to -1 now and it gives the following error now

 

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

 

710 - 738 (driectly below above code

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') {

	?>

 

top of script yes

actual code also

 

we need to see some lines before 710, the lines that have your query from $result

Link to comment
https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1310282
Share on other sites

the following is from the beginning of the function to the end of the php tag (which is the whole of the query

 

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') {

	?>

Link to comment
https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1310316
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.