php


how make a loop for inside another loop for without repeat values in a bidimensional array


I have a query in my controller, in which i search data according an id, it return 2 results, then I want search some datas according with the previously result and them shows in a view. Its something like this:
first query:
$query_1 = $obj1->Searcher_Test($type);
function Searcher_Test($type)
{
$this->db->join('n_type', 'n_type.id_test = test.id_test');
$this->db->where('test.id_type', $type);
return $this->db->get('test');
}
second query:
$query_2 = $obj2->Searcher_charact($id_test);<br>
function Searcher_charact($id_test) <br>
{<br>
$this->db->join('charact', 'charact.id_test = test.id_test');<br>
$this->db->where('test.id_test', $id_test);<br>
return $this->db->get('test');<br>
}<br>
the first query give me 2 results
id_test | test |id_type
------- |------ |--------
1 | one | 1
2 | two | 1
the second query give me 3 results
id_charact | charact | id_test
1 | moduls | 1
2 | direct | 1
3 | integer| 2
I make this for loop
$contador = 0;
$list_test = array(array());
$contador_charact = 0;
$list_charact = array(array());
for ($i = 0; $i < $query_1->num_rows; $i++) {
$id_test = $query_1->row($i)->id_test;
$query_2 = $obj2->Searcher_charact($id_test);
for ($j = 0; $j < $query_2->num_rows; $j++) {
$list_charact[$contador_charact]['charact'] = $query_2->row($j)->charact;
$contador_charact ++;
}// for j
$list_test[$contador]['test'] = $query_1->row($j)->test;
$contador++;
}// for i
and in the view I make this, but it shows me all the records, including the id_test = 1 and id_test = 2
for ($i = 0; $i < $contador; $i++) {
for ($j = 0; $j < $contador_charact; $j++) {
?>
} //for i
it shows something like this:
one
moduls
directs
integer
two
moduls
directs
integer
and I want that shows
one
moduls
directs
integer
two
integer
I do not know if my query its wrong, my loop for or my view. Please help, thanks in adavance.
Thanks to all of you. I find my answer, I do this in my view:
for ($i = 0; $i < $contador; $i++) {
<div class="layout-item-0">
<?php echo $list_test[$i]['test']; ?>
for ($j = 0; $j < $contador_charact; $j++) {
if ($id_test == $list_charact[$j]['id_test']) { // <--- this is what I add
?>
<li>
<?php echo $list_charact[$j]['charact']?>
</li>
<?php
}//del if
} //for j
</div>
} //for i

Related Links

Get data from a form that is in an iframe
Properly coding Email Form with PHP? [closed]
Yii2 rendering view doesn't work correctly
Unable to get date out put
JSON_decode with foreach in php [closed]
PHP/MYSQL counting orders
Laravel 5.3 Validate Multiple Request Show Errors
Laravel 5 is not working on shared hosting
Apostrophe S Issue While Echoing a Variable
keep argument in url with codeigniter
How does Pusher webhook work? Is HTTP POST request sended from client or Pusher server?
get backend var from php into reactjs via webpack
PHP, DOMElement get value only current node
Is it possible to restrict PHP form submission to a region/country?
How to remove a line from text file using php with specific structure
laravel 5.3: ErrorException in UrlGenerator.php line 314: Route [] not defined

Categories

HOME
schema.org
bots
dry
whmcs
histogram
consul
twitter-fabric
greasemonkey
vue-resource
ontology
cdi
kurento
cocotb
mailing-list
live-streaming
bundler
sonata
max-msp-jitter
fresco
hidden
robolectric
checkout
http-authentication
device
opentext
jstree
pyspark-sql
spring-annotations
jsonresult
windows2012
python-2.x
xcrun
seafile-server
char-pointer
transform
xvfb
telephonymanager
oauth2
grails-spring-security
plane
uipickerview
hypothesis-test
jqgrid-asp.net
absolute
django-static-precompiler
icecast
md5-file
nslayoutconstraint
gmaps.js
yui3
maven-release-plugin
right-to-left
apache-pig-grunt
onepage-checkout
flush
teensy
linuxbrew
in-app-billing
openshift-cartridge
sqlbase
scala-swing
fasterxml
mobile-country-code
django-sites
principalcontext
strcmp
vlab
grails-2.3
boinc
stty
indesign-server
void-pointers
bcdedit
web-frameworks
examine
ip-geolocation
telerik-ajax
uipangesturerecognizer
zend-server-ce
radscheduler
rtd
webresponse
chunking
pinax
ppc
3270
acceleration
watchpoint
regioninfo
html-generation
jvm-bytecode

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App