Jump to content

Converting value of 'email_id ' (varchar field) in mysql database to ascii code


Recommended Posts

 

Hi all,

 

I want to use value of 'email_id' (varchar field) in mysql database to covert into respective ascii code so that it can be used for future purpose.a part of my code is given below.can someoone guide me how to do that as I am new to PHP.I ma using PHP5.2 with mysql 5.0 nd IIS 6.0.

 

$result2 = mysql_query("SELECT * FROM registeration_details WHERE activation_status='NO'" );

 

while($row = mysql_fetch_array($result2) )

{

if($row['activation_status']=='NO')

{

$row['email_id'].'</br>';------------>email_id which is a DB field  is to be displayed as ascii in php

//echo cast($row['email_id'] AS ascii ).'</br>';

}

}

$result2 = mysql_query("SELECT ASCII(email_id) , activation_status FROM registeration_details WHERE activation_status='NO'" );

 

while($row = mysql_fetch_array($result2) )

{

if($row['activation_status']=='NO')

{

        echo $row['email_id'].'</br>';

}

}

 

 

I have just tried this but now its not printing the corresponding ascii values.

$result2 = mysql_query("SELECT ASCII(email_id) , activation_status FROM registeration_details WHERE activation_status='NO'" );

 

while($row = mysql_fetch_array($result2) )

{

if($row['activation_status']=='NO')

{

        echo $row['email_id'].'</br>';

}

}

 

 

I have just tried this but now its not printing the corresponding ascii values.

 

You have to name the column to output it as you are trying:

SELECT ASCII(email_id) as email_id, activation_status FROM registeration_details WHERE activation_status='NO'

Now its displaying ascii value of the first charcter only.but i have to use the value of the whole string .

 

Ah, I see. You would be better of doing something like this, then, since the field will be varying length:

<?php
$q   = "SELECT email_id, activation_status FROM registeration_details WHERE activation_status='NO'";
$sql = mysql_query($q);
while ($row = mysql_fetch_assoc($sql)) {
  for ($i = 0; $i < strlen($row['email_id']); $i++) {
    echo ord($row['email_id']{$i});
  }
  echo "<br />\n";
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.