oracle259 Posted September 29, 2006 Share Posted September 29, 2006 How can i do multiple mysql loops without having to do while ( ) more than once Link to comment https://forums.phpfreaks.com/topic/22454-multiple-mysql-loops/ Share on other sites More sharing options...
wildteen88 Posted September 29, 2006 Share Posted September 29, 2006 Could you explain in more detail what you're trying to do. ALsi if you want to do a loop within another loop you'll have to use either a while loop, a for loop, foreach loop Link to comment https://forums.phpfreaks.com/topic/22454-multiple-mysql-loops/#findComment-100738 Share on other sites More sharing options...
oracle259 Posted September 29, 2006 Author Share Posted September 29, 2006 ok. I have the following code. The problem is this, say $user = "bob.camsara and $reserved names are bob and sara the output would be %%%.camsara.my question is how can i modify the code to go through the entire result to get %%%.cam%%%%.[code]while ($res = @mysql_fetch_array($result)) { if (stristr(trim($user, $reserved)) { $length = strlen($reserved); for ($k = 1; $k <= $length; $k++) { $percent = "%";}$newuser = eregi_replace($reserved, $percent, trim($user));$percent = " "; } }echo $newuser;[/code] Link to comment https://forums.phpfreaks.com/topic/22454-multiple-mysql-loops/#findComment-100931 Share on other sites More sharing options...
jrodd32 Posted September 29, 2006 Share Posted September 29, 2006 couldn't you use the strpos() function and search for your reserved words and then replace them with the % character Link to comment https://forums.phpfreaks.com/topic/22454-multiple-mysql-loops/#findComment-100964 Share on other sites More sharing options...
oracle259 Posted September 29, 2006 Author Share Posted September 29, 2006 i'm not familiar with strpos how would i go about doing that. Link to comment https://forums.phpfreaks.com/topic/22454-multiple-mysql-loops/#findComment-100970 Share on other sites More sharing options...
jrodd32 Posted September 29, 2006 Share Posted September 29, 2006 strpos(string haystack, string needle) it will return the position of the needle within the haystack.For example:$string1=strpos("The cat sat on the mat", "cat");would return 4 so once you know where in the string the data is that you don't want to display you could simply create a for loop that would print the % character you were using. Link to comment https://forums.phpfreaks.com/topic/22454-multiple-mysql-loops/#findComment-100981 Share on other sites More sharing options...
oracle259 Posted September 29, 2006 Author Share Posted September 29, 2006 ok i read up on strpos but it still failed to account for both reserved names Link to comment https://forums.phpfreaks.com/topic/22454-multiple-mysql-loops/#findComment-100987 Share on other sites More sharing options...
jrodd32 Posted September 29, 2006 Share Posted September 29, 2006 I think that you would have to run it once for each reserved name Link to comment https://forums.phpfreaks.com/topic/22454-multiple-mysql-loops/#findComment-100989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.