Announcement

Collapse
No announcement yet.

Custom database query

Collapse
X
Collapse
First Prev Next Last
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Custom database query

    I have created a query that retrieves 5 groups under the caegories ID 6649950,6649951,6649952,6649953

    Right now, i have managed to display 5 groups from those categories only, and echo their permalink and title.

    But now i need to sort the query to make it display 5 groups under those specific categories, and order them by the number of discussions.

    Please let me know what i should add in the $sql
    Here is my current query:

    PHP Code:
    $link mysqli_connect("localhost""xxxx""xxxx""xxxxx");

    // Check connection
    if($link === false){
    die(
    "ERROR: Could not connect. " mysqli_connect_error());
    }

    $sql "SELECT n.*,nn.urlident purl FROM `node` n LEFT JOIN `node` nn ON (nn.nodeid = n.parentid) WHERE n.parentid IN (6649950,6649951,6649952,6649953) LIMIT 5";
    if(
    $result mysqli_query($link$sql)){
    if(
    mysqli_num_rows($result) > 0){

    while(
    $row mysqli_fetch_array($result)){
    echo 
    "<a href=WWW.SITE-URL.COM/social-groups/".$row['purl']."/" $row["urlident"]. "' class='result_link'>";
    echo 
    $row['title'];
    echo 
    "</a>";
    }
    // Free result set
    mysqli_free_result($result);
    } else{
    echo 
    "No records matching your query were found.";
    }
    } else{
    echo 
    "ERROR: Could not able to execute $sql. " mysqli_error($link);
    }

    mysqli_close($link); 
    Last edited by glennrocksvb; 02-13-2018, 07:31 AM. Reason: Removed sensitive db info

    #2
    Depends on what you want to order by. threads or posts:

    posts:

    HTML Code:
    SELECT n.*,nn.urlident purl FROM `node` n LEFT JOIN `node` nn ON (nn.nodeid = n.parentid) WHERE n.parentid IN (6649950,6649951,6649952,6649953) ORDER BY nn.textcount desc LIMIT 5
    threads
    HTML Code:
    SELECT n.*,nn.urlident purl FROM `node` n LEFT JOIN `node` nn ON (nn.nodeid = n.parentid) WHERE n.parentid IN (6649950,6649951,6649952,6649953) ORDER BY nn.totalcount desc LIMIT 5
    Did not try but this should work.

    BTW: You should use nn.urlident as purl
    My forum closed !

    Comment


      #3
      Thank you verry much delicjous . I did not saw that column in the database. I applied your code, and it works flawless

      Comment

      Users Viewing This Page

      Collapse

      There is 1 user viewing this forum topic.

      • Guest Guest

      Latest Posts

      Collapse

      Working...
      X
      Searching...Please wait.
      An unexpected error was returned: 'Your submission could not be processed because you have logged in since the previous page was loaded.

      Please push the back button and reload the previous window.'
      An unexpected error was returned: 'Your submission could not be processed because the token has expired.

      Please push the back button and reload the previous window.'
      An internal error has occurred and the module cannot be displayed.
      There are no results that meet this criteria.
      Search Result for "|||"