Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Oct 2006
    Location
    north poll
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Display top 10 overall rated tutorials?

    Hi i have been developing a tutorial system for a while now and have gotten pretty much everything done but this. I want the top 10 overall rated tutorials to be displayed in the html form below. I was thinking of using the while() loop but then saw that it would not work since their i cant use it and have to <td></td>s in the same <tr> which is being looped. Any thoughts? the score is determined by a field in my table called score and i was thinking of using a query that orders by score.
    Thanks

    Code:
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
     <tr>
      <td width="10%">Thumb for tut w/ highest score here</td>
      <td width="40%"><a href="link to it here">Name of Tutorial</a> - Description</td>
      <td width="10%">Thumb for tut w/ second highest score here</td>
      <td width="40%"><a href="link to it here">Name of Tutorial</a> - Description</td>
     </tr>
     <tr>
      <td width="10%">Thumb for tut w/ third highest score here</td>
      <td width="40%"><a href="link to it here">Name of Tutorial</a> - Description</td>
      <td width="10%">Thumb for tut w/ fourth highest score here</td>
      <td width="40%"><a href="link to it here">Name of Tutorial</a> - Description</td>
     </tr>
     <tr>
      <td width="10%">Thumb for tut w/ fifth highest score here</td>
      <td width="40%"><a href="link to it here">Name of Tutorial</a> - Description</td>
      <td width="10%">Thumb for tut w/ sixth highest score here</td>
      <td width="40%"><a href="link to it here">Name of Tutorial</a> - Description</td>
     </tr>
    </table>
    Last edited by LoRd_aLmIghTy; 12-26-2006 at 03:53 PM.

  • #2
    Regular Coder anarchy3200's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    261
    Thanks
    0
    Thanked 1 Time in 1 Post
    Ok, may be a better way and i am open to criticism but how i usually do it is with a while. Before starting the while initialise a variable with a 0 value,
    PHP Code:
    $count 0;
    print 
    "<tr>";
    while () {
    $count++;
    if(
    $count%== 0){
    print 
    "</tr><tr>";
    }
    print 
    "<td>Whatever</td>";
    }
    print 
    "</tr>"
    As this loops, the start/end tr are only used if the count field/2 has no remainder which happens every other record, may require some slight corrections to get it to display correctly but you should get the general idea.

    Hope this helps.
    Mike

  • #3
    New Coder
    Join Date
    Oct 2006
    Location
    north poll
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes i understand that but thats just displaying them in a list sort of. i wanted them to be 2 apiece in side one <tr> and the places where their is no data to display no entrie in that <td>. if you dont understand look at he html table i posted in my earlier post. hope this helps clear confusion.

    thanks

  • #4
    Regular Coder
    Join Date
    Oct 2005
    Location
    Surrey, England
    Posts
    286
    Thanks
    2
    Thanked 2 Times in 2 Posts
    PHP Code:
    <?php

    // ...

    echo '<table border="0" cellpadding="0" cellspacing="0" width="100%">
     <tr>
    '
    ;
    $columns 2;
    $resultSet mysql_query('SELECT * FROM `table` ORDER BY `highscore` DESC LIMIT 0,10');
    $rowNum mysql_num_rows($resultSet);
        if(
    $rowNum == 0)
            {
                echo 
    '  <td align="center">No results returned!</td>';
            }
            else
            {
                if(
    $rowNum $columns != 0)
                {
                    
    $rowNum += $columns $rowNum $columns;
                }
                while(
    $rowNum-- > 0)
                {
                    echo 
    '  <td';
                    if(
    $result mysql_fetch_assoc($resultSet))
                    {

        
    //Edit these echo's

                        
    echo ' width="10%">Thumb for tut w/ highest score here</td>
    '
    ;                  echo '  <td width="40%"><a href="' $result["link_to_tut"] . '">Name of tutorial</a> - Description etc....</td';

        
    //Dont edit beyond here

                    
    }else{echo ' colspan="2"';}
                    echo 
    '></td>
    '
    ;
                    if(
    $rowNum != && $rowNum $columns == 0)
                    {
                        echo 
    ' </tr>
     <tr>
    '
    ;
                    }
                }
    }
    echo 
    ' </tr>
    </table>'
    ;

    ?>
    The code above should work after you edit the query....

    ...and anarchy3200 wasnt confused...he was correct in the code he knocked up and should have provided a bit of clarity in how to make the code your asking for. His code simply displays the "<td>What ever</td>" twice, then places a "</tr><tr>" which what your aking for. You could have edited the echo "<td>What ever</td>" to display what ever you want....
    Daniel Warner
    - - - - - - - - - -
    GuitarMart.co.uk - Free Online Classified Advertisement for Guitarists in the United Kingdom. Free Ads with a Free Photo.

  • #5
    New Coder
    Join Date
    Oct 2006
    Location
    north poll
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks daniel thats pretty much what i meant except for the no data thing. i meant for each <td> with no data i wanted it to have a thumb of my choosing and text saying no entrie. so basicly if i only had 2 tutorials the top <tr> would have them and the bottom 4 <tr>'s would have each <td> saying no content. can you show me that code please.

    thanks

  • #6
    Regular Coder anarchy3200's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    261
    Thanks
    0
    Thanked 1 Time in 1 Post
    Hi, sorry about before, i did try to update my post and add another reply but my internet kept dropping out...
    As to the alternate text if an entry doesn't exist try replacing the lines:
    PHP Code:
          echo ' width="10%">Thumb for tut w/ highest score here</td>';                  echo '  <td width="40%"><a href="' $result["link_to_tut"] . '">Name of tutorial</a> - Description etc....</td'
    with something like:
    PHP Code:
    if(strlen($result["link_to_tut"])>0){
          echo 
    ' width="10%">Thumb for tut w/ highest score here</td> 
    '
    ;                  echo '  <td width="40%"><a href="' $result["link_to_tut"] . '">Name of tutorial</a> - Description etc....</td'
    }else{
          echo 
    ' width="10%">Thumb Here</td> 
    '
    ;                  echo '  <td width="40%">No Content</td'


    With this if there is a value of anysort returned from the query then the first echo will run and the value will be displayed, if there is not anything returned from the query the second set of echo's are shows displaying that there is no content.
    Mike

  • #7
    New Coder
    Join Date
    Oct 2006
    Location
    north poll
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for that thats 50% of what i was asking. the other part is lets say i have 3 tutorials and i set my query in that script to limit 6 i want the 3 to b displayed which they do and the right <td> next to the third goes to no content which i want. but i also want the remaining last 2 <tr>s to display No content in their <td>'s as well.

    Thanks everyone

  • #8
    Regular Coder anarchy3200's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    261
    Thanks
    0
    Thanked 1 Time in 1 Post
    Updated soon, code removed as it was wrong..!
    Last edited by anarchy3200; 12-26-2006 at 08:57 PM. Reason: Wrong
    Mike

  • #9
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Something like this?
    PHP Code:
    <?php

    // ... 

    define('SHOWN_TUTORIALS'10);

    echo 
    '<table border="0" cellpadding="0" cellspacing="0" width="100%"> 
     <tr> 
    '

    $columns 2
    $resultSet mysql_query('SELECT * FROM `table` ORDER BY `highscore` DESC LIMIT 0,'.SHOWN_TUTORIALS); 
    //$rowNum = mysql_num_rows($resultSet); 
    //    if($rowNum == 0) 
    //        { 
    //            echo '  <td align="center">No results returned!</td>'; 
    //        } 
    //        else 
    //        { 
                
    $rowNum SHOWN_TUTORIALS;
                if(
    $rowNum $columns != 0
                { 
                    
    $rowNum += $columns $rowNum $columns
                } 
                while(
    $rowNum-- > 0
                { 
                    echo 
    '  <td'
                    if(
    $result mysql_fetch_assoc($resultSet)) 
                    { 

        
    //Edit these echo's 

                        
    echo ' width="10%">Thumb for tut w/ highest score here</td> 
    '
    ;                  echo '  <td width="40%"><a href="' $result["link_to_tut"] . '">Name of tutorial</a> - Description etc....'

        
    //Dont edit beyond here 

                    
    }
                    else
                    {
                        echo 
    ' width="10%">Thumb Here</td>  
      <td width="40%">No Content'
    ;
                    } 
                    echo 
    '</td> 
    '

                    if(
    $rowNum != && $rowNum $columns == 0
                    { 
                        echo 
    ' </tr> 
     <tr> 
    '

                    } 
                } 
    //} 
    echo ' </tr> 
    </table>'


    ?>
    dumpfi
    Last edited by dumpfi; 12-27-2006 at 12:01 AM.
    "Failure is not an option. It comes bundled with the software."
    ....../)/)..(\__/).(\(\................../)_/)......
    .....(-.-).(='.'=).(-.-)................(o.O)...../<)
    ....(.).(.)("}_("}(.)(.)...............(.)_(.))Ż/.
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

  • #10
    New Coder
    Join Date
    Oct 2006
    Location
    north poll
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    dumpfi your code does exactly what danielwarners does with anarchy3200 modification. And anarchy3200 did you mean the code you posted as an addon to daniels or as a solution to my second problem?

    thanks all

  • #11
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    With my modification the script does display the remaining table rows as you wanted. However, I've edited it to remove some superfluous </td> tags.

    dumpfi
    "Failure is not an option. It comes bundled with the software."
    ....../)/)..(\__/).(\(\................../)_/)......
    .....(-.-).(='.'=).(-.-)................(o.O)...../<)
    ....(.).(.)("}_("}(.)(.)...............(.)_(.))Ż/.
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

  • #12
    Regular Coder
    Join Date
    Oct 2005
    Location
    Surrey, England
    Posts
    286
    Thanks
    2
    Thanked 2 Times in 2 Posts
    PHP Code:
    <?php

    // ...

    echo '<table border="0" cellpadding="0" cellspacing="0" width="100%">
     <tr>'
    ;

        
    $columns 2;
        
    $resultSet mysql_query('SELECT * FROM `table` ORDER BY `highscore` DESC LIMIT 0,10');
        
    $rowNum mysql_num_rows($resultSet);

        if(
    $rowNum $columns != 0)
        {
            
    $rowNum += $columns $rowNum $columns;
        } 
    $maxResults 10;
        while(
    $maxResults-- > 0)
            {
                    if(
    $result mysql_fetch_assoc($resultSet))
                    {

      
    //Active Tutorial
      
    echo '
      <td width="10%">Thumb for tut w/ highest score here</td>
      <td width="40%"><a href="....">Name of tutorial</a> - Description etc....</td>'
    ;

            } else {

      
    //Blank Results
      
    echo '
      <td width="10%">No Highscore</td>
      <td width="40%">No Highscore</td>'
    ;

            }
                    if(
    $maxResults != && $maxResults $columns == 0)
                    {
     echo 
    '
     </tr>
     <tr>'
    ;
                    }
        }

     echo 
    '
     </tr>
    </table>'
    ;

    ?>
    ...Havn't tested it though
    Daniel Warner
    - - - - - - - - - -
    GuitarMart.co.uk - Free Online Classified Advertisement for Guitarists in the United Kingdom. Free Ads with a Free Photo.

  • #13
    New Coder
    Join Date
    Oct 2006
    Location
    north poll
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    perfect thats exactly what i was looking for. and their were no errors with it either


  •  

    Posting Permissions

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