angelclawdust Posted January 21, 2012 Share Posted January 21, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/255487-syntax-help-needed/ Share on other sites More sharing options...
AyKay47 Posted January 21, 2012 Share Posted January 21, 2012 post the error that you are receiving Quote Link to comment https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309891 Share on other sites More sharing options...
angelclawdust Posted January 21, 2012 Author Share Posted January 21, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309892 Share on other sites More sharing options...
AyKay47 Posted January 21, 2012 Share Posted January 21, 2012 echo $sql and post the results please. Quote Link to comment https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309898 Share on other sites More sharing options...
angelclawdust Posted January 21, 2012 Author Share Posted January 21, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309903 Share on other sites More sharing options...
AyKay47 Posted January 21, 2012 Share Posted January 21, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309905 Share on other sites More sharing options...
angelclawdust Posted January 21, 2012 Author Share Posted January 21, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309907 Share on other sites More sharing options...
AyKay47 Posted January 21, 2012 Share Posted January 21, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309909 Share on other sites More sharing options...
angelclawdust Posted January 21, 2012 Author Share Posted January 21, 2012 kk i think i know which bits you need - if not just let me know and ill add them 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 Quote Link to comment https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309911 Share on other sites More sharing options...
AyKay47 Posted January 21, 2012 Share Posted January 21, 2012 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" Quote Link to comment https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309913 Share on other sites More sharing options...
Pikachu2000 Posted January 21, 2012 Share Posted January 21, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309915 Share on other sites More sharing options...
angelclawdust Posted January 21, 2012 Author Share Posted January 21, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309919 Share on other sites More sharing options...
Pikachu2000 Posted January 22, 2012 Share Posted January 22, 2012 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"? Quote Link to comment https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309923 Share on other sites More sharing options...
angelclawdust Posted January 22, 2012 Author Share Posted January 22, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1309933 Share on other sites More sharing options...
angelclawdust Posted January 23, 2012 Author Share Posted January 23, 2012 so does this mean that there is a problem with the table im calling from or is it a problem in my code?? never thought 1 eror would take me 6 days to sort lol Quote Link to comment https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1310246 Share on other sites More sharing options...
AyKay47 Posted January 23, 2012 Share Posted January 23, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1310282 Share on other sites More sharing options...
angelclawdust Posted January 23, 2012 Author Share Posted January 23, 2012 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') { ?> Quote Link to comment https://forums.phpfreaks.com/topic/255487-syntax-help-needed/#findComment-1310316 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.