Jump to content

PHP/MYSQL Help!


nauir

Recommended Posts

I am trying to make a script that picks 3 horses from the database (from shows_enteredhorses) all from the same showid and give only 3 a place (1-3 places). After it does that showid I want it to move on to the next. For example, the showids could be 1, 71, 141, 211, 281 (These aren't the real showids).

 

Example:

Showid: 1 Horseid: 2 Place: 3

Showid: 1 Horseid: 1 Place: 2

Showid: 1 Horseid: 3 Place: 1

 

Showid: 71 Horseid: 3 Place: 1

Showid: 71 Horseid: 2 Place: 3

Showid: 71 Horseid: 1 Place: 2

 

and so on... Make sense? Here is what I have in my code (it prints out 9 places for each showid).

 

$today=date('Y-m-d');

$query=mysql_query("SELECT DISTINCT * from shows_enteredhorses WHERE rundate='$today' ORDER BY RAND() LIMIT 3")or die(mysql_error());
$num=mysql_num_rows($query);

if($num > 0){
// `judgedid` ,
//`showid` ,
//`level` ,
//`discipline` ,
//`rundate` ,
//`horseid` ,
//`place` ,
//`prize` 
$q = "insert into shows_judged (showid,level,discipline,rundate,horseid,place) VALUES ";
$place = 1;
while($row=mysql_fetch_array($query)){
$hh=mysql_query("select * from horses where hid='$row[horseid]'")or die(mysql_error());
$h=mysql_fetch_array($hh);

	$q .= "('$row[showid]','$row[level]','$row[discipline]','$row[rundate]','$row[horseid]','$place'),";
	switch($place){
		case 1:
		if($row[level] == "Garnet 1" || $row[level] == "Garnet 2" || $row[level] == "Garnet 3"){
		$qur = "UPDATE horses  SET `firsts` = (`firsts` + 1), `points` = (`points` + 500) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+500 where id='$h[owner]'";
		}
			if($row[level] == "Bronze Medallion"){
		$qur = "UPDATE horses  SET `firsts` = (`firsts` + 1), `points` = (`points` + 600) WHEREhid ='{$row['hid']}'";
		$upp= "update users set money=money+600 where id='$h[owner]'";
		}
		if($row[level] == "Jade 1" || $row[level] == "Jade 2" || $row[level] == "Jade 3"){
		$qur = "UPDATE horses  SET `firsts` = (`firsts` + 1), `points` = (`points` + 700) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+700 where id='$h[owner]'";
		}
			if($row[level] == "Silver Medallion"){
		$qur = "UPDATE horses  SET `firsts` = (`firsts` + 1), `points` = (`points` + 800) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+800 where id='$h[owner]'";
		}
		if($row[level] == "Titanite 1" || $row[level] == "Titanite 2" || $row[level] == "Titanite 3"){
		$qur = "UPDATE horses  SET `firsts` = (`firsts` + 1), `points` = (`points` + 900) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+900 where id='$h[owner]'";
		}
			if($row[level] == "Gold Medallion"){
		$qur = "UPDATE horses  SET `firsts` = (`firsts` + 1), `points` = (`points` + 1000) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+1000 where id='$h[owner]'";
		}
		if($row[level] == "National Champion"){
		$qur = "UPDATE horses  SET `firsts` = (`firsts` + 1), `points` = (`points` + 1500) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+1500 where id='$h[owner]'";
		}
		if($row[level] == "World Champion"){
		//$qur = "UPDATE horses  SET `firsts` = (`firsts` + 1), `points` = (`points` + 5000) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+5000 where id='$h[owner]'";
		}
		break;
		case 2:
		if($row[level] == "Garnet 1" || $row[level] == "Garnet 2" || $row[level] == "Garnet 3"){
		$qur = "UPDATE horses  SET `seconds` = (`seconds` + 1), `points` = (`points` + 300) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+300 where id='$h[owner]'";
		}
			if($row[level] == "Bronze Medallion"){
		$qur = "UPDATE horses  SET `seconds` = (`seconds` + 1), `points` = (`points` + 400) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+400 where id='$h[owner]'";
		}
		if($row[level] == "Jade 1" || $row[level] == "Jade 2" || $row[level] == "Jade 3"){
		$qur = "UPDATE horses  SET `seconds` = (`seconds` + 1), `points` = (`points` + 500) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+500 where id='$h[owner]'";
		}
			if($row[level] == "Silver Medallion"){
		$qur = "UPDATE horses  SET `seconds` = (`seconds` + 1), `points` = (`points` + 600) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+600 where id='$h[owner]'";
		}
		if($row[level] == "Titanite 1" || $row[level] == "Titanite 2" || $row[level] == "Titanite 3"){
		$qur = "UPDATE horses  SET `seconds` = (`seconds` + 1), `points` = (`points` + 700) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+700 where id='$h[owner]'";
		}
			if($row[level] == "Gold Medallion"){
		$qur = "UPDATE horses  SET `seconds` = (`seconds` + 1), `points` = (`points` + 800) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+800 where id='$h[owner]'";
		}
		if($row[level] == "National Champion"){
		$qur = "UPDATE horses  SET `seconds` = (`seconds` + 1), `points` = (`points` + 1250) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+1250 where id='$h[owner]'";
		}
		if($row[level] == "World Champion"){
		//$qur = "UPDATE horses  SET `seconds` = (`seconds` + 1), `points` = (`points` + 5000) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+4000 where id='$h[owner]'";
		}
		break;
		case 3:
		if($row[level] == "Garnet 1" || $row[level] == "Garnet 2" || $row[level] == "Garnet 3"){
		$qur = "UPDATE horses  SET `thirds` = (`thirds` + 1), `points` = (`points` + 150) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+150 where id='$h[owner]'";
		}
			if($row[level] == "Bronze Medallion"){
		$qur = "UPDATE horses  SET `thirds` = (`thirds` + 1), `points` = (`points` + 300) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+300 where id='$h[owner]'";
		}
		if($row[level] == "Jade 1" || $row[level] == "Jade 2" || $row[level] == "Jade 3"){
		$qur = "UPDATE horses  SET `thirds` = (`thirds` + 1), `points` = (`points` + 350) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+350 where id='$h[owner]'";
		}
			if($row[level] == "Silver Medallion"){
		$qur = "UPDATE horses  SET `thirds` = (`thirds` + 1), `points` = (`points` + 400) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+400 where id='$h[owner]'";
		}
		if($row[level] == "Titanite 1" || $row[level] == "Titanite 2" || $row[level] == "Titanite 3"){
		$qur = "UPDATE horses  SET `thirds` = (`thirds` + 1), `points` = (`points` + 500) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+500 where id='$h[owner]'";
		}
			if($row[level] == "Gold Medallion"){
		$qur = "UPDATE horses  SET `thirds` = (`thirds` + 1), `points` = (`points` + 600) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+600 where id='$h[owner]'";
		}
		if($row[level] == "National Champion"){
		$qur = "UPDATE horses  SET `thirds` = (`thirds` + 1), `points` = (`points` + 1000) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+1000 where id='$h[owner]'";
		}
		if($row[level] == "World Champion"){
		//$qur = "UPDATE horses  SET `thirds` = (`thirds` + 1), `points` = (`points` + 5000) WHERE hid ='{$row['hid']}'";
		$upp= "update users set money=money+3000 where id='$h[owner]'"; 
		}
		break;
		//case 4:

		//break;
		//case 5:

		//break;
		//case 6:

		//break;

	}

    	mysql_query($qur)or die(mysql_error()); //horses points
	mysql_query($upp)or die(mysql_error()); //users money
	//mysql_query("delete from shows_enteredhorses where entryid='$row[entryid]'")or die(mysql_error()); 
	print "Showid: #$row[showid] | Horse: #$row[horseid] | Place: $place<br>";
	$place++;
}

$q = trim($q,',');
mysql_query($q)or die(mysql_error());
             }//while

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/151644-phpmysql-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.