/    Sign up×
Community /Pin to ProfileBookmark

display from db

i have following value in a db. under note1 there are 3 codes and the total1=code001+code002+code003

note1 – code001,code002,code003
note2 – code004,code005
note3 – code006,code007,code008

how can i get the values from the db and display them as i mentioned below


——————————————-

[COLOR=”Red”]Note 1 – Title 1[/COLOR]
Code 001
Code 002
Code 003
[COLOR=”Blue”]Total 1[/COLOR]

[COLOR=”Red”]Note 2 – Title 2[/COLOR]
Code 004
Code 005
[COLOR=”Blue”]Total 2[/COLOR]

[COLOR=”Red”]Note 3 – Title 3[/COLOR]
Code 006
Code 007
Code 008
Code 009
[COLOR=”Blue”]Total 3[/COLOR]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@DasherJul 04.2011 — what are the names of the columns in your db. What uniquely identifies the data you want to display?
Copy linkTweet thisAlerts:
@sodaauthorJul 04.2011 — my db table structure

code | note | amount

0001 | 1 | 100

0002 | 1 | 500

0003 | 1 | 200

0004 | 1 | 100

0005 | 2 | 1500

0006 | 2 | 1200

0007 | 3 | 1500

0008 | 3 | 1200
Copy linkTweet thisAlerts:
@DasherJul 05.2011 — Something like this?

[code=php]for ($i = 0 ; $i <= 3 ; $i++){

$total = 0;
$query = "SELECT * FROM mydb WHERE note = ". $i ." ORDER BY code ASC";
$result = mysql_query ($query);
$q = 1;

while ( $a_row = mysql_fetch_assoc ($result)){
if ($q==1){echo $a_row['note'] . "<br>";}
$q++;

echo "Code " . $a_row['code'] . "<br>";
$total = $a_row['amount'] + $total;
}
echo "Total is " . $total . "<br>";

}[/code]
Copy linkTweet thisAlerts:
@sodaauthorJul 06.2011 — thanks bro. I'll check it and let you know
Copy linkTweet thisAlerts:
@sodaauthorJul 07.2011 — Thanks a lot Dasher. It works perfect.?
Copy linkTweet thisAlerts:
@DasherJul 07.2011 — You're welcome.
×

Success!

Help @soda 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...