Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

[PHP][MYSQL]Get highest value

Posted on 2009-05-04
3
Medium Priority
?
561 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 2000 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to count occurrences of each item in an array.
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.

704 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