1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

PHP/MySQL - Can you echo an int?

Discussion in 'Programming & Webmastering' started by Akumos, Apr 30, 2012.

  1. Akumos

    Akumos

    Joined:
    Nov 30, 2008
    Messages:
    555 (0.17/day)
    Thanks Received:
    28
    Location:
    Birmingham, England...
    Hi

    playerid and level are both integers... This is my code:

    PHP:
    echo "<center><BR>Results: ".$dbRecord["playerid"].", Level: ".$dbRecord["level"]."</center>";
    And this is my result:

    Results: , Level: (no data)

    Can you echo an Int or do I need to parse it? Is there an easy way?

    Thanks
     
  2. Akumos

    Akumos

    Joined:
    Nov 30, 2008
    Messages:
    555 (0.17/day)
    Thanks Received:
    28
    Location:
    Birmingham, England...
    No worries - I'm halfway there!
     
  3. Jizzler

    Jizzler

    Joined:
    Aug 10, 2007
    Messages:
    4,040 (1.08/day)
    Thanks Received:
    1,093
    Location:
    Geneva, FL, USA
    No, your code looks sound. PHP's automatic type casting handles str/int concatenation without additional logic. Also, if you're getting a record from the database as your variable name implies, it's probably all being treated as a string anyway. Only need to cast to an int when you want to ensure it's being treated as such (Ex: bitwise comparisons, it's very important here).

    It may just be an empty array and the problem is before your echo, or there is no problem - it's just an empty record in your database or your query didn't return any data.

    Can do a print_r( $dbRecord ) or var_dump( $dbRecord ) to display everything that array contains. Post more of your script if you need further assistance.
     
    Akumos says thanks.
    10 Year Member at TPU Crunching for Team TPU
  4. Akumos

    Akumos

    Joined:
    Nov 30, 2008
    Messages:
    555 (0.17/day)
    Thanks Received:
    28
    Location:
    Birmingham, England...
    Thanks Jizzler - that helps alot...

    I'm acutally selecting from different tables... this is what your suggestion produced, which suuggests the data is there but not displaying!

    code:
    PHP:
    echo "<center><BR>Results are: ".$dbRecord[players.playerid].", Level: ".$dbRecord[players.level]."</center>";
            
    print_r$dbRecord );
    Results are: , Level:
    Array ( [0] => 20 [id] => 20 [1] => 22960 [playerID] => 22960 [2] => 10 [galexy] => 10 [3] => 10 [region] => 10 [4] => 10 [system] => 10 [5] => 10 [astro] => 10 [6] => 0 [cc] => 0 [7] => 10 [bk] => 10 [8] => 0 [lt] => 0 [9] => [mt] => [10] => [pst] => [11] => [it] => [12] => [pht] => [13] => [dt] => [14] => [ds] => [15] => [ps] => [16] => [pr] => [17] => [fleet] => [18] => 2012-04-30 [date] => 2012-04-30 [19] => 22960 [playerid] => 22960 [20] => 30.73 [level] => 30.73 )
     
  5. Akumos

    Akumos

    Joined:
    Nov 30, 2008
    Messages:
    555 (0.17/day)
    Thanks Received:
    28
    Location:
    Birmingham, England...
    ok i took out the table name and it works :)

    thanks jizz
     

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)