SweetLou Posted January 30, 2007 Share Posted January 30, 2007 I have a table that lists my rugby team's match reports. On the web page, I want to display a "default" match report, then have a menu where users can select a different report. The table consists of 7 fields.[code]report_id game_id report_title game_date game_score report_text default_report[/code]Default_report is a type tinyint(1). If this value is "1", then it is the default and it will be displayed. My question is: Is there a way to make the field default_report only have one record with the value of "1", the rest should be "0", when I set a new record as the default, the old default will be changed to "0"?If that is not possible, and I can only change the values through a query, which way would be best?Should I make all the values in default_report be "0", then update the report I want to be "1"? Something like:[code]$query = "UPDATE match_reports SET default_report='0';mysql_query($query) or die(mysql_error());$query2 = "UPDATE match_reports SET report_title ='" . $report_title . "', game_date='" . $game_date . "', game_score='" . $game_score . "', report_text='" . $report_text . "', default_report='" . $default_report . "' WHERE game_id='" . $game_id . "'"; mysql_query($query2) or die(mysql_error());[/code]Is there a better way? Quote Link to comment Share on other sites More sharing options...
bibby Posted January 30, 2007 Share Posted January 30, 2007 That sounds like something you'd want to delagate to your php, not your table.How easy is this?[code]$defaultReportID = 7;[/code] Quote Link to comment Share on other sites More sharing options...
SweetLou Posted January 30, 2007 Author Share Posted January 30, 2007 Well, that sounds good, but we want the latest match's report to be the default report to be shown on the site. So, the default report should change weekly during the season, unless the person in charge of updating the match reports doesn't do it.I was thinking about doing it by date, but that won't be good, because we could have records for future games already in the database. Quote Link to comment Share on other sites More sharing options...
fenway Posted January 30, 2007 Share Posted January 30, 2007 Just have another table with the defaults. Quote Link to comment Share on other sites More sharing options...
SweetLou Posted January 30, 2007 Author Share Posted January 30, 2007 Sorry, I am not sure what you mean by that. Quote Link to comment Share on other sites More sharing options...
SweetLou Posted January 31, 2007 Author Share Posted January 31, 2007 I think I understand what you mean, it just dawned on me. Instead of having a field of default_record, create a new table. That table would be set up something like default_record, and the value would be the report_id. Then I could do a query to get the report_id and then pull that record to show? If that is what you meant, that makes sense. and should be easy to do. Quote Link to comment Share on other sites More sharing options...
fenway Posted January 31, 2007 Share Posted January 31, 2007 That's exactly what I mean... sorry if I was too vague. Quote Link to comment 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.