PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 15, 2022

[FIXED] Get Data from database using array values with for loop in PHP

 March 15, 2022     codeigniter, mysql, php     No comments   

Issue

Array:

$ecodesAr = Array ( 
[0] => 1Z0-060 
[1] => 98-375 
[2] => 98-368 
[3] => 98-367 )

for($k=0; $k<count($ecodesAr); $k++){ 
$arrayTB[$k] = $this->Functions->exam('title', $ecodesAr[$k]); }                         
                                    
                                    

Modal code:

public function exam($q, $d) {
    $q = $this->db->where($q, $d)
                    ->get('exams');
    return $q->row();
}

Result:

Array ( 
[0] => 
[1] => 
[2] => 
[3] => stdClass Object ( [id] => 1091 [hot_exam] => 0 [top_exam] => 0 [category] => 114 [subcats] => 288 [slug] => 98-367 [sku] => OI5Ao [title] => 98-367 [name] => MTA Security Fundamentals [update] => 2021-09-16 [regular_price] => 130 [sale_price] => 59 [on_homepage] => 0 [on_request] => 0 [expired] => 0 [path_slug] => 98-367.pdf [questions] => 123 [demo_slug] => 98-367-demo.pdf [prc_price] => 65 [prc_demo] => 98-367-demo [prc_exam] => 98-367 [is_active] => 1 ) 
)

The First 3 values are skiped in the output and just the last value got, I want to all array data against values please help anyone!


Solution

$productsarry = Array ( 
    [0] => Milk 
    [1] => Cream 
    [2] => Sugar 
    [3] => Yougert
);
for($k = 0; $k < count($productsarry); $k++) { 
    $arrayTB[$k] = query("select slug, qty, name, price from exams where title ='$ecode'")->row(); 
}


Answered By - HAMMAD ALI
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing