Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8188965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:05:25+00:00 2026-06-07T03:05:25+00:00

I am a self taught coder so I may be overlooking some very simple

  • 0

I am a self taught coder so I may be overlooking some very simple answer I didn’t pick up in class, but…

I have a DB full of different businesses, where their Unique IDcorresponds with the name of their picture on my server. Every time a page on my website loads I want php to grab the business (and subsequent ad) with the fewest views. In case it is pertinent I also have two different sizes for ads. I will try to illustrate.

Table:

Business Name | Unique ID | Views | Size
--------------+-----------+-------+------
Business 1    | 1         | 50    | Small
Business 2    | 2         | 9     | Small
Business 3    | 3         | 67    | Large
Business 4    | 4         | 9     | Large

so I use this script to retrieve the business with the lowest views

SELECT * FROM ads WHERE size='Large' ORDER BY views ASC

Now to my question – this works until all views get to “9” then it seems like it just picks two ads (one of each size) to always display. So in the example you would expect Business 4 to be selected, but for some reason business 3 is always the one chosen.

Also, when I investigate in PhpMyAdmin and I click on the column name views to sort by views and the two businesses are always together at the top or bottom (ASC and DESC respectively) never mixing in with the list. Right now when I sort ASC I get:

Views
50
67
9
9 
9
9

The 50 and 67 are obviously not in correct order and they are the two that are always shown on the webpage. It seems like after “9” these two are assigned some sort of priority, I can’t figure out.

I should also mention the way the table is handled when called by the specific web page:

$result = mysql_query("SELECT * FROM ads WHERE size='Large' ORDER BY views ASC") or die(mysql_error());
$productCount = mysql_num_rows($result); // count the output amount
if ($productCount > 0) {
    if($row = mysql_fetch_array($result)){ 
            $id = $row["id"];
        $url = $row["url"];
        $views = $row["views"];
            $businessName = $row["businessName"];
    }
}
$views = $views + 1;
$sql = mysql_query("UPDATE ads SET views='$views' WHERE id='$id'");

This is in the php code of every page on my website.

The ads are displayed with this html code:

<div id="ad1">
        <a href="<?php echo $url; ?>" target="_blank"> <img src="inventory_images/<?php echo $id; ?>.jpg" alt="<?php echo $businessName; ?>" height="144" width="216"/></a>
    </div>

Hopefully that is enough information, your help is greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:05:27+00:00Added an answer on June 7, 2026 at 3:05 am

    Make sure your “views” column is set to type “int” and not “char” or “varchar”, or it won’t sort as you expect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've taught myself Obj-C, and have been self-teaching Cocoa, but adding Core Data to
As a self-taught (poorly) PHP coder, I have exhausted all the trial-and-error possibilities so
Sorry for the simple question, but I am self taught and know that there
I have been in web programming for 2 years (Self taught - a biology
I have 2 1/2 years experience of VB.Net, mostly self taught, so please bear
I am a self-taught computer programming enthusiast. I have learn C, quite a bit
So, I'm self-taught in the art of LaTeX, which means there are some really
I'm a self-taught coder and I like to debug by echoing suspicious variables and
As a mostly self-taught programmer, I have never really had anyone explain why certain
I am relatively new to writing in C. I have self taught myself using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.