Solved

Check database for similar record

Posted on 2013-01-09
3
154 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 40

Expert Comment

by:Sharath
Comment Utility
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
Comment Utility
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 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now