Jump to content

Only one record set as default


SweetLou

Recommended Posts

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?
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
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.