Failed MySQL insert with no error, binding values in execute, PHP - php
I am trying to insert data from an array into MySQL in PHP. I have been working on this for a long time and could use some help debugging. I am not getting any errors which is making it hard for me to find the problem. Any help I could get with this would be appreciated.
There are more than two items in the $productConfigArray, I only included a sample.
Here is the code:
function insertBatch($productConfigArray)
{
try {
$insertStatement = 'INSERT INTO productconfigTEST (productid, partid, currency, fobid, fobpostalcode, pricetype) VALUES';
foreach ($productConfigArray as $index => $row) {
$productId = $row['0'];
$partId = $row['1'];
$currency = $row['2'];
$fobId = $row['3'];
$fobPostalCode = $row['4'];
$priceType = $row['5'];
$insertStatement .= ' (:productId' . $index .', :partId' . $index .', :currency' . $index .', :fobId' . $index .', :fobPostalCode' . $index .', :priceType' . $index .')';
$insertParams['productId' . $index] = $productId;
$insertParams['partId' . $index] = $partId;
$insertParams['currency' . $index] = $currency;
$insertParams['fobId' . $index] = $fobId;
$insertParams['fobPostalCode' . $index] = $fobPostalCode;
$insertParams['priceType' . $index] = $priceType;
}
$productConfigStatement = $pdo->prepare($insertStatement);
$productConfigStatement->execute($insertParams);
} catch(Exeption $e) {
echo $e->getMessage();
}
}
The $productConfigArray is structured like this:
Array
(
[0] => Array
(
[0] => 0011-02
[1] => 0011-02BK
[2] => USD
[3] => 15068
[4] => 15068
[5] => Net
)
[1] => Array
(
[0] => 0011-05
[1] => 0011-05BK
[2] => USD
[3] => 15068
[4] => 15068
[5] => Net
)
)
The completed $insertStatement (after foreach):
"INSERT INTO productconfigTEST (productid, partid, currency, fobid, fobpostalcode, pricetype, configtype) VALUES (:productId0, :partId0, :currency0, :fobId0, :fobPostalCode0, :priceType0) (:productId1, :partId1, :currency1, :fobId1, :fobPostalCode1, :priceType1)"
The completed $insertParams:
Array ( [productId0] => 0011-02 [partId0] => 0011-02BK [currency0] => USD [fobId0] => 15068 [fobPostalCode0] => 15068 [priceType0] => Net [productId1] => 0011-05 [partId1] => 0011-05BK [currency1] => USD [fobId1] => 15068 [fobPostalCode1] => 15068 [priceType1] => Net )
Related
need help in mutidimensional array
Good evening my helpers! I have a multidimensional array $data like this: Array ( [0] => thunderteszt [1] => orevikod [2] => 5400 [3] => 6 ) Array ( [0] => bakterhaz1982 [1] => $s$w$0ffТΉЏИÐΞЯ [2] => 5540 [3] => 3 ) Array ( [0] => bakterhaz1982 [1] => $s$w$0ffТΉЏИÐΞЯ [2] => 5570 [3] => 2 ) Array ( [0] => bakterhaz1982 [1] => $s$w$0ffТΉЏИÐΞЯ [2] => 5740 [3] => 1 ) Array ( [0] => thunderteszt [1] => orevikod [2] => 5840 [3] => 5 ) Array ( [0] => thunderteszt [1] => orevikod [2] => 5890 [3] => 4 ) You can see I have arrays with repeated nick in row[1] ($s$w$0ffТΉЏИÐΞЯ). I will pick up the lowest value (row[2]) from the repeated arrays. Therafter I will make a new array from the picked values and I will see only the following: Array ( [0] => thunderteszt [1] => orevikod [2] => 5400 [3] => 6 ) Array ( [0] => bakterhaz1982 [1] => $s$w$0ffТΉЏИÐΞЯ [2] => 5540 [3] => 3 ) edit: I forgot to say: the array already mutisorted by score(row 2) then by nick (row 1) edit2: my code sample is the following: edit3: Sorry for caps lock in original question :( function pts_panel_on($aseco) { global $pts; $maniapos = -1; $linkmaniapos = -0.2; $linkmaniapos2 = -0; $xml = '<manialinks><manialink id="40400">'; $xml .= '<frame posn="48.2 15 0">'; if (empty($pts->finish)) return true; $beerok=array(); foreach($pts->finish as $key=>$row){ $becenev[$key] = $row['nick']; $ido[$key] = $row['score']; } array_multisort($ido, SORT_ASC, $becenev, SORT_ASC, $pts->finish ); foreach($pts->finish as $data){ print_r(array_values($data)); $rpointinc++; $linkmaniapos = ($linkmaniapos - 3) ; $linkmaniapos2 = ($linkmaniapos2 - 3) ; $maniapos = ($maniapos - 3) ; if ($rpointinc <= 10) { $xml .= '<format textsize="1"/><label posn="-19.3 ' . $linkmaniapos. ' 1.5" sizen="30 3 2" scale="0.3" style="TextRaceChrono" halign="center" text="$s$0f0'.$rpointinc .' "/>'; $xml .= '<format textsize="1"/><label posn="-27.5 ' . $linkmaniapos . ' 1.5" sizen="30 3 2" halign="left" scale="0.3" style="TextRaceChrono" text="$s$fff'.formatTime($data['score']).' "/>'; $xml .= '<format textsize="1.7"/><label posn="-16.5 ' . $linkmaniapos . ' 1.6" sizen="12 3 2" halign="left" text="$000' . $data['nick'] . ' "/>'; $xml .= '<quad sizen="4 3" posn="-19.6 ' . $maniapos . ' 1" valign="center" halign="center" style="Bgs1InRace" substyle="NavButton" />'; $xml .= '<quad sizen="6.2 3" posn="-24.9 ' . $maniapos . ' 1" valign="center" halign="center" style="Bgs1InRace" substyle="NavButton" />'; $xml .= '<quad sizen="17 3" posn="-17.4 ' . $maniapos . ' 1.1" valign="center" halign="left" style="Bgs1InRace" substyle="NavButton"/>'; } } $xml .= '</frame>'; $xml .= '</manialink></manialinks>'; foreach ($pts->Players as $data2) { $aseco->client->query("SendDisplayManialinkPageToLogin", $data2['login'], $xml, 0, false); } }
How to sort data in sql query (according to value present in the json format of a data base field)
Array ( [0] => Array ( [20] => stdClass Object ( [qopid] => 20 [data] => {"room":0,"category":0} ) [21] => stdClass Object ( [qopid] => 21 [data] => {"room":0,"category":0} ) [22] => stdClass Object ( [qopid] => 22 [data] => {"room":0,"category":0} ) ) [1] => Array ( [23] => stdClass Object ( [qopid] => 23 [data] => {"room":"3","category":0} ) [24] => stdClass Object ( [data] => {"room":"3","category":0} ) [25] => stdClass Object ( [data] => {"room":"3","category":0} ) ) [2] => Array ( [26] => stdClass Object ( [qopid] => 26 [data] => {"room":"4","category":0} ) [27] => stdClass Object ( [qopid] => 27 [data] => {"room":"4","category":0} ) [28] => stdClass Object ( [qopid] => 28 [data] => {"room":"4","category":0} ) ) ) Here I want data to be come in view as whose room is 0 , should always come last ([data] => {"room":0,"category":0}) Means I want room zero data should always come last. below is my sql query $sql = 'SELECT q.* FROM ' . \SystemTables::DB_TBL_QUOTATION_PRODUCT . ' q LEFT JOIN ' . \SystemTables::DB_TBL_ITEM . ' ii ON q.iid = ii.iid WHERE q.qoid = "' . $qoid . '" '; if ($rooms == 0) { $like = "'" . '%{"room":' . $rooms . ',%' . "'"; } else { $like = "'" . '%{"room":"' . $rooms . '",%' . "'"; } if ($cat_id != null && $cat_id > 0) { $like1 = "'" . '%[{"id":"' . $cat_id . '"}]%' . "'"; $sql .= ' AND c_catid LIKE ' . $like1 . ''; } $sql .= ' AND q.data LIKE ' . $like . ''; Above is my sql query , how to do it ? as the sort by is not an exact column. I need to do sort by room which is present inside data .
One way of doing this is a nested foreach loop foreach ($array as $key => $value) { // Loop thru each array foreach ($value as $object) { // Loop thru each object $data = $object->data; // Set data value to $data $decode = json_decode($data); // Decode $data string if ($decode->room == 0) { // Check if room is 0 $move = $array[$key]; // Set array value to $move unset($array[$key]); // Unset array first $array[$key] = $move; // Then add array to last } } } print_r($array); // print array
combine and add data in one array index?
i have a array : Array ( [0] => Array ( [spid] => 20 [name] => Sunny [clientid] => 15 [selectedproduct] => ["190","191"] [memberid] => 637 [partner_id] => 390 [monthly_forecast] => a:2:{i:0;s:151:"[["1","0","0","1","0","0","1","0","1","0","0","0"],["1","0","0","0","1","0","0","0","1","0","1","1"],["1","0","1","0","1","0","1","0","1","0","0","1"]]";i:1;s:151:"[["1","0","1","0","1","0","1","0","1","0","1","0"],["1","0","1","0","1","1","0","1","0","1","0","1"],["1","0","1","0","1","0","1","1","1","0","1","1"]]";} [growth_plan] => {"product":["190","191"],"plans":["8","8"]} [other_palns] => {"product":["190","191"],"plans":["8","8"],"total":["4000","5000"]} [marketing_s_values] => {"190":"2400","191":"7200"} [marketing_s_values_monthly] => {"190":[{"1":"150","2":"150","3":"150","4":"150","5":"150","6":"150","7":"150","8":"150","9":"150","10":"150","11":"150","12":"150"},{"1":"200","2":"200","3":"200","4":"200","5":"200","6":"200","7":"200","8":"200","9":"200","10":"200","11":"200","12":"200"},{"1":"250","2":"250","3":"250","4":"250","5":"250","6":"250","7":"250","8":"250","9":"250","10":"250","11":"250","12":"250"},{"1":"300","2":"300","3":"300","4":"300","5":"300","6":"300","7":"300","8":"300","9":"300","10":"300","11":"300","12":"300"},{"1":"350","2":"350","3":"350","4":"350","5":"350","6":"350","7":"350","8":"350","9":"350","10":"350","11":"350","12":"350"}],"191":[{"1":"500","2":"500","3":"500","4":"500","5":"500","6":"500","7":"500","8":"500","9":"500","10":"500","11":"500","12":"500"},{"1":"600","2":"600","3":"600","4":"600","5":"600","6":"600","7":"600","8":"600","9":"600","10":"600","11":"600","12":"600"},{"1":"700","2":"700","3":"700","4":"700","5":"700","6":"700","7":"700","8":"700","9":"700","10":"700","11":"700","12":"700"},{"1":"800","2":"800","3":"800","4":"800","5":"800","6":"800","7":"800","8":"800","9":"800","10":"800","11":"800","12":"800"},{"1":"900","2":"900","3":"900","4":"900","5":"900","6":"900","7":"900","8":"900","9":"900","10":"900","11":"900","12":"900"}]} ) [1] => Array ( [spid] => 20 [name] => Sunny [clientid] => 15 [selectedproduct] => ["199","210"] [memberid] => 641 [partner_id] => 394 [monthly_forecast] => a:2:{i:0;s:163:"[["10","0","0","0","30","0","0","60","0","0","0","0"],["20","0","0","30","0","0","20","0","0","0","50","0"],["30","0","0","0","20","0","0","30","0","20","0","30"]]";i:1;s:154:"[["20","0","0","0","0","0","0","0","0","0","0","0"],["30","0","0","0","0","0","0","0","0","0","0","0"],["40","0","0","0","0","0","0","0","0","0","0","0"]]";} [growth_plan] => {"product":["199","210"],"plans":["8","8"]} [other_palns] => {"product":["199","210"],"plans":["10","10"],"total":["6000","3000"]} [marketing_s_values] => {"199":"4700","210":"0"} [marketing_s_values_monthly] => {"199":[{"1":"4600","2":"0","3":"0","4":"0","5":"0","6":"0","7":"0","8":"0","9":"0","10":"0","11":"0","12":"0"},{"1":"4700","2":"0","3":"0","4":"0","5":"0","6":"0","7":"0","8":"0","9":"0","10":"0","11":"0","12":"0"},{"1":"4800","2":"0","3":"0","4":"0","5":"0","6":"0","7":"0","8":"0","9":"0","10":"0","11":"0","12":"0"},{"1":"4900","2":"0","3":"0","4":"0","5":"0","6":"0","7":"0","8":"0","9":"0","10":"0","11":"0","12":"0"},{"1":"5000","2":"0","3":"0","4":"0","5":"0","6":"0","7":"0","8":"0","9":"0","10":"0","11":"0","12":"0"}],"210":[{"1":"0","2":"0","3":"0","4":"0","5":"0","6":"0","7":"0","8":"0","9":"0","10":"0","11":"0","12":"0"},{"1":"0","2":"0","3":"0","4":"0","5":"0","6":"0","7":"0","8":"0","9":"0","10":"0","11":"0","12":"0"},{"1":"0","2":"0","3":"0","4":"0","5":"0","6":"0","7":"0","8":"0","9":"0","10":"0","11":"0","12":"0"},{"1":"0","2":"0","3":"0","4":"0","5":"0","6":"0","7":"0","8":"0","9":"0","10":"0","11":"0","12":"0"},{"1":"0","2":"0","3":"0","4":"0","5":"0","6":"0","7":"0","8":"0","9":"0","10":"0","11":"0","12":"0"}]} ) [2] => Array ( [spid] => 20 [name] => Sunny [clientid] => 15 [selectedproduct] => ["190","191","192","193"] [memberid] => 574 [partner_id] => 374 [monthly_forecast] => a:4:{i:0;s:151:"[["1","0","0","1","0","0","1","0","1","0","0","0"],["1","0","0","0","1","0","0","0","1","0","1","1"],["1","0","1","0","1","0","1","0","1","0","0","1"]]";i:1;s:151:"[["1","0","1","0","1","0","1","0","1","0","1","0"],["1","0","1","0","1","1","0","1","0","1","0","1"],["1","0","1","0","1","0","1","1","1","0","1","1"]]";i:2;s:151:"[["1","1","1","0","1","1","1","0","0","0","1","1"],["1","1","1","0","0","1","1","1","1","0","1","1"],["1","1","1","1","0","0","1","1","1","1","1","1"]]";i:3;s:151:"[["1","0","1","0","0","0","1","0","1","0","0","2"],["1","0","0","2","1","0","1","0","1","1","0","1"],["1","0","2","1","1","1","0","1","0","1","1","1"]]";} [growth_plan] => {"product":["190","191","192","193"],"plans":["8","8","9","8"]} [other_palns] => {"product":["190","191","192","193"],"plans":["8","8","8","8"],"total":["4000","5000","1500","36000"]} [marketing_s_values] => {"190":"2400","191":"7200","192":"2400","193":"24000"} [marketing_s_values_monthly] => {"190":[{"1":"150","2":"150","3":"150","4":"150","5":"150","6":"150","7":"150","8":"150","9":"150","10":"150","11":"150","12":"150"},{"1":"200","2":"200","3":"200","4":"200","5":"200","6":"200","7":"200","8":"200","9":"200","10":"200","11":"200","12":"200"},{"1":"250","2":"250","3":"250","4":"250","5":"250","6":"250","7":"250","8":"250","9":"250","10":"250","11":"250","12":"250"},{"1":"300","2":"300","3":"300","4":"300","5":"300","6":"300","7":"300","8":"300","9":"300","10":"300","11":"300","12":"300"},{"1":"350","2":"350","3":"350","4":"350","5":"350","6":"350","7":"350","8":"350","9":"350","10":"350","11":"350","12":"350"}],"191":[{"1":"500","2":"500","3":"500","4":"500","5":"500","6":"500","7":"500","8":"500","9":"500","10":"500","11":"500","12":"500"},{"1":"600","2":"600","3":"600","4":"600","5":"600","6":"600","7":"600","8":"600","9":"600","10":"600","11":"600","12":"600"},{"1":"700","2":"700","3":"700","4":"700","5":"700","6":"700","7":"700","8":"700","9":"700","10":"700","11":"700","12":"700"},{"1":"800","2":"800","3":"800","4":"800","5":"800","6":"800","7":"800","8":"800","9":"800","10":"800","11":"800","12":"800"},{"1":"900","2":"900","3":"900","4":"900","5":"900","6":"900","7":"900","8":"900","9":"900","10":"900","11":"900","12":"900"}],"192":[{"1":"100","2":"100","3":"100","4":"100","5":"100","6":"100","7":"100","8":"100","9":"100","10":"100","11":"100","12":"100"},{"1":"200","2":"200","3":"200","4":"200","5":"200","6":"200","7":"200","8":"200","9":"200","10":"200","11":"200","12":"200"},{"1":"300","2":"300","3":"300","4":"300","5":"300","6":"300","7":"300","8":"300","9":"300","10":"300","11":"300","12":"300"},{"1":"400","2":"400","3":"400","4":"400","5":"400","6":"400","7":"400","8":"400","9":"400","10":"400","11":"400","12":"400"},{"1":"500","2":"500","3":"500","4":"500","5":"500","6":"500","7":"500","8":"500","9":"500","10":"500","11":"500","12":"500"}],"193":[{"1":"1500","2":"1500","3":"1500","4":"1500","5":"1500","6":"1500","7":"1500","8":"1500","9":"1500","10":"1500","11":"1500","12":"1500"},{"1":"2000","2":"2000","3":"2000","4":"2000","5":"2000","6":"2000","7":"2000","8":"2000","9":"2000","10":"2000","11":"2000","12":"2000"},{"1":"2200","2":"2200","3":"2200","4":"2200","5":"2200","6":"2200","7":"2200","8":"2200","9":"2200","10":"2200","11":"2200","12":"2200"},{"1":"2500","2":"2500","3":"2500","4":"2500","5":"2500","6":"2500","7":"2500","8":"2500","9":"2500","10":"2500","11":"2500","12":"2500"},{"1":"2700","2":"2700","3":"2700","4":"2700","5":"2700","6":"2700","7":"2700","8":"2700","9":"2700","10":"2700","11":"2700","12":"2700"}]} ) In this array as you see "spid" is similar to in all the array index.i just want that it will merge all the data in one index array. As you see "selectedproduct" of index 0 and index 2 is similar data like 190 and 191 whenever the "selectedproduct" is similar i just want that there respective "monthly_forecast" values added with each other and merge all the three index values into one but only in the case where there "selectedproduct" is similar only those "monthly_forecast" value added. i tried this code: $new_values = array(); foreach($get_partner_same_forecast as $value) { if(isset($new_values[$value['spid']])) { $temp = $new_values[$value['spid']]; $temp['selectedproduct'] .= ',' . $value['selectedproduct']; $user[] = json_decode($value['selectedproduct'],true); $result = array(); foreach($user as $item) { $result = array_merge($result, $item); } $temp['selectedproduct']=json_encode($result); $temp['partner_acc_name'] .= ',' . $value['partner_acc_name'];//mergepartner name $temp['crm_acc_name'] .= ',' . $value['crm_acc_name']; //merge crmname $temp['memberid'] .= ',' . $value['memberid'];//merge memberid $temp['partner_id'] .= ',' . $value['partner_id'];//merge partnerid $temp['growth_plan'] .= ',' . $value['growth_plan'];//merge growth plan $user1[] = json_decode($value['growth_plan'],true); $product = array(); $plan = array(); foreach($user1 as $k=>$v) { $product = array_merge($product, $v['product']); $plan = array_merge($plan, $v['plans']); $user1[$k]['product'] = $product; $user1[$k]['plans'] = $plan; } $temp['growth_plan']=json_encode($user1[1]); $temp['monthly_forecast'] .= ',' . $value['monthly_forecast'];//merge unserialize monthly data $data1=array(); $data2=array(); $data2=unserialize($value['monthly_forecast']); $data1=unserialize($temp['monthly_forecast']); $combinedData=array(); $combinedData = array($data1, $data2); $monthly_forecast = array(); $monthly_forecast=serialize($combinedData); $temp['monthly_forecast']=$monthly_forecast;//merge monthly $monthly_forecast=unserialize($monthly_forecast); //echo "<pre>"; print_r($monthly_forecast);echo "</pre>"; $new_values[$value['spid']] = $temp; } else { $new_values[$value['spid']] = $value; } } $new_values = array_values($new_values);
Echo comma separated values in PHP
I have a invoice table in which three columns have comma-separated values. Now I want to show a report in details for each invoice. For example, Invoice_id=10 product=1,5,55 category=2,44,25 QTY= 55,2,10 So for the above invoice I want to show each product name and category with qty.
If they are in the right order and have a consistent correlation, you can do that. For example, you can explode by ',' the fields and create the output in a for loop like this: //you have to retrieve the data from database, the fields are strings $product= "1,5,55" $category= "2,44,25" $QTY= "55,2,10" //for each invoice: $products = explode(',',$product); $categories = explode(',',$category); $QTYs = explode(',',$QTY); for ($i = 0; $i < count($products); $i++){ echo "Product: " . $products[$i] . ", Category: " . $categories[$i] . ", Quantity: " . $QTYs[$i] . ".<br>"; } hope it helps
foreach(explode(' ', 'Invoice_id=10 product=1,5,55 category=2,44,25 QTY=55,2,10') as $key => $value) { $temp[] = explode('=', $value); } foreach($temp as $key => $value) { $final[$value[0]] = explode(',', $value[1]); } echo '<pre>'; print_r($final); output: Array ( [Invoice_id] => Array ( [0] => 10 ) [product] => Array ( [0] => 1 [1] => 5 [2] => 55 ) [category] => Array ( [0] => 2 [1] => 44 [2] => 25 ) [QTY] => Array ( [0] => 55 [1] => 2 [2] => 10 ) )
Avoid recurring of Records in the code
I am implementing Wordpress feature, viewing posts per Year and Month using PHP as eg: Press Releases 2013(4) October(1) Announcement1 But I am getting each records as repeated in the result. The code is as shown below: $query = "SELECT * FROM edu_announcements WHERE status = '1' ORDER BY add_time asc"; $resultSet = mysql_query($query); if (mysql_num_rows($resultSet)) { $newsArray = array(); echo '<ul>' . PHP_EOL; echo '<li><strong>Press releases:</strong></li>' . PHP_EOL; while ($newsResult = mysql_fetch_array($resultSet)) { $newDate = $newsResult['add_time'] ; $timePeriod =date("F Y", $newDate); //$timePeriod = date('F Y ',strtotime($newDate)); $timePeriodY = date('Y',$newDate); $timePeriodM = date('F',$newDate); if (!isset($newsArray[$timePeriod])) { $newsArray[$timePeriod] = array(); } $newsArray[$timePeriod][] = $newsResult; } foreach ($newsArray as $timePeriod => $newsItems) { $timePeriodY = date('Y',strtotime($timePeriod)); echo '<li><strong>' . $timePeriodY . '</strong>' . PHP_EOL; echo '<ul>' . PHP_EOL; //by month foreach ($newsArray as $timePeriod => $newsItems) { echo '<li><strong>' . $timePeriod . '</strong>' . PHP_EOL; echo '<ul>' . PHP_EOL; //news items foreach ($newsItems as $item) { echo '<li>'; echo ''.$item["title"].''; echo '</li>' . PHP_EOL; } //end by month echo '</ul>' . PHP_EOL; echo '</li>' . PHP_EOL; } //end by year echo '</ul>' . PHP_EOL; echo '</li>' . PHP_EOL; } echo '<li> </li>' . PHP_EOL; echo '</ul>' . PHP_EOL; } else { echo 'No announcements'; } I am getting the result as repeated as shown below: Array ( [July 2013] => Array ( [0] => Array ( [0] => 99 [id] => 99 [1] => sdfsdf [title] => sdfsdf [2] => sdfsdfsdfc [description] => sdfsdfsdfc [3] => [documents] => [4] => [photo1] => [5] => [photo2] => [6] => [photo3] => [7] => [photo4] => [8] => 1 [public_visibility] => 1 [9] => 0 [dept_visibility] => 0 [10] => 0 [depatment] => 0 [11] => 1373913000 [add_time] => 1373913000 [12] => 1 [status] => 1 [13] => sdfsdf [small_description] => sdfsdf ) [1] => Array ( [0] => 100 [id] => 100 [1] => sefsdfvsxdf [title] => sefsdfvsxdf [2] => sdfsdfsd [description] => sdfsdfsd [3] => [documents] => [4] => [photo1] => [5] => [photo2] => [6] => [photo3] => [7] => [photo4] => [8] => 1 [public_visibility] => 1 [9] => 0 [dept_visibility] => 0 [10] => 0 [depatment] => 0 [11] => 1374604200 [add_time] => 1374604200 [12] => 1 [status] => 1 [13] => sdfsefs [small_description] => sdfsefs ) ) I want distinct records from the table. Can anyone help me to solve this.
If you mean why are you getting the parts of each record duplicated, such as: [0] => 99 [id] => 99 it is because mysql_fetch_array has a second option (beyond your $resultset), which defaults to int $result_type = MYSQL_BOTH. The type of array that is to be fetched. It's a constant and can take the following values: MYSQL_ASSOC, MYSQL_NUM, and MYSQL_BOTH. If you must use the raw (and old) mysql functions (as others say, this is no longer good practice), then you will also want to probably add , MYSQL_ASSOC to the function call, and then deal only with the name of the columns - such as 'id', 'title' & 'description'. There may also be similar parameters to other DB access calls, though mostly they will use the MYSQL_ASSOC-style returns to have the column name by default.
I solved the answer by using the code as shown below: echo '<div id="news_events_section_wrapper"> <div class="news_events_section">'; $CURRENT_TIMESTAMP=time(); $sqlstr=mysql_query("select * from nesote_edu_announcements where status=1"); $count=mysql_num_rows($sqlstr); if($count!=0) { while($article=mysql_fetch_row($sqlstr)) { $id=$article[0]; $details= $article[2]; $postedon=date("F j, Y",$article[11]); $olderpost=date("Y",$article[11]); $yearnoquery=mysql_query("select count(*) from nesote_edu_announcements where add_time <='$CURRENT_TIMESTAMP' and status=1 "); $resultq=mysql_fetch_row($yearnoquery); $numberofposts=$resultq[0]; } echo "<a href=javascript:showmonths(".$id.") style=".'"'."text-decoration:none".'"><div>'; echo $olderpost;echo '(';echo $numberofposts;echo ')'; echo '</div> </a>'; $monthqry=mysql_query("SELECT add_time,COUNT(id),id FROM nesote_edu_announcements WHERE status=1 AND (add_time <='$CURRENT_TIMESTAMP') AND FROM_UNIXTIME(add_time, '%Y')='$olderpost' GROUP BY FROM_UNIXTIME(add_time, '%M') ASC"); while($month=mysql_fetch_row($monthqry)) { $monthsfordisplay=date("F",$month[0]); $months=date("m",$month[0]); $monthnos=$month[1]; $artid=$month[2]; echo '<div id='.'"'."month_art".'"'." class=".'"'."month_"; echo $id.'">'; echo '<a href="javascript:showdetails'.'('; echo $artid; echo ')">'; echo $monthsfordisplay; echo '('; echo $monthnos; echo ')</a></div>'; $smalldisquery=mysql_query("SELECT * FROM nesote_edu_announcements WHERE FROM_UNIXTIME(add_time, '%m')='$months' AND add_time <='$CURRENT_TIMESTAMP' and status=1"); while($smalldisc=mysql_fetch_row($smalldisquery)) { $articlemonthid=$smalldisc[0]; $disc=$smalldisc[1]; echo ' <div style="display:none;" id="sub_str" class="smalldiscription_';echo $artid; echo '"> <a href='.'"index.php?page=events/announcementdetails/'; echo $articlemonthid; echo '"'.' style='.'"text-decoration:none;'.'"> <font color="#80000">'; $message=substr($disc,0,30); $message=$message."..."; echo "* ".$message; echo "</font></a>"; echo "</div>"; } } } echo "</div></div>"; This will show announcements in Year-Month basis.