/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] looping through an array

Hi

I’m new at PHP and I am having an issue with my loop. I have a mysql database that I am retrieving data from. I need to echo the information so that flash can read it. When I echo my array it displays my data but repeats the first row several times. Why is this? Here is the output from the echo:

numsx=381,474,646&numsx=381,474,646&numsx=318,432,626

see the repeat in data.

[code=php]
$houseID = 74420665;
$id_query = mysql_query(“SELECT colors, xvalues, yvalues FROM t_neonlights WHERE houseID='{$houseID} ‘”) or print mysql_error();

while ($row = mysql_fetch_array($id_query, MYSQL_ASSOC)) {
$i++;
$vars .=”numsx=”. $row[“xvalues”]. “&”;
echo $vars;

}
[/code]

Thanks for your help.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@salmanshafiqNov 21.2007 — can you give me script of you table for testing?
Copy linkTweet thisAlerts:
@salmanshafiqNov 21.2007 — i have tried this code with my table script and it's working fine their is no repeatation... please give me your table script for testing
Copy linkTweet thisAlerts:
@gpm1982Nov 21.2007 — The while block is supposed to end before the echo line. the code should be as below:

[code=php]$houseID = 74420665;
$id_query = mysql_query("SELECT colors, xvalues, yvalues FROM t_neonlights WHERE houseID='{$houseID} '") or print mysql_error();

while ($row = mysql_fetch_array($id_query, MYSQL_ASSOC)) {
$i++;
$vars .="numsx=". $row["xvalues"]. "&";
} // close while loop here
echo $vars; // then we see the display
[/code]
Copy linkTweet thisAlerts:
@jasonahouleNov 21.2007 — That or change

$vars .=

to

$vars =

It all depends on what you are trying to do.
Copy linkTweet thisAlerts:
@pulleysauthorNov 21.2007 — Thanks everyone for your help.
×

Success!

Help @pulleys 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,
)...