Ok not sure if this was ment for SQL or here but it goes in a php tag so im putting it here... Ok there is a database field that holds a number like 111-252-51 The first number sorts it by Type , then Brand - Then model How would I make it so it will only pull by specfic parts of this and sort it like that?
Assuming all numbers will be in the same format as your example (except different digits). <?php $number = "111-252-51"; preg_match("/([0-9]{3})-([0-9]{3})-([0-9]{2})/", $number, $parts); $type = $parts[1]; $brand = $parts[2]; $model = $parts[3]; ?> PHP: Now you have each part in a variable.
Hi, it's better to redesing your database, so Type , Brand and Model will be separated integer fields. Regards
Yeah. The way suggested by Danx10 is a fix for your problem, although the easier way is to create seperate Integer fields in the database, and when you need to combine the numbers, simply $combined = $type . '-' . $brand . '-' . $model; PHP:
That all works good, now I need one more thing I need to have it pull from database XXX-THIS-XXXXXX I need it to pull only the center line and all of them that have the same number. How do I make it sort though like that and ignore the rest.
<?php $str = "XXX-THIS-XXXXXX"; preg_match("/(.+)\-(.+)\-(.+)/", $str, $parts); $center = $parts[2]; echo $center; ?> PHP:
I don't see how this will do it, Let me show a better example of what I need to do 11-142-13452 - Product Name - Product Description - Price 11-142-13453 - Product Name - Product Description - Price 11-142-13451 - Product Name - Product Description - Price 11-143-31452 - Product Name - Product Description - Price Lets say I wanted to pull all rows of 142 and use every field I need to be able to use the other this when I pull a array of products.