Jump to content

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result reso


winnard2008

Recommended Posts

RE:Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/myweddin/public_html/categorybanner.php on line 48

 

 

Hi Guys,

 

This is my first post, but something that is causing major problems.

 

Our website recently changed server and thus the PHP was upgraded from 4.3 to 5.2 and MySQL was upgraded to 5.

 

Our website was working perfectly until this change and now the above error is causing problems.

 

Another problem is that our programmer recently quit, just before the changeover and as I am a total basic PHP programmer (Of 1 week!!!) I have know idea what to do to fix it. As our business relies on the smooth running of this site I need to get it fixed A.S.A.P.

 

 

Here is the entire code from the page that does not work properly.

 

 

<?PHP
  //topbanner   =  1 pulls out 468*60 banners
  //sidebanner  =  1 pulls out 125 wide by scaled height side banners
  
  //get random banner trying to match category and area
  $query = "Select * From siteBanners Where topbanner=1 AND categoryID = '$catid' AND areaID = '$areaid' Order By Rand() Limit 1";
  $result = mysql_query($query);
  $count = mysql_num_rows($result);  
  if($count > 0){
    while ($row = mysql_fetch_array($result)){//get banner details
      $bannerID = $row['bannerID']; 
      $bannerImage = $row['bannerImage']; 
      $altText = $row['altText'];
  $impressions = $row['impressions'] + 1;//this code updates banner stats
  $query = "Update siteBanners set impressions = '$impressions' where bannerID = '$bannerID'"; //get random banner
  $result = mysql_query($query);
  //output banner - as we want to keep a log of banner click-throughs, we will link to a interim page

?>

<a href="updateclicks.php?id=<?PHP echo $bannerID; ?>">
<img src="http://www.myweddingdreams.co.uk/banners/<?PHP echo $bannerImage ?>" alt="<?PHP echo $altText; ?>" border="0"  /></a>
<?PHP


    }//end of loop
    mysql_free_result($result); //free up result set memory
  }
  
  if($count == 0){//try and match category on its own without area
    $query = "Select * From siteBanners Where topbanner=1 AND categoryID = '$catid' Order By Rand() Limit 1";
    $result = mysql_query($query);
    $count = mysql_num_rows($result);

if($count > 0){
    while ($row = mysql_fetch_array($result)){//get banner details
      $bannerID = $row['bannerID']; 
      $bannerImage = $row['bannerImage']; 
      $altText = $row['altText'];
  $impressions = $row['impressions'] + 1;//this code updates banner stats
  $query = "Update siteBanners set impressions = '$impressions' where bannerID = '$bannerID'"; //get random banner
  $result = mysql_query($query);
  //output banner - as we want to keep a log of banner click-throughs, we will link to a interim page
?>

<a href="updateclicks.php?id=<?PHP echo $bannerID; ?>">
<img src="http://www.myweddingdreams.co.uk/banners/<?PHP echo $bannerImage ?>" alt="<?PHP echo $altText; ?>" border="0" class="dark_pink_border" /></a>
<?PHP
    }//end of loop
    mysql_free_result($result); //free up result set memory
  }else{//no match found so use allsite banner instead
    $query = "Select * From siteBanners Where topbanner=1 AND showall = 1 Order By Rand() Limit 1";
    $result = mysql_query($query);

while ($row = mysql_fetch_array($result)){//get banner details
      $bannerID = $row['bannerID']; 
      $bannerImage = $row['bannerImage']; 
      $altText = $row['altText'];
  $impressions = $row['impressions'] + 1;//this code updates banner stats
  $query = "Update siteBanners set impressions = '$impressions' where bannerID = '$bannerID'"; //get random banner
  $result = mysql_query($query);
  //output banner - as we want to keep a log of banner click-throughs, we will link to a interim page
?>

<a href="updateclicks.php?id=<?PHP echo $bannerID; ?>">
<img src="http://www.myweddingdreams.co.uk/banners/<?PHP echo $bannerImage ?>" alt="<?PHP echo $altText; ?>" border="0" class="dark_pink_border" /></a>
<?PHP	
    }//end of loop

  }//end of else no match found

  }//end of if count == 0
  
?>

 

 

Now i have added this thread to a different forum earlier today, but they were useless. I managed to narrow the problem down to this section

 

$impressions = $row['impressions'] + 1;//this code updates banner stats
  $query = "Update siteBanners set impressions = '$impressions' where bannerID = '$bannerID'"; //get random banner
  $result = mysql_query($query);
  //output banner - as we want to keep a log of banner click-throughs, we will link to a interim page

 

but as I had to keep telling them, i am literally one week into my PHP learning and no nothing of the terminology so need step by step instructions. If you need anything to help either re-write this part of the script or info regarding the database structure for this code just ask and I will help as we need to get this part of the script working.

 

 

 

If anybody could help me fix this today then that would be so much appreciated.

 

Everything was working fine until the PHP upgrade which makes me think that maybe our programmers code somewhere is using out dated code.

 

 

Please please help

 

 

Danny

Link to comment
Share on other sites

It should be put outside of the loop i.e.

 

while(condition) {
  // Do something...
}

mysql_free_result($mysql_resource);

 

If that was me I would remove it, but if you're worried about large memory allocations then by all means keep it. In my experience it hasn't really done anything significant for me.

 

As I said, this may not be the only problem.

Link to comment
Share on other sites

I took out the mysql_free_result($result) and it still has the same error.

 

 

When I was in the other forum with this same topic, I commented out this part of the code which read

 

$impressions = $row['impressions'] + 1;//this code updates banner stats
  $query = "Update siteBanners set impressions = '$impressions' where bannerID = '$bannerID'"; //get random banner
  $result = mysql_query($query);

 

once this was commented out no errors appeared on the page.

 

This part of the script was created to store a record of click throughs and impressions so that we had figures to give advertisers. So we do need to get this part working.

 

Any ideas

Link to comment
Share on other sites

Would it be a difficult task to re-write this script?

 

 

Basically it requires only three things

 

When somebody selects an area they then have to select a category. Once this page loads up this script gets to work.

 

 

It loads a top banner in three ways.

 

 

1.) It checks to see if there is a top banner that matches the category and the area, if so loads one up.

2.) If no match is found it searches the database for a banner that matches the category.

3.) If no match is found it searches the database for a banner that is national and appears in every category and area.

 

 

For every banner that loads up we need to record click through and impressions.

 

 

If I could provide the relevant database structure of the current table, would it be an easy job for someone to re-write the script?

 

 

Any help would be saving my life. So come on be a samaritan.

Link to comment
Share on other sites

Wouldn't be difficult at all, but we're not here to write your code for you, we're here to help you with what you've already done.  If you want someone to write it for you, try the freelance section.

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.