ondi Posted August 13, 2008 Share Posted August 13, 2008 I have this code, and im trying to select the results from the most recent date, but i can't get it to work. Can anyone see where i'm going wrong? Many thanks in advance session_start(); include('admin/user.php'); $connection = mysql_connect("$host","$user","$password") or die(mysql_error()); mysql_select_db("$txt_db_name",$connection) or die(mysql_error()); // //Includes preferences // $pref = mysql_query("SELECT * FROM tplls_preferences WHERE ID = '1'",$connection) or die(mysql_error()); $pdata = mysql_fetch_array($pref); mysql_free_result($pref); $team_name = $pdata['teamname']; $d_seasonid = $pdata['defaultseasonid']; $show_all_or_one = $pdata['defaultshow']; $show_table = $pdata['defaulttable']; $language = $pdata['defaultlanguage']; $for_win = $pdata['forwin']; $for_draw = $pdata['fordraw']; $for_lose = $pdata['forloss']; $print_date = $pdata['printdate']; $top_bg = $pdata['topoftable']; $bg1 = $pdata['bg1']; $bg2 = $pdata['bg2']; $inside_c = $pdata['inside']; $border_c = $pdata['bordercolour']; $tb_width = $pdata['tablewidth']; $accept_ml = $pdata['acceptmultilanguage']; ?> <?php get_matches = mysql_query(" SELECT O.OpponentName AS hometeam, OP.OpponentName AS awayteam, LM.LeagueMatchHomeGoals AS goals_home, LM.LeagueMatchAwayGoals AS goals_away, LM.LeagueMatchID AS id, LM.LeagueMatchDate AS date FROM tplls_leaguematches LM, tplls_opponents O, tplls_opponents OP WHERE O.OpponentID = LM.LeagueMatchHomeID AND OP.OpponentID = LM.LeagueMatchAwayID AND LeagueMatchSeasonID LIKE '1' AND LM.LeagueMatchHomeGoals IS NOT NULL ORDER BY LM.LeagueMatchDate DESC, hometeam",$connection) or die(mysql_error()); $i=0; while($data = mysql_fetch_array($get_matches)) { if($i == 0) { $temp = $data['date']; } if($data['date'] == $temp) { //print match echo"$data[hometeam] - $data[awayteam] $data[goals_home]-$data[goals_away]<br>"; } else { break; } $i++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/119468-trouble-with-selecting-and-dates/ Share on other sites More sharing options...
JonnoTheDev Posted August 13, 2008 Share Posted August 13, 2008 What results are you getting? Quote Link to comment https://forums.phpfreaks.com/topic/119468-trouble-with-selecting-and-dates/#findComment-615427 Share on other sites More sharing options...
ondi Posted August 13, 2008 Author Share Posted August 13, 2008 Well at the moment i'm getting Parse error: syntax error, unexpected '=' in /home/fhlinux222/w/walthamforest-fc.co.uk/user/htdocs/leaguestats/minifixtures2.php on line 69 which might be where im goign wrong :| Quote Link to comment https://forums.phpfreaks.com/topic/119468-trouble-with-selecting-and-dates/#findComment-615435 Share on other sites More sharing options...
JonnoTheDev Posted August 13, 2008 Share Posted August 13, 2008 and what is the code on minifixtures2.php line 69 Quote Link to comment https://forums.phpfreaks.com/topic/119468-trouble-with-selecting-and-dates/#findComment-615440 Share on other sites More sharing options...
ondi Posted August 13, 2008 Author Share Posted August 13, 2008 Oops, i knew i forgot something. It's this, but i cant see anything wrong with it? get_matches = mysql_query(" Quote Link to comment https://forums.phpfreaks.com/topic/119468-trouble-with-selecting-and-dates/#findComment-615445 Share on other sites More sharing options...
JonnoTheDev Posted August 13, 2008 Share Posted August 13, 2008 Look closer get_matches = mysql_query Should be $get_matches = mysql_query Quote Link to comment https://forums.phpfreaks.com/topic/119468-trouble-with-selecting-and-dates/#findComment-615448 Share on other sites More sharing options...
ondi Posted August 13, 2008 Author Share Posted August 13, 2008 thanks for that, now i just get a blank page? ??? Quote Link to comment https://forums.phpfreaks.com/topic/119468-trouble-with-selecting-and-dates/#findComment-615455 Share on other sites More sharing options...
JonnoTheDev Posted August 13, 2008 Share Posted August 13, 2008 Probably because your query is not returning any data! Have you tested the query first from the mysql command line? Quote Link to comment https://forums.phpfreaks.com/topic/119468-trouble-with-selecting-and-dates/#findComment-615464 Share on other sites More sharing options...
ondi Posted August 13, 2008 Author Share Posted August 13, 2008 Please excuse my ignorance, but what is the MySQL command line? Quote Link to comment https://forums.phpfreaks.com/topic/119468-trouble-with-selecting-and-dates/#findComment-615472 Share on other sites More sharing options...
JonnoTheDev Posted August 13, 2008 Share Posted August 13, 2008 mysql > Login to mysql on your server/PC, select your database and enter your query: Linux: mysql -u username -p mysql > use databaseName; mysql > SELECT * FROM tableName; How are you creating your tables? Do you use something like phpmyadmin? If so you can test your queries before you place them into your php code there. Unless its a really simple query you should test your queries through the mysql database server prior to using them in your code. This helps to get indexes correct before using the query. If your application needs to perform well then you may not have the most optimal query first time around. Quote Link to comment https://forums.phpfreaks.com/topic/119468-trouble-with-selecting-and-dates/#findComment-615476 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.