garteth Posted July 8, 2011 Share Posted July 8, 2011 Hi I have the following code: $result = mysql_query("SELECT * FROM smsaudit WHERE smsuser = '" . $_SESSION['SESS_SMS_USER'] . "'"); while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['smsident'] . "</td>"; echo "<td>" . $row['smsdest'] . "</td>"; echo "<td>" . $row['smsreply'] . "</td>"; echo "<td>" . $row['smsidentifier'] . "</td>"; echo "<td>" . $row['smsorigip'] . "</td>"; echo "<td>" . $row['smstext'] . "</td>"; echo "</tr>"; } echo "</table>"; echo "</br>"; ?><br /> What I would like to do is have the output of 'smsident' to be reversed when it appears in the table. Is there any way that I can do this or a much simpler piece of coding that will do the same as t he above does? Please help!!! Quote Link to comment https://forums.phpfreaks.com/topic/241399-help-with-reversing-a-value/ Share on other sites More sharing options...
MasterACE14 Posted July 8, 2011 Share Posted July 8, 2011 as in have it's values rearranged so it's backwards? http://php.net/manual/en/function.strrev.php Quote Link to comment https://forums.phpfreaks.com/topic/241399-help-with-reversing-a-value/#findComment-1239992 Share on other sites More sharing options...
harristweed Posted July 8, 2011 Share Posted July 8, 2011 $result = mysql_query("SELECT * FROM smsaudit WHERE smsuser = '" . $_SESSION['SESS_SMS_USER'] . "' order by smsident DESC"); Quote Link to comment https://forums.phpfreaks.com/topic/241399-help-with-reversing-a-value/#findComment-1239993 Share on other sites More sharing options...
garteth Posted July 8, 2011 Author Share Posted July 8, 2011 I know about the function strrev but could you tell me how I would use it with my coding? I tried . $row strrev['smsident'] but it didnt work. Quote Link to comment https://forums.phpfreaks.com/topic/241399-help-with-reversing-a-value/#findComment-1240075 Share on other sites More sharing options...
jnvnsn Posted July 8, 2011 Share Posted July 8, 2011 TRY: echo "<td>" . strrev($row['smsident']). "</td>"; Quote Link to comment https://forums.phpfreaks.com/topic/241399-help-with-reversing-a-value/#findComment-1240076 Share on other sites More sharing options...
garteth Posted July 11, 2011 Author Share Posted July 11, 2011 That's brilliant thank. If I wanted to strip off the first 5 characters how would I do that? I tried this but it didn't work: echo "<td>" . strrev(substr($row['smsident' ,1,8])). "</td>"; Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/241399-help-with-reversing-a-value/#findComment-1241155 Share on other sites More sharing options...
garteth Posted July 11, 2011 Author Share Posted July 11, 2011 Just realised that the string reversal was not completely successful. I have a date format which I wanted altered 20110523 This reversed as 32501102 but what I wanted was 23052011 I have read about the explode() function and the ability to separate a string into parts and then echo them into the right order, but is there a way of doing this for what I want to accomplish? Can I use the explode function and say characters 1-4 will be named part1, characters 5-6 will be part2, and characters 7-8 will be part3? Quote Link to comment https://forums.phpfreaks.com/topic/241399-help-with-reversing-a-value/#findComment-1241183 Share on other sites More sharing options...
Maq Posted July 11, 2011 Share Posted July 11, 2011 This reversed as 32501102 but what I wanted was 23052011 You have to reformat it with the date function or in SQL. $s = strtotime('20110523'); echo date('dmY', $s); Quote Link to comment https://forums.phpfreaks.com/topic/241399-help-with-reversing-a-value/#findComment-1241520 Share on other sites More sharing options...
garteth Posted July 12, 2011 Author Share Posted July 12, 2011 That would be the right answer but I have realised that I left out a few details. What I really have is the following value in a field within my database: 20110523094726.BmmW The first part is the year/month/day hh:mm:ss I want to be able to strip the .BmmW off of the end and then print the date and time as follows: 09:47:26 23/05/2011 Do you know of any way that I can accomplish this? Would I need to do it before calling: echo "<td>" . $row['smsident'] . "</td>"; *smsident is the field containing the value. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/241399-help-with-reversing-a-value/#findComment-1241712 Share on other sites More sharing options...
garteth Posted July 15, 2011 Author Share Posted July 15, 2011 Hi I have a problem where I want to display all of the SMS messages a user has sent within this month, however the date format within mysql is YYYY-MM-DD. So I think what I would need is a way for the PHP query to get the current month and then select all entries within the DB that correspond to said month. Any ideas on how I would go about solving this issue? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/241399-help-with-reversing-a-value/#findComment-1243100 Share on other sites More sharing options...
Maq Posted July 15, 2011 Share Posted July 15, 2011 There may be a better way but, selecting records for the month of November: SELECT blah FROM table WHERE MONTH(date_field) = 11 Sounds like you might want to add a condition in for the year too. Quote Link to comment https://forums.phpfreaks.com/topic/241399-help-with-reversing-a-value/#findComment-1243103 Share on other sites More sharing options...
garteth Posted July 18, 2011 Author Share Posted July 18, 2011 Brilliant Thank you very much for your help. Quote Link to comment https://forums.phpfreaks.com/topic/241399-help-with-reversing-a-value/#findComment-1244158 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.