dennismonsewicz Posted August 19, 2008 Share Posted August 19, 2008 Is there a way to manipulate a query to strip numbers out of a mysql query? Here is some example code I have written: $result = mysql_query("SELECT * FROM test") or die(mysql_error()); $i = 0; $notallowed = "1234567890"; while($i < mysql_num_fields($result)) { $meta = mysql_fetch_field(str_replace($notallowed, "", $result),$i); echo $i . ". " . $meta->name . "<br />"; $i++; } Link to comment https://forums.phpfreaks.com/topic/120363-solved-stripping-numbers-away-from-query/ Share on other sites More sharing options...
dennismonsewicz Posted August 19, 2008 Author Share Posted August 19, 2008 BUMP Link to comment https://forums.phpfreaks.com/topic/120363-solved-stripping-numbers-away-from-query/#findComment-620147 Share on other sites More sharing options...
Mchl Posted August 19, 2008 Share Posted August 19, 2008 Don't quite understand what you're doing, byt $notallowed has to be an array $notallowed = array("0","1","2","3","4","5","6","7","8","9"); And $result is not a string, so you cannot use str_replace on it... Link to comment https://forums.phpfreaks.com/topic/120363-solved-stripping-numbers-away-from-query/#findComment-620151 Share on other sites More sharing options...
dennismonsewicz Posted August 19, 2008 Author Share Posted August 19, 2008 I thought it had to be an array... I am displaying column names in my sql table but some of the columns contain numbers, IE(Name1, Name2). I am wanting to strip out the 1, 2, 3, 4... or whatever number it happens to be. Link to comment https://forums.phpfreaks.com/topic/120363-solved-stripping-numbers-away-from-query/#findComment-620158 Share on other sites More sharing options...
Mchl Posted August 19, 2008 Share Posted August 19, 2008 I'm pretty sure you shouldn't have table like that... echo $i . ". " . str_replace($notallowed,"",$meta->name) . "<br />"; Link to comment https://forums.phpfreaks.com/topic/120363-solved-stripping-numbers-away-from-query/#findComment-620162 Share on other sites More sharing options...
dennismonsewicz Posted August 19, 2008 Author Share Posted August 19, 2008 I know its a retarded way of setting up it the table but its the only solution I can come up with for the project I am working on. Thanks for the help, the script worked like a charm Link to comment https://forums.phpfreaks.com/topic/120363-solved-stripping-numbers-away-from-query/#findComment-620166 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.