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
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 *.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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