Jump to content

return a int from a function


clankill3r

Recommended Posts

Hi, i got this function to get the wordCount that i store in a tabel:

 

function getWordCount($word) {
$query = "SELECT count FROM uniqueWords WHERE word='$word'";
$data = execQuery($query);
return $data;
}

 

Only it returns an array, what i want is to have it return a integer, how can i do that?

 

Link to comment
https://forums.phpfreaks.com/topic/233264-return-a-int-from-a-function/
Share on other sites

sorry, forgot that it was not a bis php function:

 

function execQuery($query) {
$result = mysql_query($query) or die ("Query failed: " . mysql_error());
$data = array();
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
	$data[] = $row;
}
return $data;
}

 

With return $data['count'];

i get:

Notice: Undefined index: count in /home/vhosting/x/vhost0033377/domains/doeke.nl/htdocs/www/artez/uitwerking01/cms/lib.php on line 99

 

It can also happen that the word not exists for that i should return zero.

I now got this but it's still returning an array

 

function getWordCount($word) {
$query = "SELECT count FROM uniqueWords WHERE word='$word'";
$data = execQuery($query);
if(count($data) > 0){
	return $data[0];
}
else {
	return 0;
} 
}

 

 

 

 

i get stuff like this (small part of whole):

 

Array

(

)

Array

(

)

Array

(

    [0] => Array

        (

            [count] => 1

        )

 

)

Array

(

    [0] => Array

        (

            [count] => 1

        )

 

)

    [17] => Array

        (

            [count] => 1

        )

 

    [18] => Array

        (

            [count] => 1

        )

did you also mean [/count]?

 

Cause with that i get a error.

 

And if i use:

$query = "SELECT 'count' FROM uniqueWords WHERE word='$word'";

 

i get:

 

Array

(

    [0] => Array

        (

            [count] => count

        )

 

)

Array

(

    [0] => Array

        (

            [count] => count

        )

 

)

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.