SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A few formatting queries...

    I was wondering if anyone knew how to resolve the following.

    I am using a database that has stored some information as Submitted. Some entries have these markings around them and some don't. How can I amend a query so that it is always shown correctly as just text.

    And a couple of other quick things I thought I would ask, seeing as they're kind of related:

    I have an auto-id that started at 1, and then is increasing slowly from there. Is there anyway that I can make it 8 digits, so that 1 would be 00000001 and so on from there. Is this something that can be done in the MySQL database or would it need to be done in PHP?

    Lastly, what code would I use to make 0 and 1 into Yes and No when being displayed using PHP?

    Thanks
    Russ

  2. #2
    messing with my mind fristi's Avatar
    Join Date
    Feb 2009
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by slaterino View Post
    I was wondering if anyone knew how to resolve the following.

    I am using a database that has stored some information as Submitted. Some entries have these markings around them and some don't. How can I amend a query so that it is always shown correctly as just text.
    That seems like a char encoding issue. You need to make sure that your webpage has the same char encoding as your database. If for instance your webpage is UTF8 and your DB is just some ISO, the ISO will translate as a strange char.


    Quote Originally Posted by slaterino View Post
    I have an auto-id that started at 1, and then is increasing slowly from there. Is there anyway that I can make it 8 digits, so that 1 would be 00000001 and so on from there. Is this something that can be done in the MySQL database or would it need to be done in PHP?
    What is the point in that??? 00000000001 will translate as 1 in every way you will use it :/ except string... but that wouldn't make sense...


    Quote Originally Posted by slaterino View Post
    Lastly, what code would I use to make 0 and 1 into Yes and No when being displayed using PHP?

    Thanks
    Russ

    PHP Code:
    if ($var === 0) echo 'No';
    if (
    $var === 1) echo 'Yes'

    Or you could use replacements like preg or str ...
    Depends on what you need exactly.
    To PHP or to Perl, that is the question!
    (Bucket - simpletest) User

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to pad a number with zeros, you can use str_pad() or printf/sprintf.

    you can also search mysql zerofill, although I would do this in php if your purpose is for display.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •