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

PHP/MySQL - Can you echo an int?

Joined
Nov 30, 2008
Messages
555 (0.17/day)
Likes
28
Location
Birmingham, England...
Processor Intel Core 2 Quad Q6600 @ 2.8GHz
Motherboard Gigabyte X48T-DQ6
Cooling Zalman 9500 LED CPU Cooler
Memory 2x 2GB Corsair DDR3 XMS3 DHX - 1600MH/PC3-12800
Video Card(s) Gigabyte HD4870 1GB
Storage 2x Seagate 320GB Barracuda (RAID 0) 3x 1TB Samsung F3, 140GB WD Maxtor (10,000rpm)
Display(s) 2x 20" LG Flatron L204WS
Power Supply Powercool 850W
Software Windows 7 Ultimate x64
#1
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
 
Joined
Nov 30, 2008
Messages
555 (0.17/day)
Likes
28
Location
Birmingham, England...
Processor Intel Core 2 Quad Q6600 @ 2.8GHz
Motherboard Gigabyte X48T-DQ6
Cooling Zalman 9500 LED CPU Cooler
Memory 2x 2GB Corsair DDR3 XMS3 DHX - 1600MH/PC3-12800
Video Card(s) Gigabyte HD4870 1GB
Storage 2x Seagate 320GB Barracuda (RAID 0) 3x 1TB Samsung F3, 140GB WD Maxtor (10,000rpm)
Display(s) 2x 20" LG Flatron L204WS
Power Supply Powercool 850W
Software Windows 7 Ultimate x64
#2
No worries - I'm halfway there!
 
Joined
Aug 10, 2007
Messages
4,064 (1.07/day)
Likes
1,130
Location
Geneva, FL, USA
Processor Intel i5-6600
Motherboard ASRock H170M-ITX
Cooling Cooler Master Geminii S524
Memory G.Skill DDR4-2133 16GB (8GB x 2)
Video Card(s) Gigabyte R9-380X 4GB
Storage Samsung 950 EVO 250GB (mSATA)
Display(s) LG 29UM69G-B 2560x1080 IPS
Case Lian Li PC-Q25
Audio Device(s) Realtek ALC892
Power Supply Seasonic SS-460FL2
Mouse Logitech G700s
Keyboard Logitech G110
Software Windows 10 Pro
#3
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.
 
Joined
Nov 30, 2008
Messages
555 (0.17/day)
Likes
28
Location
Birmingham, England...
Processor Intel Core 2 Quad Q6600 @ 2.8GHz
Motherboard Gigabyte X48T-DQ6
Cooling Zalman 9500 LED CPU Cooler
Memory 2x 2GB Corsair DDR3 XMS3 DHX - 1600MH/PC3-12800
Video Card(s) Gigabyte HD4870 1GB
Storage 2x Seagate 320GB Barracuda (RAID 0) 3x 1TB Samsung F3, 140GB WD Maxtor (10,000rpm)
Display(s) 2x 20" LG Flatron L204WS
Power Supply Powercool 850W
Software Windows 7 Ultimate x64
#4
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 )
 
Joined
Nov 30, 2008
Messages
555 (0.17/day)
Likes
28
Location
Birmingham, England...
Processor Intel Core 2 Quad Q6600 @ 2.8GHz
Motherboard Gigabyte X48T-DQ6
Cooling Zalman 9500 LED CPU Cooler
Memory 2x 2GB Corsair DDR3 XMS3 DHX - 1600MH/PC3-12800
Video Card(s) Gigabyte HD4870 1GB
Storage 2x Seagate 320GB Barracuda (RAID 0) 3x 1TB Samsung F3, 140GB WD Maxtor (10,000rpm)
Display(s) 2x 20" LG Flatron L204WS
Power Supply Powercool 850W
Software Windows 7 Ultimate x64
#5
ok i took out the table name and it works :)

thanks jizz