/    Sign up×
Community /Pin to ProfileBookmark

variables problem

i have a for loop that contains varibale that changes from 1 -> 6
all that i need is to replace the variable $query to be $query1 when $n equals to 1, $query2 when n=2 ect…..

but i need it to be variable $query1, $query2 , $query3…$query6
can anyone help me plz

[code=php]
<? for ($n = 1; $n <=6; $n++) {?>
<div style=’display:<? if($n==1) {echo ‘block’;} else {echo ‘none’;}?>’ id='<?=$n;?>’>

<?
$query = “SELECT b.cat_id as cat_id,c.category as category , b.title as title, b.contento as contento FROM general b, category c WHERE b.section=’careers’ and b.cat_id=$n and c.cat_id=b.cat_id ORDER BY b.id”;
$result=mysql_query($query)?>[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 08.2009 — Why not use an array?
[code=php]
$query = array();
for(...) {
// . . .
$query[$n] = "SELECT . . . ";
}
[/code]
Copy linkTweet thisAlerts:
@MindzaiJun 08.2009 — You may also find you don't even need a loop, queries in loops are [I]usually[/I] not necessary.
×

Success!

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