PHP Loop and Data stucture for SQL data join

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 1
Joined: Tue Jul 03, 2018 1:29 pm

Tue Jul 03, 2018 1:59 pm

I have multiple SQL data tables.

initially I use a SQL query such that.

d.domainname AS domain
p.policyname AS POLICY
r.rulename AS rule,


smpolicylink4 pl,
smpolicy5 p,
smrules5 r,
smdomain5 d,

p.policyoid = pl.policyoid
AND pl.ruleoid = r.ruleoid
AND pl.domainoid = d.domainoid
AND d.domainname LIKE "search string"


Now I cannot use sql directly.
instead I can use JSON web services directly where I can get only use search filter for each table.

I write a pseudo code something like that

$results_domain_d = search_objects (smdomain5, domainname, "search_string")
for each $domain_d() in $results_domain_d {

$result.add ( $domain_d -> domainname;)

$results_policylink_pl = search_objects (smpolicylink4, domainoid, $domain_d()-> domainoid;);

for each $policylink_pl () in $results_policylink_pl {

$results_policy_p = search_objects (smpolicy5, policyoid, $policylink_pl()-> domainoid;);

for each $policy_p in $results_policy_p (){
$result.add ( $policy_p -> p.policyname)

$results_rule_r = search_objects (smrules5, ruleoid, $policylink_pl()-> ruleoid;);

for each $rule_r in $results_rule_r () {
$result.add ( $rule_r -> r.rulename;)


I am wondering if there is any sample code
for the $result.add feature? (data structure)
it is like a a dynamic list of a 1 d array.
each array means each row.
and it will add row dynamically?
this dynamic array will replicate itself if they detect they add new data.??

New php-forum User
New php-forum User
Posts: 1
Joined: Wed Jul 11, 2018 4:54 pm

Wed Jul 11, 2018 5:05 pm

I have a idea for this result: array()

Based on the column you want to retrieve data from tables
I thing that you should create an element array with an array of all columns as variables :) , it means
$itemArray = array(
domain => ''
policy=> ''
rule=> ''

then after get all data for specific columns, then push it the $result variable as you defined.

Finally, you get the array result of two dimension array.

Post Reply