0

My script was working before but when I changed all the mysql tags to mysqli everything stopped working. Can some please help me make the script work agian.

Here is the script.

<?php

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

mysqli_connect($db_host, $db_user, $db_pass) or die(mysqli_error());
mysqli_select_db($db_name);

function tag_info() {

$page = "3";.
$result = mysqli_query("SELECT tags.tag, COUNT(questions_tags.tag_id) 'num' FROM questions_tags JOIN tags ON tags.id = questions_tags.tag_id WHERE questions_tags.users_questions_id = '$page' GROUP BY tags.tag ORDER BY num DESC");
while($row = mysqli_fetch_array($result)) {
$arr[$row['tag']] = $row['num'];
}
ksort($arr);
return $arr;
}

function tag_cloud() {

$min_size = .8;
$max_size = 1.5;

$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: '. $size . 'em'
. '" class="tag_cloud" href="http://www.example.com/tags/' . $tag .'/'
. '" title="\'' . $tag . '\' returned a count of ' . $count . '">'
. htmlspecialchars(stripslashes($tag)) . '</a>';
}
$cloud_html = join("\n", $cloud_tags) . "\n";
return $cloud_html;

}

?>

<div id="wrapper">
<?php print tag_cloud(); ?>
</div>
1
  • Assuming you aren't getting any obvious error messages that you can fix. Throw a die('Made it to here!'); into the script somewhere near the top and then progressively move it down. This can help if you don't know where something is breaking. Commented Dec 5, 2009 at 14:12

1 Answer 1

3

Converting from mysql_* to mysqli_* is not that simple : you should take a quick look at the manual ;-)

For instance, you'll see that mysqli_query is waiting for two parameters, in procedural style :

mixed mysqli_query  ( mysqli $link  , string $query  [, int $resultmode  ] )

Which means you have to pass the link identifier (returned by mysqli_connect) as a first parameter -- and the SQL query as the second one, and not the first one as you did.


The same stands for mysqli_select_db, btw :

bool mysqli_select_db  ( mysqli $link  , string $dbname  )

And maybe for other functions too : I didn't check the manual for every functions your are using.


Another one : when checking if the connection (call to mysqli_connect) has been successfully established or not, you should not use mysqli_error, but the dedicated function mysqli_connect_error.

And [mysqli_error], that you can get to determine if there was an error during the execution of a query, also takes the link identifier as a parameter.


As a sidenote : when reading the documentation for mysqli_*, note that this extension has two API :

  • object oriented
  • and procedural style

The functions using the procedural style often require more parameters (especially, the link identifier) than the methods when using OO-style...

Sign up to request clarification or add additional context in comments.

5 Comments

@SlaPtHiS : I've edited my answer a couple of times to add some informations : basically, you need to check every call you make to each mysqli_* function -- and taking a look at the manual would really help you ;-)
I've been trying to fix the code for a while if the manual don't help look out for another question. I'll give it another try.
Have fun :-) And, as a sidenote : activating error_reporting and display_errors might help a bit ; you can add this at the beginning of your script, while developping ::: error_reporting(E_ALL); ini_set('display_errors, 'On');
How come I never heard of this error reporting have any docs on it?
Well, the PHP manual ;-) ;; php.net/manual/en/function.error-reporting.php and php.net/manual/en/… for instance

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.