I'm working on my first php project, so I apologize if the questions seem a little simple . Thanks for your help it is greatly appreciated .
Here is my classes.php file. I want the write function to take the table the field I'm looking for and the userid, but it is not working properly.
I get this error when I try to run the function.
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 'Resource id #3' at line 1
The rank function is supposed to load up all the userids in the database into an array and use usort to rank them according their win/lose ratio. I was a little confused on how to use the usort function. Any help here would be greatly appreciated.
I'm still working on the write function, but I assume it will be pretty similar to the read function.
<?php
class ladderfunctions
{
function connect
{
[b]HIDDEN[/b]
}
function selectdb( $db )
{
mysql_select_db("$db")or die("cannot select DB");
}
function read( $table, $field, $userid )
{
$sql="SELECT $field FROM $table WHERE userid='$userid'";
$result=mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($result)) {
// userid exists
$sql="SELECT $field FROM $table WHERE userid='$userid'";
$result=mysql_query($result) or die(mysql_error());
$row=mysql_fetch_assoc($result);
return $row['$field']; }
}
function write( $table, $field, $userid )
{
}
function rank()
{
$query="select * from ladder;
$result=mysql_query($query);
$row=mysql_fetch_row($result);
$array[mysql_num_rows($result)];
//Store userid into array
for( int i=0; i<mysql_num_rows($result); i++)
{
$array[i]=$row[i];
}
//Sort userid in array by win/lose ratio
function cmp($a, $b)
{
if( ((read(ladder, win, $a) / (read(ladder, lose, $a)) > read(ladder, win, $b) / read(ladder, lose, $b))) )
{
return $a;
}
else
return $b;
}
usort($array, "cmp");
return $array;
}
}
?>