grahamb314 Posted October 22, 2008 Share Posted October 22, 2008 Hi all, The folowing code takes the row "Shows" from a database table and puts it into an option drop down to select from. I want to be able to remove apostrophies: ' and slashes / and \ from the drop down box results, but leave them intact on the database. Any ideas? I thought about making an array of ' / \ and then saying if each row form the query result contains one or more of these, then remove them from the row list but i'm not advanced enough! Thanks! <?php require_once 'mysql_connect.php'; $DJshows = mysqli_query($mysqli, "SELECT * FROM schedule"); str_replace("'", "", "$DJshows"); while ($show = mysqli_fetch_assoc($DJshows)) { echo "<option value=\"{$show['Show']}\">{$show['Show']}</option>"; } //str_replace("'", "", "$show['Show']"); ?> Link to comment https://forums.phpfreaks.com/topic/129604-solved-replace-with-nothing-from-a-query/ Share on other sites More sharing options...
grahamb314 Posted October 22, 2008 Author Share Posted October 22, 2008 Error in the above code: New code: <?php //connect to DB with user and pass require_once 'mysql_connect.php'; //query $DJshows = mysqli_query($mysqli, "SELECT * FROM schedule"); while ($show = mysqli_fetch_assoc($DJshows)) { echo "<option value=\"{$show['Show']}\">{$show['Show']}</option>"; } ?> Link to comment https://forums.phpfreaks.com/topic/129604-solved-replace-with-nothing-from-a-query/#findComment-671906 Share on other sites More sharing options...
discomatt Posted October 22, 2008 Share Posted October 22, 2008 Try while ($show = mysqli_fetch_assoc($DJshows)) { $show['Show'] = str_replace( array('\\','/','\''), '', $show['Show'] ); echo "<option value=\"{$show['Show']}\">{$show['Show']}</option>"; } Link to comment https://forums.phpfreaks.com/topic/129604-solved-replace-with-nothing-from-a-query/#findComment-671911 Share on other sites More sharing options...
grahamb314 Posted October 22, 2008 Author Share Posted October 22, 2008 Works really well, thanks!! Link to comment https://forums.phpfreaks.com/topic/129604-solved-replace-with-nothing-from-a-query/#findComment-671920 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.