MyBB Community Forums

Full Version: Help in consult of mybb
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello.

My question and problem is ¿How to use this consult in mybb?

$consulta2= "SELECT (COUNT(*) + 1) AS rank FROM table WHERE scorem > ".$score." OR scorem = ".$score." AND tiempo > ".$tiempo_jugador;
$resultado2= mysql_query($consulta2, $conex) or die (mysql_error());
$rank = mysql_fetch_array($resultado2);
echo $rank[0];

Example of the result: 25

I tried this and it doesn't work:

global $db;
$query = $db->query("SELECT (COUNT(*) + 1) AS rank FROM table WHERE scorem > ".$score." OR scorem = ".$score." AND tiempo > ".$tiempo_jugador);
$rank = fetch_array($query);
echo $rank[0];

Result:
MyBB SQL Error - [20] array ( 'error_no' => 1064, 'error' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \') OR scorem = () AND tiempo > ()\' at line 1', 'query' => 'SELECT (COUNT(*) + 1) AS rank FROM sv_fun_maps WHERE scorem > () OR scorem = () AND tiempo > ()', )

Sorry for my bad english. Blush
Use the MyBB database method simple_select().

$query = $db->simple_select('table', '(COUNT(*) + 1) AS scorem', "scorem > '{$score}' AND tiempo > '{$tiempo_jugador}'");
$rank = $db->fetch_field($query, 'scorem');
echo $rank;

EDIT: I missed your OR clause.
Use:
$query = $db->simple_select('table', '(COUNT(*) + 1) AS scorem', "scorem >= '{$score}' AND tiempo > '{$tiempo_jugador}'");
Thanks for the help me.
New error:
SQL Error:
   1146 - Table 'sinaloense.mybb_sv_fun_maps' doesn't exist
The name of the table is "sv_fun_maps", is not "mybb_sv_fun_maps"
Is it not in the same database as MyBB or is it in a separate database?
Is a new table created in the same database, but the function "simple_select" automatically added to the beginning of the name of the following "mybb_mytable " table , but my table does not contain the name of mybb_

My english is super bad C:
Can you please show me how you're using it?
$rank = $db->simple_select('sv_fun_maps', '(COUNT(*) + 1) AS scorem', "scorem >= '{$score}' AND tiempo > '{$tiempo_jugador}'");
echo $rank;

[Image: U1luIqp.png]

Can it be solved without renaming the table : mybb_sv_fun_maps ?

Edit: Thanks for help me, tomorrow will try renaming the table "mybb_sv_fun_maps".
Change the simple_select line to:
$rank = $db->simple_select("SELECT (COUNT(*) + 1) AS `scorem` FROM `sv_fun_maps` WHERE `scorem` >= '{$score}' AND `tiempo` > '{$tiempo_jugador}'");

I just realised I didn't even change the method.. Sorry. Use:
$rank = $db->write_query("SELECT (COUNT(*) + 1) AS `scorem` FROM `sv_fun_maps` WHERE `scorem` >= '{$score}' AND `tiempo` > '{$tiempo_jugador}'");
I did not work , better not show you the rank , but thank you very much for helping me.