/    Sign up×
Community /Pin to ProfileBookmark

Pulling Vars in from MySQL

inside MySQL have a table w/ fields of ‘id’, ‘module’, ‘variableName’, ‘dataValue’.

Let’s say the gallery.php is the current page. At the begging I would like to pull all related variables in from MySQL, create variables from the ‘variableName’, and give the var it’s corrisponding value.

beggining code….

while(…sql conditions…)
$results=$db->Execute(“select id, variableName, dataValue from {$siteid}_Var where module=’gallery’ order by id”);

…now how can I create the variables?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@JonaSep 05.2004 — [code=php]

# Create empty, named array variables
$ids = $varNames = $dataValues = array();

# Run the query
$results=$db->Execute("select id, variableName, dataValue from {$siteid}_Var where module='gallery' order by id");

if(!$results){ # upon error
echo "Error: ".mysql_error(); # display error description
} else { # if no error
while($row = mysql_fetch_array($results)){ # loop through database fields, based on result
# fill in empty array variables with results
$ids[] = $row['id'];
$varNames[] = $row['variableName'];
$dataValues[] = $row['dataValue'];
}
}
# variable usage example
foreach($ids as $id){
echo "$idn";
}
[/code]
×

Success!

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