pagegen Posted March 24, 2010 Share Posted March 24, 2010 Hi guys, I have a double nested loop.. The issue here is, if(str_replace(" ", "", $row_dataset['numbers']) == str_replace(" ", "", $tps_num)) { $row_dataset['numbers'] is "01125336538" and $tps_num is also "01125336538" but the if statment wont echo what its spose too.. while($row_dataset = mysql_fetch_array($result_get_dataset)){ while($row_tps = mysql_fetch_array($result_get_tps)){ $test++; $tps_num = $row_tps['numbers']; if(str_replace(" ", "", $row_dataset['numbers']) == str_replace(" ", "", $tps_num)) { $tps_numbers = $tps_numbers . $row_tps['numbers']; echo $current_number . " | " . $row_tps['numbers'] . "<br/>"; } } } Quote Link to comment Share on other sites More sharing options...
pagegen Posted March 24, 2010 Author Share Posted March 24, 2010 All help will be usefull guys, any suggestions at all? Quote Link to comment Share on other sites More sharing options...
teamatomic Posted March 24, 2010 Share Posted March 24, 2010 str_replace does not return 1/0 or TRUE/FALSE, it returns the string it work on. So if it does not work as you expected its possible that your string are not ==. Depending on where tps_num comes from perhaps trimming it would help. HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
pagegen Posted March 24, 2010 Author Share Posted March 24, 2010 Hi I have changed the code while($row_dataset = mysql_fetch_array($result_get_dataset)){ $current_number = str_replace(" ", "", $row_dataset['numbers']); while($row_tps = mysql_fetch_array($result_get_tps)){ $test++; $tps_num = str_replace(" ", "", $row_tps['numbers']); if($current_number == $tps_num) { $tps_numbers = $tps_numbers . $row_tps['numbers']; echo $current_number . " | " . $row_tps['numbers'] . "<br/>"; echo "match found"; } echo $current_number . " | " . $row_tps['numbers'] . "<br/>"; } } without the if it does echo the both numbers 01125336538 | 01125336538 bit with the if, nothing happens.. Quote Link to comment Share on other sites More sharing options...
priti Posted March 24, 2010 Share Posted March 24, 2010 you are printing echo $current_number . " | " . $row_tps['numbers'] . "<br/>"; try echo $current_number . " | " . $tps_num . "<br/>"; Quote Link to comment Share on other sites More sharing options...
pagegen Posted March 24, 2010 Author Share Posted March 24, 2010 Hi, just tried that, no luck Quote Link to comment Share on other sites More sharing options...
pagegen Posted March 24, 2010 Author Share Posted March 24, 2010 i have also tried $current_number = "01125336538"; if($row_tps['numbers'] == $current_number) no luck with that either.. but if I echo $row_tps['numbers'] its the same number... Quote Link to comment Share on other sites More sharing options...
teamatomic Posted March 24, 2010 Share Posted March 24, 2010 Change the if comparison to != and see what happens. HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
priti Posted March 24, 2010 Share Posted March 24, 2010 01125336538 | 01125336538 Can you remove those leading zero and try... It may be possible that these number are internally taken as octal... so either you can cast your these two number in int and then compare.. or just give a try removing those leading zeros. Quote Link to comment Share on other sites More sharing options...
pagegen Posted March 24, 2010 Author Share Posted March 24, 2010 while($row_dataset = mysql_fetch_array($result_get_dataset)){ $current_number = str_replace(" ", "", $row_dataset['numbers']); if ( $current_number{0} == "0" ) $current_number = substr($current_number, 1); while($row_tps = mysql_fetch_array($result_get_tps)){ $test++; $tps_num = str_replace(" ", "", $row_tps['numbers']); if ( $tps_num{0} == "0" ) $tps_num = substr($tps_num, 1); if($current_number == $tps_num) { $tps_numbers = $tps_numbers . $row_tps['numbers']; echo $current_number . " | " . $tps_num . "<br/>"; echo "match found"; } echo $current_number . " | " . $tps_num . "<br/>"; } } Just removed the 1st character of both when echoed without if() 1125336538 | 1125336538 when if used, nothing Quote Link to comment Share on other sites More sharing options...
pagegen Posted March 24, 2010 Author Share Posted March 24, 2010 Change the if comparison to != and see what happens. HTH Teamatomic Tried this if($current_number != $tps_num) { the following is the echo.. 1125336538 | 1125336538 match found Quote Link to comment Share on other sites More sharing options...
teamatomic Posted March 24, 2010 Share Posted March 24, 2010 Then trim the vars before you use them HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
pagegen Posted March 24, 2010 Author Share Posted March 24, 2010 Then trim the vars before you use them HTH Teamatomic That seems to work Thanks alot guys for all your help,, really really helped Quote Link to comment 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.