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

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);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.