Forum Moderators: coopster

Message Too Old, No Replies

Formatting data when retrieving from MySQL

Where can I find info on this?

         

RRRonnie

10:43 pm on Dec 27, 2003 (gmt 0)

10+ Year Member



When I select data from MySQL I use the following to format the date:

$result = mysql_query("SELECT DATE_FORMAT(date, '%d %M %Y')",$db);

Is there a way to also format a URL, as I have in my db a field called PartyURL where I have stored the website. eg: www.domainname.com

When retrieving the data I want to have it formatted like [domainname.com...] and of course it should be a hyperlink.

Or do I have to format it why displaying it in a table?

Thanks in advance.

dmorison

9:48 am on Dec 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>>Or do I have to format it why displaying it in a table?

I would.

Leave the database to do what it does best - storing stuff. Your presentation of that data is best done away from the database.

Be aware that if you are storing a URL without the protocol component (i.e. [)...] then you will not be able to store URLs to secure sites (unless the site in question redirects automatically). I would store the protocol in the database also.

If you have end users inputting a URL into a form; it is easy to look at the input and see if they have entered "http" at the start. If they have not then you can assume a plain HTTP site and add "http://" to the start of the URL. This will allow people to add secure sites if they wish...

RRRonnie

10:44 am on Dec 30, 2003 (gmt 0)

10+ Year Member



Found the following solution and is working fine:

<TD><A HREF="http://<?echo($myrow['PartyURL']);?>" TARGET="_new"><?echo($myrow['PartyURL']);?></A></TD>

Thanks anyhow. Ronnie

slade7

2:32 pm on Dec 30, 2003 (gmt 0)

10+ Year Member



If you have users inputting urls, If you tell them to put in the http:// -- half of them will and the other half still won't.

I just use a string function to replace automatically if necessary