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