Jump to content

[SOLVED] I'm new to functions


almightyegg

Recommended Posts

It doesn't return anything really....

 

function Update($rid) {
while($rid <> 0) {
        $update = mysql_query("UPDATE topics SET updatetimestamp='$timestamp' WHERE fid='$f' and id='$rid'");
$sel = mysql_fetch_array(mysql_query("SELECT * FROM topics WHERE fid='$f' and id='$rid'"));
$rid = $sel[rid];
}
}

 

just does Updates Mysql

Link to comment
Share on other sites

There's other variables in there that aren't declared/set. You might want to use the 'global' function:

function Update($rid)
{
global $timestamp, $f;
while($rid <> 0) {
        $update = mysql_query("UPDATE topics SET updatetimestamp='$timestamp' WHERE fid='$f' and id='$rid'");
$sel = mysql_fetch_array(mysql_query("SELECT * FROM topics WHERE fid='$f' and id='$rid'"));
$rid = $sel[rid];
}
}

These will still need to be set external to the function. Also you might want to return a result to indicate success or failure.

Here's a wrapper I use:

function _db_do_mysql_query($s, $conn)
{
try
{
	if ( !@ ($res = mysql_query($s, $conn)) )
		throw new Exception (mysql_error());
}
catch (Exception $e)
{
	//echo 'ERROR: ' . $e->getMessage();
	return array(-1, $res);
}
return array(0, $res);
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.