Jump to content

Function Weirdness


Fabis94

Recommended Posts

I have this function:

 

function pruneTrue($regdate1, $i, $auto_prune_date) { //Must be YYYY-MM-DD
$query = "SELECT * FROM hosted_forums";
$result = mysql_query($query);
$fname=mysql_result($result,$i,"fname"); //Forum Name
$table = $fname . "_isawaiting_activation";
echo $table . ' ';
$check = mysql_is_table($table);
if ($check != TRUE) {
	echo ' FALSE LOL ';
	return false;
} else {
	$query22 = mysql_query("SELECT * FROM " . $table);
	print_r($query22);
	$autoprune = $auto_prune_date * 86400; //1 unix day = 86400
	$todayd = date("Y-m-d");
	$today = strtotime($todayd);
	$regdate = strtotime($regdate1);
	$expire = $regdate + $autoprune;
	if ($today > $expire) {
		return true;
	} else {
		return false;
	}
}
}

 

This is the mysql_is_table():

 

function mysql_is_table($tbl)

{

    $tables = array();

    $q = @mysql_query("SHOW TABLES");

    while ($r = @mysql_fetch_array($q)) { $tables[] = $r[0]; }

    @mysql_free_result($q);

    if (in_array($tbl, $tables)) { return TRUE; }

    else { return FALSE; }

}

 

Anyways the first function results in 1 and causes other weird stuff in my script. What is wrong with it?

Link to comment
https://forums.phpfreaks.com/topic/165287-function-weirdness/
Share on other sites

The first thing you need to do is check return values for mysql_query().  And please remove all "@" signs from your code.  At the debugging stage you want to know all of the errors.

 

For example:

 

function mysql_is_table($tbl)
{
    $tables = array();
    $q = mysql_query("SHOW TABLES") or die("SHOW TABLES failed: " . mysql_error());
    while ($r = mysql_fetch_array($q)) { $tables[] = $r[0]; }  # no @ - if there's an error here we want to know!
    mysql_free_result($q); # Again, we want to see the error if something is wrong.
    if (in_array($tbl, $tables)) { return TRUE; }
    else { return FALSE; }
}

Link to comment
https://forums.phpfreaks.com/topic/165287-function-weirdness/#findComment-871789
Share on other sites

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.