Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Check database for similar record

Posted on 2013-01-09
3
Medium Priority
?
163 Views
Last Modified: 2013-02-07
I am working on a ticket tracking system for a baseball team. All of their season ticket holders are in the database. Players are assigned ticketholders to sell tickets to so the query pulls up everyone assigned to a player that bought a ticket in 2012.

They can click on Renew and change the year to 2013 and it will show that the ticket holder bought in 2013 and show in a list at the top of the same page.

What I would like to have is when they renew, have a field in database (Renewed) be marked as YES so when the print their call list, they know who has renewed this year.

This is my update SQL...
      $sql = "UPDATE Passes1 SET THID='$THID', MoneyCollectedDate='$MoneyCollectedDate', Year='$Year', Buddy='$Buddy', Charity='$Charity', Comments='$Comments', CheckNumber='$CheckNumber', TicketNumber='$TicketNumber', TicketType='$TicketType', AmtCollected='$AmtCollected' WHERE PassID='$contacts_id'";
            $update_result = mysql_query($sql);
                    if (!($update_result))
                  {
                        echo mysql_error();
                        echo "<br>\n";
                        echo "$sql<br>\n";
                        exit;
                  }

How do I update the row like this as well IF there is a source_id?
$pass_sql = "UPDATE Passes1 SET Renewed='1' WHERE PassID='$source_id'";
0
Comment
Question by:katlees
3 Comments
 
LVL 41

Expert Comment

by:Sharath
ID: 38761336
Do you have additional column as 'Renewed' in your table? If yes, you can update that flag in the first UPDATE statement itself. No need of second UPDATE statement.
0
 

Author Comment

by:katlees
ID: 38761343
Yes, there is a column of Renewed... the first update statement creates the NEW record.. the 2nd update statement would update the current record...

So if there is a record of
ID - 56
Name - Smith
Year -  2012
Renewed - 0

If they click on the renewed and change the year to 2013 a new record would be created with
ID - 57
Name - Smith
Year -  2013
Renewed - 0

And the old record would become
ID - 56
Name - Smith
Year -  2012
Renewed - 1
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 38761541
Make a Google search for this exact phrase: Should I Normalize My Database.  There are arguments on both sides of the question and it is part art and part science.  You will find good and thoughtful reading in the pages that are responsive to that query.  

In the instant case, it looks like your answer would be, "yes" because a data base that has a "renewed" column would ignore the year - a design flaw with confusing consequences.  You might want to have a table of clients, a table of seats, a table of clients-and-seats, etc.  This is actually a fairly well understood design pattern (think MLB, NFL, StubHub, etc) and it is not a simple data base design, but if implemented correctly it will work with flawless precision and accountability.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question