Solved

Check database for similar record

Posted on 2013-01-09
3
159 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
[X]
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
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 110

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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

632 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