PHP/MySQL Resulting Values
Posted by: caydee (---.dip0.t-ipconnect.de)
Date: May 05, 2015 06:49PM

Hi RiggsFolly,

Here's an old fan of yours and here are greetings of the season!

I have a database and in that is a table of itineraries with some and some columns show the "Number of Hotel Nights" or the "Number of Houseboat Nights" or the "Number of Trekking Days" and so on. The values are either 2 digits or just one digit.

Now, when I query and pull a value it shows correctly the value in the database a single or a double digit. But I want it to always show the value as a double digit e.g: 07 or 09 or 04 etc (when it is a single digit value). The 2 digit values are fine. It doesn't store the values as double digits even if I manually enter these as 01, 02, 03, etc. I am not sure what it is storing the values as Text or Integer or how to tamper with it..

Is there an easy way to fix it?

To your health and high spirits,

Caydee

Caydee

IN ALL THINGS BE MEN
Windows 10 x64 | WAMP 3.3.2 - x64 | Apache 2.4.58 | MySQL 8.2.0 | PHP 8.2.13 | PHPMyAdmin 5.2.0

Options: ReplyQuote
Re: PHP/MySQL Resulting Values
Posted by: caydee (---.dip0.t-ipconnect.de)
Date: May 05, 2015 07:13PM

Hi,

I just checked and changed the value:
ALTER TABLE `itinerary` CHANGE `Hotel Nights` `Hotel Nights` TINYINT(2) NULL DEFAULT NULL, CHANGE `Houseboat Nights` `Houseboat Nights` INT(2) NULL DEFAULT NULL, CHANGE `Trekking & Camping Days` `Trekking & Camping Days` INT(2) NULL DEFAULT NULL;
or should I change it to something else as this does not change the result.

Caydee

Options: ReplyQuote
Re: PHP/MySQL Resulting Values
Posted by: RiggsFolly (---.as43234.net)
Date: May 06, 2015 12:49AM

Hi,

I would use the PHP code to format the numbers rather than change the database.

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: PHP/MySQL Resulting Values
Posted by: caydee (---.dip0.t-ipconnect.de)
Date: May 06, 2015 06:57PM

Hi,

Thank you!

"format the numbers" reminded me that I had used it before. After that it was easy enough.

So I used it like this:
 <p>
          <?php  if( isset($row_rsItinerary['Houseboat Nights']) && $row_rsItinerary['Houseboat Nights'] >0) { ?>
          <li><span class="big"><?php echo sprintf('%02d', $row_rsItinerary['Houseboat Nights']); ?></span> Night/s in Deluxe Houseboats with Double | Twin | Single Occupancy on Full Boarding &amp; Lodging basis.</li>
            <?php } ?>          
        </p>

Have a nice evening!

Caydee

Options: ReplyQuote


Sorry, only registered users may post in this forum.