/    Sign up×
Community /Pin to ProfileBookmark

Returning query result in table

Hi all!
I got troubles while inputting data in table from mysql query. Here is the code:

[code]
$sql_2 = “SELECT name FROM product_attributes WHERE cid=$category_id ORDER BY order_field AND id”;
$result_2 = mysql_query($sql_2) or die(“2”.mysql_error());
while($atribute = mysql_fetch_assoc($result_2)){
echo “<tr>”;
foreach ($atribute as $k=>$v){
echo “<td>”;
echo $v;
echo “</td>”;
foreach($_SESSION[‘ident’] as $ident){
if(isset($_GET[$ident])){
$temp_id = $ident;
$sql_3 = “SELECT val_string FROM product_attribute_values WHERE product_id=$ident ORDER BY id”;
$result_3 = mysql_query($sql_3) or die(“3”.mysql_error());
while($value = mysql_fetch_assoc($result_3)){
foreach($value as $stoinost){
echo “<td>”;
echo $stoinost;
echo “</td>”;
}
break;
}
}

}
break;
}
}
[/code]

I want them to be outputted like this:

[code]
|product 1| product 2
attribute1 | value.1 | value.1
attribute1 | value.2 | value.2
attribute1 | value.3 | value.3
[/code]

but they are outputting like this:

[code]
|product 1| product 2
attribute1 | value.1 | value.1
attribute1 | value.1 | value.1
attribute1 | value.1 | value.1
[/code]

Where i’m wrong with my code? Can someone help me out?
Thanks in advance!

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@Phill_PaffordAug 20.2008 — Try removing both break commands and see what happends
Copy linkTweet thisAlerts:
@stanislav01authorAug 20.2008 — I wrote them there.

When i remove them, it outputs:
<i>
</i> |product 1| product 2
attribute1 | value.1 | value.2|value.3 | value.1| value.2 | value.3
attribute1 | value.1 | value.2|value.3 | value.1| value.2 | value.3
attribute1 | value.1 | value.2|value.3 | value.1| value.2 | value.3


The $atribute array contains:
<i>
</i>Array ( [name] =&gt; attr1) Array ( [name] =&gt;attr2 ) Array ( [name] =&gt; attr3 ) Array ( [name] =&gt; attr4 ) Array ( [name] =&gt; attr5 ) Array ( [name] =&gt; attr6 )

and it's dynamicaly changing. The content of this array depends to database query

the $value array contains:
<i>
</i>Array ( [val_string] =&gt; D37EX-21 )
Array ( [val_string] =&gt; 63 / 85 )
Array ( [val_string] =&gt; 7 410 )
Array ( [val_string] =&gt; 122.6 )
Array ( [val_string] =&gt; 1.75 )
Array ( [val_string] =&gt; triple )

and it's dynamicaly changing. The content of this array depends to database query result
Copy linkTweet thisAlerts:
@Phill_PaffordAug 20.2008 — Print this out and see if this changes when you add the break back in

[code=php]
$temp_id = $ident;

echo "TEMP ID: " . $temp_id . "<br />";
[/code]


I think the temp_id is not being updated so the query is returning the same results over and over.
×

Success!

Help @stanislav01 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...