scrypte
10-26-2005, 01:24 PM
Ok having two issues with two various scripts I am writing right now.
First one is I am trying to figure out how to how to take two numbers and divide them so that I can find out an average of sorts and display the whole number and two decimal points.
if($rateme>0 && $userid>0){
$sql = "INSERT INTO votes (receive,give) VALUES (\"$oldpic\",\"$userid\");";
$result = @mysql_query($sql) or die("couldn't execute query .".mysql_error());
$sql = "SELECT * FROM users WHERE `userid`!='$oldpic'";
$result = @mysql_query($sql) or die("couldn't execute query .".mysql_error());
while($row = mysql_fetch_array($result)) {
$totalpts=$row{'totalpts'};
$totalvotes=$row{'totalvotes'};
}
$totalpts=$totalpts+$rateme;
$totalvotes++;
$rankscore=$totalpts/$totalvotes;
$sql = "UPDATE users SET rankscore=\"$rankscore\",totalpts=\"$totalpts\",totalvotes=\"$totalvotes\" WHERE `userid`='$oldpic';";
$result = @mysql_query($sql) or die("couldn't execute query .".mysql_error());
}
The other problem I am having is that I cant get this script to pull more then one record from the database and display it as follows: user, user, user, user1, user1, user1
here is the coding
<?
$whereclause="WHERE status=2";
$sql = "SELECT * FROM friends WHERE `userid_1`='$userid' && `status`='2'";
$result = @mysql_query($sql) or die("couldn't execute query $sql.".mysql_error());
while($row = mysql_fetch_array($result)) {
$friend1=$row{'userid_2'};
$sql = "SELECT * FROM users WHERE `userid`='$friend1'";
$result = @mysql_query($sql) or die("couldn't execute query .".mysql_error());
while($row = mysql_fetch_array($result)) {
$username1=$row{'username'};
echo "<a href=viewprofile.php?id=$friend1>$username1</a>, \n";
}
}
$whereclause="WHERE status=2";
$sqlb = "SELECT * FROM friends WHERE `userid_2`='$userid' && `status`='2'";
$resultb = @mysql_query($sqlb) or die("couldn't execute query $sqlb.".mysql_error());
while($row = mysql_fetch_array($resultb)) {
$friend2=$row{'userid_1'};
$sql = "SELECT * FROM users WHERE `userid`='$friend2'";
$result = @mysql_query($sql) or die("couldn't execute query .".mysql_error());
while($row = mysql_fetch_array($result)) {
$username2=$row{'username'};
echo "<a href=viewprofile.php?id=$friend2>$username2</a>, \n";
}
}
?>
Any help with either of these issues would be greatly appreciated
First one is I am trying to figure out how to how to take two numbers and divide them so that I can find out an average of sorts and display the whole number and two decimal points.
if($rateme>0 && $userid>0){
$sql = "INSERT INTO votes (receive,give) VALUES (\"$oldpic\",\"$userid\");";
$result = @mysql_query($sql) or die("couldn't execute query .".mysql_error());
$sql = "SELECT * FROM users WHERE `userid`!='$oldpic'";
$result = @mysql_query($sql) or die("couldn't execute query .".mysql_error());
while($row = mysql_fetch_array($result)) {
$totalpts=$row{'totalpts'};
$totalvotes=$row{'totalvotes'};
}
$totalpts=$totalpts+$rateme;
$totalvotes++;
$rankscore=$totalpts/$totalvotes;
$sql = "UPDATE users SET rankscore=\"$rankscore\",totalpts=\"$totalpts\",totalvotes=\"$totalvotes\" WHERE `userid`='$oldpic';";
$result = @mysql_query($sql) or die("couldn't execute query .".mysql_error());
}
The other problem I am having is that I cant get this script to pull more then one record from the database and display it as follows: user, user, user, user1, user1, user1
here is the coding
<?
$whereclause="WHERE status=2";
$sql = "SELECT * FROM friends WHERE `userid_1`='$userid' && `status`='2'";
$result = @mysql_query($sql) or die("couldn't execute query $sql.".mysql_error());
while($row = mysql_fetch_array($result)) {
$friend1=$row{'userid_2'};
$sql = "SELECT * FROM users WHERE `userid`='$friend1'";
$result = @mysql_query($sql) or die("couldn't execute query .".mysql_error());
while($row = mysql_fetch_array($result)) {
$username1=$row{'username'};
echo "<a href=viewprofile.php?id=$friend1>$username1</a>, \n";
}
}
$whereclause="WHERE status=2";
$sqlb = "SELECT * FROM friends WHERE `userid_2`='$userid' && `status`='2'";
$resultb = @mysql_query($sqlb) or die("couldn't execute query $sqlb.".mysql_error());
while($row = mysql_fetch_array($resultb)) {
$friend2=$row{'userid_1'};
$sql = "SELECT * FROM users WHERE `userid`='$friend2'";
$result = @mysql_query($sql) or die("couldn't execute query .".mysql_error());
while($row = mysql_fetch_array($result)) {
$username2=$row{'username'};
echo "<a href=viewprofile.php?id=$friend2>$username2</a>, \n";
}
}
?>
Any help with either of these issues would be greatly appreciated