Jump to content

Trouble with selecting and dates


ondi

Recommended Posts

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++;
}

?>

Link to comment
https://forums.phpfreaks.com/topic/119468-trouble-with-selecting-and-dates/
Share on other sites

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.