Reputation: 135
I want to fetch some info from my database, and choose which of the info in the string, I want to display.
--- What I know so far ---
This code is showing me NULL
value:
$ticketis = mysql_query("SELECT `module` FROM games ORDER BY `id` DESC LIMIT 1,1");
$showticket = mysql_fetch_assoc($ticketis);
$rest = mb_substr($showticket,0,30);
var_dump($rest);
AND this code is showing me the data-string I want to cut out specific data from:
$ticketis = mysql_query("SELECT `module` FROM games ORDER BY `id` DESC LIMIT 1,1");
$showticket = mysql_fetch_assoc($ticketis);
var_dump($showticket);
This is the return value of the above code:
array(1) { ["module"]=> string(11) "0.435264836" }
What I want is to cut out is the numbers and display these: 0.435264836
Anyone got a clue what I can do to make that happen?
Thank you!
Upvotes: 0
Views: 65
Reputation: 4387
Use this $showticket['module']
mysql_fetch_assoc
returns an array, not just a single value. Since you're using mysql_fetch_assoc
you get an associative array indexed by the column name, hence the ['module']
. If you would use mysql_fetch_row
you'd get a numeric index and thus have to use $showticket[0]
.
But please don't forget that all the mysql_* functions are deprecated and will be removed in future versions of PHP!
Upvotes: 1
Reputation: 135
Thanks for your help. It seemed I had to use print_r to get the pure numbers from the string. My code ended up like this, combining Remo and FirstOne's suggestions. Thanks.
$ticketis = mysql_query("SELECT `module` FROM games ORDER BY `id` DESC LIMIT 1,1");
$showticket = mysql_fetch_assoc($ticketis);
print_r($showticket['module']);
Upvotes: 0