www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Help needed with Querying and Printing one of same named item

Hybrid View

  1. #1
    Join Date
    Mar 2011
    Posts
    67

    resolved [RESOLVED] Help needed with Querying and Printing one of same named item

    Hi

    I am trying to figure out how to print one of same-named pieces of software from my database. I'll explain further.

    I have a list of software to show people what has been recently updated.

    For example in my database I have the following columns.

    id, name, version, link, description, dateadded, category

    and this is my code to query and print the records:

    PHP Code:
        $query=("SELECT * FROM software ORDER BY name ASC");
        
    $result=mysql_query($query) or die('Sorry, could not get software at this time '.mysql_error());
            while(
    $row=mysql_fetch_array($result))  {

                
    $id=$row['id'];
                
    $name=$row['name'];
                
    $version=$row['version'];
                
    $link=$row['link'];
                
    $description=$row['description'];
                
    $dateadded=$row['dateadded'];
                
    $category=$row['category'];

    echo 
    "<div id=\"softwaredistro_page_main\">";
    echo 
    "$name"&nbsp<a href=\"singlesoftwarepiece.inc.php?id=$id&name=$name&version=$version&url=$link&description=$description&category=$category\"/>go</a>" "<br>";

    This code works well to print out my records. Now here is the problem. I have some pieces of software that have been updated and entered into my database a two or three times so I end up with:

    (For example):

    Calibre
    Evolution
    Evolution
    Opera Web Browser
    Opera Web Browser
    And so on...

    How do I query, if it is done in the query, obtain only the most recently updated version of a piece of software so I end up with:

    Calibre
    Evolution
    Opera Web Browser
    And so on...

    I want to keep all versions, so deleting an old one is not something I want o do.

    And, lastly, I did try to use LIMIT clause in my query with no success. Otherwise, I am just stumped.

    Thanks in advance,
    Randy

  2. #2
    Join Date
    Nov 2012
    Posts
    1
    Use a temporary variable to check is the $name already is used

    PHP Code:
    $query=("SELECT * FROM software ORDER BY name ASC, version DESC");
        
    $result=mysql_query($query) or die('Sorry, could not get software at this time '.mysql_error());
            while(
    $row=mysql_fetch_array($result))  {

                
    $id=$row['id'];
                
    $name=$row['name'];
                
    $version=$row['version'];
                
    $link=$row['link'];
                
    $description=$row['description'];
                
    $dateadded=$row['dateadded'];
                
    $category=$row['category'];

                if (!isset(
    $temp[$name])) {

    echo 
    "<div id=\"softwaredistro_page_main\">";
    echo 
    "$name"&nbsp<a href=\"singlesoftwarepiece.inc.php?id=$id&name=$name&version=$version&url=$link&description=$description&category=$category\"/>go</a>" "<br>"; }

                
    $temp[$name]=1;



  3. #3
    Join Date
    Mar 2011
    Posts
    67
    Thanks for the help. I will give this a try tonight.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles