Hello,
Getting data from mysql and assign to associative array
Last data not assign to associative array.
for ex:
mysql query:
$qry = "
SELECT ci.itemType, SUM(ci.itemValue) AS itemValue
FROM count_info AS ci, s_info as si
WHERE si.`site_cd`=ci.`site_info`
AND ci.info_datetime BETWEEN '$date_start' AND '$date_end'
AND ci.adfile_uid='$ad_uid'
AND si.areacode = '$ph_code'
GROUP BY ci.itemType
ORDER BY ci.`itemtype`";
Result set:
itemType itemValue
MVC 942943
MTC 106503
SVC 213587
STC 1411050
php:
//define associative array
$as_arr = array('MVC'=>0, 'MTC'=>0,'SVC'=>0, 'STC'=>0);
All data assign perfectly, except last one[STC].
I'm getting the data by this way,
echo "MVC = " . $as_arr ['MVC']; // get data perferctly
echo "MTC = " . $as_arr ['MTC']; // get data perferctly
echo "SVC = " . $as_arr ['SVC']; // get data perferctly
echo "SRC = " . $as_arr ['SRC']; // NOT GETTING DATA
Code help please.
Where i did mistake? Please correct the code.
Thanks & Best Regards,
Thendral.
Associative array can't fetch the last data.
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Associative array can't fetch the last data.
Code: Select all
<?php echo "SRC = " . $as_arr ['SRC']; // NOT GETTING DATA ?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: Associative array can't fetch the last data.
hi,
Sorry for inconvenience. I mistyped.
This is my correct sentence.
echo "STC = " . $as_arr ['STC']; // NOT GETTING DATA
same thing is happening, not getting data.
Thanks,
thendral
Sorry for inconvenience. I mistyped.
This is my correct sentence.
echo "STC = " . $as_arr ['STC']; // NOT GETTING DATA
same thing is happening, not getting data.
Thanks,
thendral
Re: Associative array can't fetch the last data.
Post the missing code parts - ie.e fetching the data from the DB server, assigning data to you array, etc.
Please use [syntax=php ][/syntax] for your code blocks.
Please use [syntax=php ][/syntax] for your code blocks.
There are 10 types of people in this world, those who understand binary and those who don't
Re: Associative array can't fetch the last data.
hi,
please refer to my previous post.
hope it helps.
$qry = "
SELECT ci.itemType, SUM(ci.itemValue) AS itemValue
FROM count_info AS ci, s_info as si
WHERE si.`site_cd`=ci.`site_info`
AND ci.info_datetime BETWEEN '$date_start' AND '$date_end'
AND ci.adfile_uid='$ad_uid'
AND si.areacode = '$ph_code'
GROUP BY ci.itemType
ORDER BY ci.`itemtype`";
$this->res = $this->query($qry);
if ( $this->getCount() > 0 ) {
//define associative array
$as_arr = array('MVC'=>0, 'MTC'=>0,'SVC'=>0, 'STC'=>0);
echo "MVC = " . $as_arr ['MVC']; // get data perferctly
echo "MTC = " . $as_arr ['MTC']; // get data perferctly
echo "SVC = " . $as_arr ['SVC']; // get data perferctly
echo "SRC = " . $as_arr ['SRC']; // NOT GETTING DATA
Thanks,
thenral
please refer to my previous post.
hope it helps.
$qry = "
SELECT ci.itemType, SUM(ci.itemValue) AS itemValue
FROM count_info AS ci, s_info as si
WHERE si.`site_cd`=ci.`site_info`
AND ci.info_datetime BETWEEN '$date_start' AND '$date_end'
AND ci.adfile_uid='$ad_uid'
AND si.areacode = '$ph_code'
GROUP BY ci.itemType
ORDER BY ci.`itemtype`";
$this->res = $this->query($qry);
if ( $this->getCount() > 0 ) {
//define associative array
$as_arr = array('MVC'=>0, 'MTC'=>0,'SVC'=>0, 'STC'=>0);
echo "MVC = " . $as_arr ['MVC']; // get data perferctly
echo "MTC = " . $as_arr ['MTC']; // get data perferctly
echo "SVC = " . $as_arr ['SVC']; // get data perferctly
echo "SRC = " . $as_arr ['SRC']; // NOT GETTING DATA
Thanks,
thenral
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Associative array can't fetch the last data.
Code: Select all
<?php
//define associative array
$as_arr = array('MVC'=>0, 'MTC'=>0,'SVC'=>0, 'STC'=>0);
?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: Associative array can't fetch the last data.
Hello,
I fix it.
I assign data through while loop, before last data while loop stop.
after change the count value, it works charm.
Thanks for giving the idea.
Thanks again,
Thendral
I fix it.
I assign data through while loop, before last data while loop stop.
after change the count value, it works charm.
Thanks for giving the idea.
Thanks again,
Thendral