Jump to content

Stupid Stupid mysql Bug ?


scotchegg78

Recommended Posts

Hi guys.

 

My code works fine locally just not on the live server.

When i run the sql qry on the live server in mysql admin it also works fine!?

 

Anway its not getting the last row regionID, but its getting everything else? row regionName etc..

 

$sql = "SELECT * FROM cr_region LEFT JOIN cr_office USING (regionID) ORDER BY cr_region.regionID";

$result = $dblink->query($sql);
$lastid = '';
while($row = $result->fetch_assoc()){
    if($lastid != $row['regionID']){
    	
        $array[$row['regionID']] = array('regionID'=>$row['regionID'],'regionName'=>$row['regionName'],'address1'=>$row['regionaddress1'],'address2'=>$row['regionaddress2'],'address3'=>$row['regionaddress3'],'address4'=>$row['regionaddress4'],'town'=>$row['regiontown'],'county'=>$row['regioncounty'],'country'=>$row['regioncountry'],'postcode'=>$row['regionpostcode'],'webaddress'=>$row['webaddress'],'regionEmail'=>$row['regionEmail'],'regionTelephone'=>$row['regionTelephone'],'message'=>$row['message']);
    
        $lastid = $row['regionID'];
        
    }
    echo $row['regionID'];
    
    if(!is_null($row['officeID'])){
        $array[$row['regionID']]['offices'][] = array('address1'=>$row['address1'],'address2'=>$row['address2'],'address3'=>$row['address3'],'address4'=>$row['address4'],'town'=>$row['town'],'county'=>$row['county'],'country'=>$row['country'],'postcode'=>$row['postcode']);
    }

}

 

Whats going on!? only thing is we are on mysql 5 local and mysql 4 live?

So again, It gets everything else except for the last region ID from the last row? but the qry in admin seems fine, when I also print the array its all there except the last $row[regionID]?

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/109877-stupid-stupid-mysql-bug/
Share on other sites

ok ok,

 

I have noticed the mysql admin run has two regionID columns, one from my region table and one from my office table.

So its allowing ambiguity?! i guess i have to address them via row direct not assoc.

No, you have to alias them, or don't use *.

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.