almightyegg Posted September 16, 2007 Share Posted September 16, 2007 I have just written one but I'm not sure how to start it going.... It's not one that echoes anything, so I don't echo it out. How else would I start it up?? Link to comment https://forums.phpfreaks.com/topic/69581-solved-im-new-to-functions/ Share on other sites More sharing options...
pocobueno1388 Posted September 16, 2007 Share Posted September 16, 2007 Well...post your function code. If it just returns a value, you could assign it to a variable. $var = myfunc(); echo $var; Link to comment https://forums.phpfreaks.com/topic/69581-solved-im-new-to-functions/#findComment-349650 Share on other sites More sharing options...
almightyegg Posted September 16, 2007 Author Share Posted September 16, 2007 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 https://forums.phpfreaks.com/topic/69581-solved-im-new-to-functions/#findComment-349654 Share on other sites More sharing options...
Jessica Posted September 16, 2007 Share Posted September 16, 2007 You mean how to call it? Update($value); Link to comment https://forums.phpfreaks.com/topic/69581-solved-im-new-to-functions/#findComment-349659 Share on other sites More sharing options...
almightyegg Posted September 16, 2007 Author Share Posted September 16, 2007 Can I literally just call it: Update($value); Nothing before/after it??? Link to comment https://forums.phpfreaks.com/topic/69581-solved-im-new-to-functions/#findComment-349660 Share on other sites More sharing options...
rarebit Posted September 16, 2007 Share Posted September 16, 2007 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 https://forums.phpfreaks.com/topic/69581-solved-im-new-to-functions/#findComment-349662 Share on other sites More sharing options...
almightyegg Posted September 16, 2007 Author Share Posted September 16, 2007 Thanks, I got it working Link to comment https://forums.phpfreaks.com/topic/69581-solved-im-new-to-functions/#findComment-349667 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.