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 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 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 PostWhat do you mean, exactly?
Your string functions should be faster than my array_combine(). However thinking about it, you're using arrays in your string functions too, so not sure. Be interesting to do a time comparison.
Jump to PostHere's the test...
$start = microtime(true); 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; } echo convert('C'); $end = …
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.