/    Sign up×
Community /Pin to ProfileBookmark

Should be simple…making a string out of a mysql query

I’m trying to make a little update script, using the mysql_field_name to keep the form database-driven and not too hard-coded.

But it seems like a query to mysql doesn’t return a string, whether it’s the name of a field, a table, or whatever. So, here’s my code, I’m sure it’s some simple escape operator or built-in php function, but I could either search on the web all night or ask one of you guys that knows.

[code=php]
for($x=0; $x<mysql_numrows($result); $x++)
{
$updatequery = “UPDATE schools SET “;
for($y=2; $y<mysql_num_fields($result); $y++)
{
$updatequery +=(mysql_field_name($result, $y) . “='” . mysql_field_name($result, $y) . $x . “‘, “);
}
$updatequery +=(” WHERE id='” . ($x+1) . “‘”);

$update = mysql_query($updatequery);
echo $updatequery; //for my own debugging purposes
}
[/code]

^ This returns “0” (most likely because it cannot concatenate the mysql functions as strings.)

Any help is truly appreciated.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsJan 04.2005 — you have plusses "+" where there should be periods ".":[code=php]for($x = 0; $x < mysql_num_rows($result); $x++)
{

$update = "UPDATE schools SET ";
$sep = "";

for($y = 2; $y < mysql_num_fields($result); $y++)
{
$name = mysql_field_name($result, $y);
$update .= $sep . "$name = '$name$x'";
$sep = ", ";
}
$update .= " WHERE id = '" . ($x + 1) . "'";
mysql_query($update);
echo $update."n"; //for my own debugging purposes
}[/code]
Copy linkTweet thisAlerts:
@jlipin3authorJan 05.2005 — It works, perfectly. The += operators are probably from all of the java/javascript/whatever I've been doing.

Thanks though, I really appreciate it.
×

Success!

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