Jump to content

Is row counting causing duplicate entries?


wright67uk

Recommended Posts

For some reason my code is creating duplicate entries within my database.

Am I using row count in the wrong way? Line 32

<html><body>
 <?php ob_start(); 
 
                $mysqli = new mysqli('', '', '', ''); 
				 
                $url = "http://whdn.williamhill.com/pricefeed/openbet_cdn?action=template&template=getHierarchyByMarketType&classId=2&marketSort=--&filterBIR=N";
                $root = @simplexml_load_file($url);
                if ($root) {
                    $data = get_object_vars($root);
                    $response = $data['response'];
                    $class = $response->williamhill->class;
                    $attClass = $class->attributes();
                    $types = $class->type;

                foreach ($types as $_type) {
                     $_attributeType = $_type->attributes();
                     $markets = $_type->market;
                     $html = '';
					 	
        foreach ($markets as $_market) {$_attributeMarket = $_market->attributes();                               
        $participants = $_market->participant;                                           
                                                
                     foreach ($participants as $_participants) {$_attributeParticipant = $_participants->attributes();
                     $name = $_attributeParticipant["name"];   
                     $odds = $_attributeParticipant["odds"];
                     $race = $_attributeMarket["name"];
                     echo $name . " - " . $odds . " - " . $race ?><br/>
                     
                    <?php  if ($mysqli->connect_error) {die('Connect Error: ' . $mysqli->connect_error);}
					
		      if ($stmt = $mysqli->query("SELECT * FROM races WHERE name = '$name' and race = '$race' ")) {
                      $row_cnt = $stmt->num_rows;	
                      $stmt->close();                                                                             }
                    
                     if ($row_cnt > 0) {	
                    $stmt = $mysqli->prepare("UPDATE races SET odds = ?, race = ? WHERE name = ?"); 
                    $stmt->bind_param('sss', $odds, $race, $name);
                    $stmt->execute();
                    $stmt->close();   }

                     else if (($name !="2nd Favourite") AND ($name !="Favourite")) { 
                    $stmt = $mysqli->prepare("INSERT INTO races VALUES (?, ?, ?)");
                    $stmt->bind_param('sss', $name, $odds, $race);
                    $stmt->execute();
                    $stmt->close();                                                } 
					} 
                                                                                                            } 
                  } 
	             } 
	
	?>        

<?php ob_flush(); ?>

</body></html>

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.