Note that there are some explanatory texts on larger screens.

plurals
  1. POphp function/script for combining 2 columns in a database and remove their special characters and spaces
    text
    copied!<p>hi im trying to write a script that will update my database using php</p> <p>i need to combine two columns from the database, remove their special characters and spaces and insert the result inside the third column of my database</p> <pre><code>fn ln result Super- Man sman Bat&amp; Man bman Wonder - Woman wwoman </code></pre> <p>i cant seem to get the result i want with my script</p> <pre><code> &lt;?php include('connect2.php'); $query = mysql_query("SELECT * from alumni"); $query = mysql_fetch_array($query); while($query){ $query[ln] = str_replace(" ", "", $query[ln]); $query[fn] = str_replace(" ", "", $query[fn]); $query[ln] = ereg_replace("[^A-Za-z0-9]", "", $query[ln]); $query[fn] = ereg_replace("[^A-Za-z0-9]", "", $query[fn]); $query[ln] = strtolower($query[ln]); $query[fn] = strtolower($query[fn]); $query[fn] = substr($query[fn],0,1); printf($username = $query[fn] . $query[ln]); mysql_query("UPDATE alumni SET username='$username' WHERE alumni_id = $query[alumni_id]") or die(mysql_error()); } ?&gt; </code></pre> <p>can anyone help me? thanks in advance</p> <p><em><strong></em>***</strong><em>EDIT</em><strong><em>*</em>****</strong> finally got it working</p> <pre><code> &lt;?php include('connect2.php'); $b = mysql_query("SELECT * from alumni"); while($a = mysql_fetch_array($b)){ //echo $a[fn]; $ln = str_replace(" ", "", $a[ln]); $fn = str_replace(" ", "", $a[fn]); $ln = ereg_replace("[^A-Za-z0-9]", "", $ln); $fn = ereg_replace("[^A-Za-z0-9]", "", $fn); $ln = strtolower($ln); $fn = strtolower($fn); $fn = substr($fn,0,1); printf($username = $fn . $ln); mysql_query("UPDATE alumni SET username='$username' where alumni_id = $a[alumni_id]") or die(mysql_error()); } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload