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

 

 

 

 

Link to comment
Share on other sites

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

        )

Link to comment
Share on other sites

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

        )

 

)

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.