macinslaw Posted September 24, 2007 Share Posted September 24, 2007 I have a simple query that I am restricting to the first 4 character, however instead of the first 4 characters I am getting only the characters from the end of the field. The information in the field resembles: 4285-002 My result should be: 4285 What I am getting is: -002 The following is the code to pull the dat from field 'Dest': $dest=odbc_result($rs1, 'Destination'); $deststrcount=1; $deststr = $dest; $deststr = str_split($deststr,4); foreach($deststr as $destv){ if ($deststrcount<="1"){ $desttext=$destv; $destnew = "DEST[1,$deststrcount]\t$desttext\r\n"; $strcount=$strcount+1; } -Thanks for your help. Mac Quote Link to comment https://forums.phpfreaks.com/topic/70471-strange-result-from-table-query/ Share on other sites More sharing options...
macinslaw Posted September 24, 2007 Author Share Posted September 24, 2007 BUMP - Please assist. Quote Link to comment https://forums.phpfreaks.com/topic/70471-strange-result-from-table-query/#findComment-354101 Share on other sites More sharing options...
cooldude832 Posted September 24, 2007 Share Posted September 24, 2007 explode at that - and then take the first half of the explosion. Quote Link to comment https://forums.phpfreaks.com/topic/70471-strange-result-from-table-query/#findComment-354103 Share on other sites More sharing options...
macinslaw Posted September 24, 2007 Author Share Posted September 24, 2007 Pardon? Quote Link to comment https://forums.phpfreaks.com/topic/70471-strange-result-from-table-query/#findComment-354119 Share on other sites More sharing options...
macinslaw Posted September 24, 2007 Author Share Posted September 24, 2007 Guys, all I need to know is why the dashes causes this and what I need to do to keep it from happening, surely someone has some knowledge on this. Quote Link to comment https://forums.phpfreaks.com/topic/70471-strange-result-from-table-query/#findComment-354151 Share on other sites More sharing options...
cooldude832 Posted September 24, 2007 Share Posted September 24, 2007 your code lacks solid structure, and i said $string = explode("_",$string); $string[0] = //Predash $string[1] = //post dash If you don't know what explode is maybe you should look it up. Quote Link to comment https://forums.phpfreaks.com/topic/70471-strange-result-from-table-query/#findComment-354214 Share on other sites More sharing options...
macinslaw Posted September 24, 2007 Author Share Posted September 24, 2007 Okay, sorry....I now understand what the "explode" post meant above, unfortunately, I cannot for the life of me find out how to do what I want to do. Cooldude, thanks so much for following up with your second post. I have the code and understand now what you were trying to tell me. I have the hardest time following the foo examples that are the lifeline to these programming languages, I learn best by point blank example and trial and error. Thanks so much for your time and your effort on this issue. I owe you one. -Mac Quote Link to comment https://forums.phpfreaks.com/topic/70471-strange-result-from-table-query/#findComment-354226 Share on other sites More sharing options...
cooldude832 Posted September 24, 2007 Share Posted September 24, 2007 this line: $deststr = $dest; is pointless, just say $string = explode("_",$deststr,4); $number = $string[1]; and echo out $number to see it. A lot of functions you think you have to build on your own for strings/arrays pre exsit and you just have to find them. Quote Link to comment https://forums.phpfreaks.com/topic/70471-strange-result-from-table-query/#findComment-354229 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.