Jump to content

Help with reversing a value


garteth

Recommended Posts

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!!!

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.