PHP Query

I need to write a Query that grabs a number from a specific table but I'm not sure how to write it.

The table entry that I need to look at has the following;
entry_id, title, url_title
there are entries in this table ;
entry_id = 353
title = 230
url_title = order_230

entry_id = 354
title = 231
url_title = order_231

entry_id = 355
title = 232
url_title = order_232

I need to write a query that grabs the title value and add 1 to it title +1 where the url_title has the highest value.  
So from the data above I would need to write something like;
<?php
$Q = SELECT title
FROM My-Table
WHERE url_title Contains order_% That is the highest value.

Open in new window

The query needs to contain the order_ part cause not every entry in that field is formatted the same way.  There are other title formats.
Does this make sense?
LVL 7
rgranlundAsked:
Who is Participating?
 
Chris StanyonCommented:
Not entirely sure what you're trying to do, but have a look at this and see if does what you need:

// Select the record with the highest title where url_title starts with order_
SELECT title FROM yourTable WHERE LEFT(url_title, 6) = "order_" ORDER BY title DESC LIMIT 1;

// Update the record with highest title by adding 1 to the current value
UPDATE yourTable SET title = title +1 WHERE LEFT(url_title, 6) = "order_" ORDER BY title DESC LIMIT 1;
0
 
Chris StanyonCommented:
Does the number in the title column ALWAYS match the number from the url_title column?
0
 
rgranlundAuthor Commented:
Yes.
0
 
rgranlundAuthor Commented:
I think this is what I need.  For clarification, what does the "6" represent? (LEFT(url_title, 6))
0
 
Chris StanyonCommented:
LEFT(url_title, 6) means the 6 leftmost characters of the url_title field (which would match order_)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.