Jump to content

Wrong parameter count for max


TheUnknown

Recommended Posts

any ideas on how to solve these errors

 

Warning: ksort() expects parameter 1 to be array, null given in /public_html/tags.php on line 16

 

Warning: array_values() [function.array-values]: The argument should be an array in /public_html/tags.php on line 27

 

Warning: Wrong parameter count for min() in /public_html/tags.php on line 27

 

Warning: array_values() [function.array-values]: The argument should be an array in /public_html/tags.php on line 28

 

Warning: Wrong parameter count for max() in /public_html/tags.php on line 28

 

Warning: Invalid argument supplied for foreach() in /public_html/tags.php on line 37

here is the code

 

<?php

$db_host = "localhost";
$db_user = "";
$db_pass = ";
$db_name = "";

mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name);

function tag_info() { 
  $result = mysql_query("SELECT * FROM tags GROUP BY tag ORDER BY count DESC"); 
  while($row = mysql_fetch_array($result)) { 
    $arr[$row['tag']] = $row['count'];
  } 
  ksort($arr); 
  return $arr; 
}

function tag_cloud() {

    $min_size = 10;
    $max_size = 30;

    $tags = tag_info();

    $minimum_count = min(array_values($tags));
    $maximum_count = max(array_values($tags));
    $spread = $maximum_count - $minimum_count;

    if($spread == 0) {
        $spread = 1;
    }

    $cloud_html = '';
    $cloud_tags = array(); 
    foreach ($tags as $tag => $count) {
        $size = $min_size + ($count - $minimum_count) 
            * ($max_size - $min_size) / $spread;
        $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' 
            . '" class="tag_cloud" target="_blank" href="http://site.com/search.php?search=' . $tag 
            . '" title="\'' . $tag  . '\' returned a count of ' . $count . '">' 
            . htmlspecialchars(stripslashes($tag)) . '</a>';
    }
    $cloud_html = join("\n", $cloud_tags) . "\n";
    return $cloud_html;

}

?>

<style type="text/css">
.tag_cloud
    {padding: 3px; text-decoration: none;
    font-family: verdana;     }
.tag_cloud:link  { color: #FF66CC; }
.tag_cloud:visited { color: #9900FF; }
.tag_cloud:hover { color: #FF66CC; background: #000000; }
.tag_cloud:active { color: #6699FF; background: #000000; }
</style>

<div id="wrapper">
<?php print tag_cloud(); ?>
</div> 

 

thanks in advance

 

Link to comment
Share on other sites

Played around with the code a little bit and now im getting

 

Warning: array_values() [function.array-values]: The argument should be an array in /public_html/cloud.php on line 28

 

Warning: Wrong parameter count for max() in /public_html/cloud.php on line 28

 

Warning: Invalid argument supplied for foreach() in /public_html/cloud.php on line 41

 

Edited Code

<?php

$db_host = "localhost";
$db_user = "";
$db_pass = "";
$db_name = "";

mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name);

function tag_info() { 
  $result = mysql_query("SELECT * FROM `tags` GROUP BY `tag` ORDER BY `count` DESC"); 
while($row = mysql_fetch_array($result)) { 
    $arr[$row['tagName']] = $row['count'];
  } 
  //ksort($arr); 
  return $arr; 
}

function tag_cloud() {

    $min_size = 20;
    $max_size = 60;

    $tags = tag_info();

    //$minimum_count = min(array_values($tags));
    $maximum_count = max(array_values($tags));
    $spread = $maximum_count - $minimum_count;

    if($spread == 0) {
        $spread = 1;
    }

    $cloud_html = '';
    $cloud_tags = array();

$step = ($max_size - $min_size)/($spread);


    foreach ($tags as $tag => $count) {
        $size = $min_size + ($count - $minimum_count) 
            * $step;

  $size = ($max_size + $min_size)/$spread;
        $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' 
            . '" class="tag_cloud" href="mysite/?search=' . $tag 
            . '" title="\'' . $tag  . '\' returned a count of ' . $count . '">' 
            . htmlspecialchars(stripslashes($tag)) . '</a>';
    }
    $cloud_html = join("\n", $cloud_tags) . "\n";
    return $cloud_html;

}


?>

<style type="text/css">
.tag_cloud
    {padding: 3px; text-decoration: none;
    font-family: verdana;     }
.tag_cloud:link  { color: #FF66CC; }
.tag_cloud:visited { color: #9900FF; }
.tag_cloud:hover { color: #FF66CC; background: #000000; }
.tag_cloud:active { color: #6699FF; background: #000000; }

div.wrapper{
position:absolute;
height:200px;
width:400px;


}
</style>

<div id="wrapper" class="wrapper">
<?php print tag_cloud(); ?>
</div> 

Link to comment
Share on other sites

Before using array its a good habit to define a variable as an ARRAY

 

Example :

 

function tag_info() {

$result = mysql_query("SELECT * FROM tags GROUP BY tag ORDER BY count DESC");

$arr = array();

  while($row = mysql_fetch_array($result)) {

$arr[$row['tag']] = $row['count'];

}

ksort($arr);

return $arr;

}

 

Link to comment
Share on other sites

new code

 

<?php

$db_host = "localhost";
$db_user = "";
$db_pass = "";
$db_name = "";

mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name);

function tag_info() {
  $result = mysql_query("SELECT * FROM `tags` GROUP BY `tag` ORDER BY `count` DESC");
  $arr = array(); 
  while($row = mysql_fetch_array($result)) {
    $arr[$row['tag']] = $row['count'];
  }
  ksort($arr);
  return $arr;
}

//SELECT * FROM `tags` GROUP BY `tag` ORDER BY `count` DESC
function tag_cloud() {

    $min_size = 20;
    $max_size = 60;

    $tags = tag_info();

    $minimum_count = min(array_values($tags));
    $maximum_count = max(array_values($tags));
    $spread = $maximum_count - $minimum_count;

    if($spread == 0) {
        $spread = 1;
    }

    $cloud_html = '';
    $cloud_tags = array();

$step = ($max_size - $min_size)/($spread);


    foreach ($tags as $tag => $count) {
        $size = $min_size + ($count - $minimum_count) 
            * $step;

  $size = ($max_size + $min_size)/$spread;
        $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' 
            . '" class="tag_cloud" href="/torrents-search.php?search=' . $tag 
            . '" title="\'' . $tag  . '\' returned a count of ' . $count . '">' 
            . htmlspecialchars(stripslashes($tag)) . '</a>';
    }
    $cloud_html = join("\n", $cloud_tags) . "\n";
    return $cloud_html;

}


?>

<style type="text/css">
.tag_cloud
    {padding: 3px; text-decoration: none;
    font-family: verdana;     }
.tag_cloud:link  { color: #FF66CC; }
.tag_cloud:visited { color: #9900FF; }
.tag_cloud:hover { color: #FF66CC; background: #000000; }
.tag_cloud:active { color: #6699FF; background: #000000; }

div.wrapper{
position:absolute;
height:200px;
width:400px;


}
</style>

<div id="wrapper" class="wrapper">
<?php print tag_cloud(); ?>
</div> 

 

Now i get this error GRRR

 

Warning: min() [function.min]: Array must contain atleast one element in /public_html/cloud.php on line 29

 

Warning: max() [function.max]: Array must contain atleast one element in /public_html/cloud.php on line 30

Link to comment
Share on other sites

<?php

$db_host = "localhost";
$db_user = "";
$db_pass = "";
$db_name = "";

mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name);

function tag_info() {
  $result = mysql_query("SELECT * FROM `tags` GROUP BY `tag` ORDER BY `count` DESC");
  $arr = array(); 
  while($row = mysql_fetch_array($result)) {
    $arr[$row['tag']] = $row['count'];
  }
  ksort($arr);
  return $arr;
}

//SELECT * FROM `tags` GROUP BY `tag` ORDER BY `count` DESC
function tag_cloud() {

    $min_size = 20;
    $max_size = 60;

    $tags = tag_info();

    if ( !empty($tags) ) {
        $minimum_count = min(array_values($tags));
        $maximum_count = max(array_values($tags));
        $spread = $maximum_count - $minimum_count;
    }

    if($spread == 0) {
        $spread = 1;
    }

    $cloud_html = '';
    $cloud_tags = array();

$step = ($max_size - $min_size)/($spread);


    foreach ($tags as $tag => $count) {
        $size = $min_size + ($count - $minimum_count) 
            * $step;

  $size = ($max_size + $min_size)/$spread;
        $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' 
            . '" class="tag_cloud" href="/torrents-search.php?search=' . $tag 
            . '" title="\'' . $tag  . '\' returned a count of ' . $count . '">' 
            . htmlspecialchars(stripslashes($tag)) . '</a>';
    }
    $cloud_html = join("\n", $cloud_tags) . "\n";
    return $cloud_html;

}


?>

<style type="text/css">
.tag_cloud
    {padding: 3px; text-decoration: none;
    font-family: verdana;     }
.tag_cloud:link  { color: #FF66CC; }
.tag_cloud:visited { color: #9900FF; }
.tag_cloud:hover { color: #FF66CC; background: #000000; }
.tag_cloud:active { color: #6699FF; background: #000000; }

div.wrapper{
position:absolute;
height:200px;
width:400px;


}
</style>

<div id="wrapper" class="wrapper">
<?php print tag_cloud(); ?>
</div>

 

just a patch.. will probably introduce other errors or unexpected results. There's definitely some logic errors in this whole script. That really needs to be addressed, I think...

 

PhREEEk

Link to comment
Share on other sites

Update on this issue:

 

I was approached via PM and asked to look at this directly on the server, and I agreed to.

 

The table `tags` in the database was empty, so of course that is why no arrays were being populated. Every fix generated new errors because of the constant reference to non-existent or empty arrays.

 

I have re-coded the script so far to not try and do any surgery on the arrays if mysql_num_rows does not return at least one record set. So for now, when the script is run, it is simply saying 'No data returned'. I have asked TheUnknown to provide some testing data for the `tags` field, but that's where we are right now... this one is solved, as there are no more curious errors popping up.

 

PhREEEk

Link to comment
Share on other sites

Last Update:

 

OP directed me to where I could find the original script. I figured out what the script was supposed to do, and so I created a 'test' of 10 items added to the MySQL table that was empty. After putting back some things that was in the original code, the code produced the exact desired results. So, not only does the OP have a good working 'cloud' script, he also has some error protection built into it in the case of an empty table... awaiting my paypal payment.

 

Topic solved...

 

PhREEEk

Link to comment
Share on other sites

Commented out half of the code?

 

Here is the current code I left for you:

 

<?php

$db_host = "localhost";
$db_user = "**********";
$db_pass = "**********";
$db_name = "**********";

mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name);

function tag_info() {
    $result = mysql_query("SELECT * FROM `tags` GROUP BY `tag` ORDER BY Rand() DESC");
    if ( mysql_num_rows($result) > 0 ) { 
        while($row = mysql_fetch_array($result)) {
            $arr[$row['tag']] = $row['count'];
        }
        // ksort($arr);
        return $arr;
    } else {
        return FALSE;
    }
}

//SELECT * FROM `tags` GROUP BY `tag` ORDER BY `count` DESC
function tag_cloud() {
    $min_size = 20;
    $max_size = 60;
    $tags = tag_info();
    if ( is_array($tags) && !empty($tags) ) {
        $minimum_count = min(array_values($tags));
        $maximum_count = max(array_values($tags));
        $spread = $maximum_count - $minimum_count;
        if ( $spread == 0 ) {
            $spread = 1;
        }
        $cloud_html = '';
        $cloud_tags = array();
    $step = ($max_size - $min_size)/($spread);
        foreach ( $tags as $tag => $count ) {
            $size = $min_size + ($count - $minimum_count) * $step;
            //$size = ($max_size + $min_size)/$spread;
            $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' 
                          . '" class="tag_cloud" href="/torrents-search.php?search=' . $tag 
                          . '" title="\'' . $tag  . '\' returned a count of ' . $count . '">' 
                          . htmlspecialchars(stripslashes($tag)) . '</a>';
        }
        $cloud_html = join("\n", $cloud_tags) . "\n";
        return $cloud_html;
    } else {
        return 'No data returned...';
    }
}


?>

<style type="text/css">
.tag_cloud {
    padding: 3px;
    text-decoration: none;
    font-family: verdana;
}
.tag_cloud:link {
    color: #FF66CC;
}
.tag_cloud:visited {
    color: #9900FF;
}
.tag_cloud:hover {
    color: #FF66CC;
    background: #000000;
}
.tag_cloud:active {
    color: #6699FF;
    background: #000000;
}
div.wrapper {
    position:absolute;
    height:200px;
    width:400px;
}
</style>

<div id="wrapper" class="wrapper">
<?php print tag_cloud(); ?>
</div>

 

Can you please point out where half the code is commented out?

 

Original script here:

http://srinix.wordpress.com/2007/06/04/tutorial-how-to-make-a-tag-cloud-using-php-mysql/

 

<?php

$db_host = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "test";

mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name);

function tag_info() { 
  $result = mysql_query("SELECT * FROM tags GROUP BY tagName ORDER BY Rand() DESC"); 
  while($row = mysql_fetch_array($result)) { 
    $arr[$row['tagName']] = $row['count'];
  } 
  //ksort($arr); 
  return $arr; 
}

function tag_cloud() {

    $min_size = 20;
    $max_size = 60;

    $tags = tag_info();

    $minimum_count = min(array_values($tags));
    $maximum_count = max(array_values($tags));
    $spread = $maximum_count - $minimum_count;

    if($spread == 0) {
        $spread = 1;
    }

    $cloud_html = '';
    $cloud_tags = array();

$step = ($max_size - $min_size)/($spread);


    foreach ($tags as $tag => $count) {
        $size = $min_size + ($count - $minimum_count) 
            * $step;

//  $size = ($max_size + $min_size)/$spread;
        $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' 
            . '" class="tag_cloud" href="http://localhost/content/tagcloud.php?s=' . $tag 
            . '" title="\'' . $tag  . '\' returned a count of ' . $count . '">' 
            . htmlspecialchars(stripslashes($tag)) . '</a>';
    }
    $cloud_html = join("\n", $cloud_tags) . "\n";
    return $cloud_html;

}


?>

<style type="text/css">
.tag_cloud
    {padding: 3px; text-decoration: none;
    font-family: verdana;     }
.tag_cloud:link  { color: #FF66CC; }
.tag_cloud:visited { color: #9900FF; }
.tag_cloud:hover { color: #FF66CC; background: #000000; }
.tag_cloud:active { color: #6699FF; background: #000000; }

div.wrapper{
position:absolute;
height:200px;
width:400px;


}
</style>

<div id="wrapper" class="wrapper">
<?php print tag_cloud(); ?>
</div>

 

Now then, your original post is right here where we're talking now... you asked for help getting rid of errors. You never asked for help getting the database populated, because you didn't KNOW it wasn't being populated. You PM'd and offered me $10 via paypal to fix the script errors. I agreed, and after realizing the table was empty, asked you how it was populated. You said "I don't know, here's weher I found the script...". I went there, and realized what it was doing, populated the table with 10 items and re-did parts of the script you mangled from above. It now WORKS.

 

You then come at me saying your 'searches' do not insert any tags into the database, or whatever problem you're having. I said that you didn't hire me to fix THAT part, only the script that displays the results. Of course you're going to get the same 10 results over and over... your INSERT script isn't working, and you didn't ask for that to be fixed, only this script.

 

I do expect my payment for services rendered. I also did offer to look at why data isn't being inserted, but I will do nothing further until my original payment is made.

 

PhREEEk

Link to comment
Share on other sites

you dont go and comment out 95% of the code and put a few lines of your code in. its not even the same script anymore.

The code you listed above isn't the code in the file on my server.

I dont have a problem with paying hell i donated money to this site today.

You cant go around a try to screw over people like this. I will send you the money and i bet you dont lose any sleep over screwing me !

 

 

 

 

 

Link to comment
Share on other sites

fair enough,

@TheUnknown stop being such a jerk, he got your script to do something other than produce errors,

do you really expect to be helped if you carry on like that,

we can tell by this topic that you dont really know what you are doing, so if the script is not doing what you expect then maybe its because you are not doing what your script expects,

PHP_PhREEEk has helped me and many others alot and i have never had a problem, so im thinking you just lost the help of one of the most helpful members on this forum,

good job! :-\

Link to comment
Share on other sites

If you claim some code is 'commented' out, then 2 things...

 

Your server verifies the code is working as expected, and this portion of the code has NOTHING to do with INSERTING tags into the tag database. Show me an INSERT query anywhere... you can't. You asked for help with errors that were being produced because of empty and/or non-existent arrays!

 

Secondly, if you say I left commented or mangled code on your server, then I just POSTED the FIXED code. Please point out ANY commented out sections. The only comments there are the same comments in the code by the ORIGINAL AUTHOR, not me.

 

I have NOT received payment for this work to this point.

 

PhREEEk

Link to comment
Share on other sites

One hour and 15 mins since the OP says 'the coder is paid and im moving on', and I still have not received payment, nor has the OP provided me with a verified paypal receipt showing payment. I just received a PM from the OP stating that he already paid me (which he has NOT), and to stop 'harrassing' him for the payment (I have so far only sent ONE request for payment).

 

PhREEEk

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.