Solved

[PHP][MYSQL]Get highest value

Posted on 2009-05-04
3
552 Views
Last Modified: 2012-05-06
In PHP I have a table with rows. The rows are currently within a SQL database and are stored by a value call position in which the will be loaded with ORDER BY ASC(position).
What I am having trouble doing is finding the row with the highest value of position WHERE parentseries='$parent' AND category='$category'

I need to do this when I am  adding a new variable. In a sort it's an auto increment of my own. But I cannot use normal auto Increment as this table is shared with other product tables.

example of table:
parentseries    |    category    |    data    |    position
1721                  14                      ...            1
1721                  14                      ...            2
1532                  14                      ...            1
1532                  14                      ...            2

What now want to happen is if I add another category 14 item that it will find all other category 14 items that are parentseries 1721 and find which one has the highest position integer.

Thank you.
0
Comment
Question by:drakeshe
[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
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
jausions earned 500 total points
ID: 24300490
SELECT MAX(position) FROM myTable WHERE parentseries='$parent' AND category='$category'

You also want to make sure you're using a database engine that support transactions (InnoDB for instance) otherwise there's a slight chance you could run the same query at exactly the same moment and then insert the same "position" twice for different record. That of course would depend on the traffic on your database and how often you do this kind of INSERT
0
 
LVL 5

Author Closing Comment

by:drakeshe
ID: 31577818
Thank you! This worked perfectly! Exactly what I needed
0
 
LVL 5

Author Comment

by:drakeshe
ID: 24300537
Thank you! It worked perfectly! Exactly what I needed
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

This article discusses how to implement server side field validation and display customized error messages to the client.
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

752 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