Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Check database for similar record

Posted on 2013-01-09
3
156 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
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 109

Accepted Solution

by:
Ray Paseur earned 500 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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 a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

839 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