while saving in database, if I save A it shouldnot save as A, it should save as 1, for b as 2, it should continue till 26.
How it is possible?
AntonyRayan
15
Posting Whiz in Training
Recommended Answers
Jump to PostWhat about something like:
<?php $letters = range('a', 'z'); $numbers = range(0, 26); echo 'Value before: ' . $value . '<br>'; $value = strtolower($value); // The value in which you want to replace stuff. $value = str_replace($letters, $numbers); echo 'Value after: ' . $value . '<br>';
Jump to PostShouldn't the range be
range(1,26)
?Here's my take...
function convert($value) { $keys = range("A","Z"); $values = range(1, 26); $falseValue = 0; //or false or null etc- decide $conv = array_combine($keys,$values); $value = strtoupper($value); //remove this if not req'd return (isset($conv[$value])) ? $conv[$value] : $falseValue; } …
Jump to PostYou're right, my bad. You cannot set it as a default in PHPMyAdmin/MySQL. You will either have to create a stored procedure for it or edit the data you save every time you save it using PHP (I'd suggest the latter option).
Jump to PostI was confused too as this is posted in the PHP forum. If this has to be a MySQL flavoured SQL solution, it should be posted to the Databases > MySQL forum
Jump to PostOh yeah I wasn't trying to say anything bad about your code, I was just really wondering if it would matter uppercasing or lowercasing the whole string before converting it :).
All 20 Replies
minitauros
151
Junior Poster
Featured Poster
AntonyRayan
15
Posting Whiz in Training
AntonyRayan
15
Posting Whiz in Training
diafol
AntonyRayan
15
Posting Whiz in Training
minitauros
151
Junior Poster
Featured Poster
diafol
minitauros
151
Junior Poster
Featured Poster
AntonyRayan
15
Posting Whiz in Training
diafol
minitauros
151
Junior Poster
Featured Poster
diafol
minitauros
151
Junior Poster
Featured Poster
diafol
AntonyRayan
15
Posting Whiz in Training
diafol
minitauros
151
Junior Poster
Featured Poster
diafol
minitauros
151
Junior Poster
Featured Poster
diafol
commented:
no worries
+15
diafol
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.