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

Materialized Path PHP Regex to Select Last Item
jQuery Autocomplete returns data, but not outputting it using JSONP
how to use both condition() and addcondition() for a same search model
php date from unix timestamp
Creating a 5 star product review with PHP
PHP putting “if” in header and “else” in footer
how to fix notice and check file on server side?
How do I export variable columns to a CSV file using PHP?
log4php and timezone
Can i include my session_functions.php in my header then call a function from body.php
PHP add iTXt comment to a PNG image
catch error from a SOAP?
2 drop down menus w/o submit button
$_POST not working
Lookahead assertion as condition in conditional subpattern on .NET regular expression
javascript empty field validation

Categories

HOME
events
apache-nifi
list
applescript
transactions
devexpress
web2py
tcp
iptables
tibco
sentry
position
pyresttest
mailing-list
driver
tiff
buffer
createjs
multi-step
powermock
trace32
orange-api
tfsbuild
wsf
node-webkit
social-tables
mime-types
data-collection
plyr
xdebug
adapter
amazon-cloudtrail
d3.js-v4
delayed-job
cucumber-junit
osx-lion
appcode
markov-chains
cups
wdk
redgate
cargo
android-n
slideshow
hdiv
secure-coding
pyttsx
elasticsearch-aggregation
spooler
linq-to-excel
windows-media-player
return-type
scala-breeze
photoswipe
ilrepack
pen
patternlab.io
clrs
dtd
case-when
dymola
petsc
xcode6.4
tablespace
pyaudio
raw-sockets
directx-9
ora-04091
blank-line
bjam
cache-manifest
phpredis
dbmigrate
tree-structure
sablecc
python-c-extension
libgcc
full-text-indexing
unrealscript
coalesce
delphi-xe4
html-frames
aero
arel
significant-digits
session-0-isolation
multiple-dispatch
onconfigurationchanged
xcode4.5
popup-blocker
word-frequency
kobold2d
uipangesturerecognizer
yuidoc
winsxs
libxslt
pyjamas
eaccelerator
aspbutton
getimagesize
data-retrieval
jboss-mdb
jvm-bytecode

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App