BluePhoenixNC Posted June 22, 2006 Share Posted June 22, 2006 Sorry, but I did not know how to make the header say what I need. I am trying to do a lookup of a value. The situation is the following: I have the VIN (something like MHASCH21051035272) and I have a table setup like that: ID VIN_ID Model Category1 LYD1C model1 12 YCBL1 model2 13 KCAL3 model3 14 LZH1A model4 15 YAEL1 model5 16 YCFL1 model6 17 JCHL1 model7 18 JCJL1 model8 19 JCKL1 model9 110 JCML0 model10 111 SCBL1 model11 212 SCHZ1 model12 213 SCH21 model13 2...Now what I want to do is see if a value of VIN_ID is contained within the VIN and then give me the table row. I assume I have to do something like: [code]$mystring ='MHASCH21051035272';$findme = 'SCH21'; // loop through table to get those values$pos = strpos($mystring, $findme);[/code]Any help in this matter is greatly appreciated and I appologize for the lengthy post, but I would not know how to explain it better than by examples.Thank you Quote Link to comment https://forums.phpfreaks.com/topic/12655-pos-how-to-question/ Share on other sites More sharing options...
.josh Posted June 22, 2006 Share Posted June 22, 2006 have sql do it for you. [code]$findme = 'SCH21';$sql = "select * from table where VIN_ID like '%$findme%'";$result = mysql_query($sql);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12655-pos-how-to-question/#findComment-48551 Share on other sites More sharing options...
BluePhoenixNC Posted June 22, 2006 Author Share Posted June 22, 2006 [!--quoteo(post=386921:date=Jun 22 2006, 02:13 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ Jun 22 2006, 02:13 PM) [snapback]386921[/snapback][/div][div class=\'quotemain\'][!--quotec--]have sql do it for you. [code]$findme = 'SCH21';$sql = "select * from table where VIN_ID like '%$findme%'";$result = mysql_query($sql);[/code][/quote]Crayon: thank you for your reply, that is what I eventually want to do, but first I want to "validate" the VIN. In other words, I want to see if the string in VIN_ID can be found in the VIN. For that I need to check the entire column VIN_ID against the VIN and see if any of those can be found in the VIN, if this makes any sense. Quote Link to comment https://forums.phpfreaks.com/topic/12655-pos-how-to-question/#findComment-48556 Share on other sites More sharing options...
zq29 Posted June 22, 2006 Share Posted June 22, 2006 [!--quoteo(post=386926:date=Jun 22 2006, 07:36 PM:name=Blue Phoenix)--][div class=\'quotetop\']QUOTE(Blue Phoenix @ Jun 22 2006, 07:36 PM) [snapback]386926[/snapback][/div][div class=\'quotemain\'][!--quotec--]Crayon: thank you for your reply, that is what I eventually want to do, but first I want to "validate" the VIN. In other words, I want to see if the string in VIN_ID can be found in the VIN. For that I need to check the entire column VIN_ID against the VIN and see if any of those can be found in the VIN, if this makes any sense.[/quote]Thats what Crayons code does... Searches all of the VIN_ID's in the database and returns all of the VIN_IDs that are found within the VIN held in $findme. You can just return a count if you like with:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] [color=blue]COUNT[/color](*) [color=green]FROM[/color] [color=orange]`table`[/color] [color=green]WHERE[/color] `VIN_ID` [color=orange]LIKE[/color] [color=red]'%$findme%'[/color] [!--sql2--][/div][!--sql3--]If that query returns a number higher than 0, you have a match. Quote Link to comment https://forums.phpfreaks.com/topic/12655-pos-how-to-question/#findComment-48559 Share on other sites More sharing options...
BluePhoenixNC Posted June 22, 2006 Author Share Posted June 22, 2006 [!--quoteo(post=386929:date=Jun 22 2006, 02:55 PM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Jun 22 2006, 02:55 PM) [snapback]386929[/snapback][/div][div class=\'quotemain\'][!--quotec--]Thats what Crayons code does... Searches all of the VIN_ID's in the database and returns all of the VIN_IDs [/quote]Semi: Thank you, too. I think I confused you guys more than necessary> I appologize, English is not my native language and php/mysql well... let's just say... n00b hits it.. ;) let me try that again and hopefully I make more sense now: $mystring ='MHASCH21051035272'; // the only known value and "static" user typed that in$findme = $something out of the table; // loop through table to get those values$pos = strpos($mystring, $findme);so what I want to know is: "is in the variable $mystring any of the "strings" contained in the tablecolumn VIN_ID ?Column Vin_ID has just that part of the vin which indicates the Model, therefore I need to find a match and it needs to loop through the table to return a result. I should get a match at position (ID) 13 since SCH21 can be found in $mystring all others do not match.... Does that make more sense ? Again my apologies for making things more complicated than they need to be. Quote Link to comment https://forums.phpfreaks.com/topic/12655-pos-how-to-question/#findComment-48570 Share on other sites More sharing options...
.josh Posted June 22, 2006 Share Posted June 22, 2006 example:[code]<?php$vin = "MHASCH21051035272";$sql = "select VIN_ID from table";$result = mysql_query($sql);$found = FALSE;while ($list = mysql_fetch_array($result)) { $pattern = "/" . $list['VIN_ID'] . "/i"; if (preg_match($pattern, $vin)) { echo "found" . $list['VIN_ID'] . "<br>"; $found = TRUE; }}if ($found == FALSE) { echo "no matches found.";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12655-pos-how-to-question/#findComment-48587 Share on other sites More sharing options...
BluePhoenixNC Posted June 22, 2006 Author Share Posted June 22, 2006 [!--quoteo(post=386961:date=Jun 22 2006, 04:22 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ Jun 22 2006, 04:22 PM) [snapback]386961[/snapback][/div][div class=\'quotemain\'][!--quotec--][/quote]Crayon: Thank you very much :) That was exactly what I was looking for..... now I have to do some readup on php.net to fully understand your code example..... :) but it works out the box..... :) Thanks again... Quote Link to comment https://forums.phpfreaks.com/topic/12655-pos-how-to-question/#findComment-48604 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.