gc5483 Posted May 9, 2007 Share Posted May 9, 2007 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>'; } } Link to comment https://forums.phpfreaks.com/topic/50673-converting-value-of-email_id-varchar-field-in-mysql-database-to-ascii-code/ Share on other sites More sharing options...
obsidian Posted May 9, 2007 Share Posted May 9, 2007 I would recommend doing the translation within MySQL before you pull it out: SELECT ASCII(email_id) FROM registration_details; Link to comment https://forums.phpfreaks.com/topic/50673-converting-value-of-email_id-varchar-field-in-mysql-database-to-ascii-code/#findComment-249086 Share on other sites More sharing options...
soycharliente Posted May 9, 2007 Share Posted May 9, 2007 There is also a function to give you the ascii value of a character, but obsidian's way is better. http://us.php.net/manual/en/function.ord.php Link to comment https://forums.phpfreaks.com/topic/50673-converting-value-of-email_id-varchar-field-in-mysql-database-to-ascii-code/#findComment-249088 Share on other sites More sharing options...
gc5483 Posted May 9, 2007 Author Share Posted May 9, 2007 $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. Link to comment https://forums.phpfreaks.com/topic/50673-converting-value-of-email_id-varchar-field-in-mysql-database-to-ascii-code/#findComment-249114 Share on other sites More sharing options...
obsidian Posted May 9, 2007 Share Posted May 9, 2007 $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' Link to comment https://forums.phpfreaks.com/topic/50673-converting-value-of-email_id-varchar-field-in-mysql-database-to-ascii-code/#findComment-249116 Share on other sites More sharing options...
gc5483 Posted May 9, 2007 Author Share Posted May 9, 2007 Now its displaying ascii value of the first charcter only.but i have to use the value of the whole string . Link to comment https://forums.phpfreaks.com/topic/50673-converting-value-of-email_id-varchar-field-in-mysql-database-to-ascii-code/#findComment-249137 Share on other sites More sharing options...
obsidian Posted May 9, 2007 Share Posted May 9, 2007 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/50673-converting-value-of-email_id-varchar-field-in-mysql-database-to-ascii-code/#findComment-249162 Share on other sites More sharing options...
gc5483 Posted May 9, 2007 Author Share Posted May 9, 2007 Thnax obsidian nd charlieholder . I think now I will be able to do that. Link to comment https://forums.phpfreaks.com/topic/50673-converting-value-of-email_id-varchar-field-in-mysql-database-to-ascii-code/#findComment-249185 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.