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 7958669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:27:28+00:00 2026-06-04T04:27:28+00:00

Hi i am a beginner i am working on software site. i have built

  • 0

Hi i am a beginner i am working on software site. i have built all the pages and layout for the site that was the easy part done using HTML CSS AND JAVASCRIPT alone, only thing left is to make main categories pages for different software which is tough for me.

i want to to add sorting option on category pages like this (See Here)
where user shall be able to sort software according to date, name, date added etc. and also be able to control max number of software to display like 20, 30, 100 etc.

On my HTML Page i have these div’s in which i want to display data (different softwares)
from MySQL database “security_software” (it is a testing database) from table “internet_security” (it is a testing table)

HTML Div’s

  <div class="category-container">
    <div class="category-image"></div>
    <div class="category-desc"><a href="#">#</a><p>text</p></div>
    <div class="rating5" >Editors' rating: </div>
    <div class="category-download-btn"><a href="#">Download</a></div>
    <div class="category-buy-btn"><a href="#">Buy</a></div>
  </div>

After Some research i have got a solution to use JSON AJAX PHP &MySQL

JAVASCRIPT Code i have

<head>    
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$.ajax({
    url: 'ajax.php',
    dataType: 'json',
    success: function(response){
        data = '';
        $.each(response,function(i,val){
          data = '<div class="category-image">'+val.image+'</div>'+
        '<div class="category-link"><a href="#">'+val.id+'</a></div>'+
        '<div class="category-desc"><p>'+val.description+'</p> </div>'+
        '<div class="rating5" >'+val.rating+'</div>'+ 
        '<div class="category-download-btn"><a href="'+val.download+'">Download</a></div>'+ 
        '<div class="category-buy-btn"><a href="'+val.buy+'">Buy</a></div>';
        $('<div>').attr('id',i).html(data).appendTo('#response');
    });

    }
 });
</script>
</head>
 <body>
<div id='response'></div>   
 </body>

PHP Code i have

<?php
$q=$_GET["q"]; 

$con = mysql_connect('localhost', 'root', '');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("security_software", $con);

$sql="SELECT * FROM internet_security ORDER by `".$q."` DESC" ;


$result = mysql_query($sql);
$response = array();
$i=0;
while($row = mysql_fetch_array($result))
  {
  $response[$i]['id']           =$row['id'];
  $response[$i]['title']        = $row['title'];
  $response[$i]['image']        = $row['image'];
  $response[$i]['description']  = $row['description'];
  $response[$i]['rating']       = $row['rating'];
  $response[$i]['download']     = $row['download'];  
  $response[$i]['buy']          = $row['buy'];
  $i++;
  }
mysql_close($con); 

echo json_encode($response);
?>

Now it is not working at all as i dont have any place to attach these codes for (categories drop down) in javascript i have.

<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="id">id</option>
<option value="title">title</option>
<option value="image">image</option>
<option value="description">description</option>
<option value="description">rating</option>
<option value="download">download</option>
<option value="buy">buy</option>
</select>
</form>

Please help me guys where can i attach these code and how to get it working, i am totally confused.

  • 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-04T04:27:28+00:00Added an answer on June 4, 2026 at 4:27 am

    First thing worth noting is, if you are going to display tabular data… Use a table! It will make things a lot easier for you.

    Secondly. Build your code and table as if Ajax did not exist. Initially populate the data using PHP on the page your displaying the data. Then, hook up the column header’s so they link to your page, but passing which column you want to sort by and also which direction.

    i.e.

    <?
        $column = (isset($_GET["column"]) ? $_GET["column"] : 'id'); 
        $direction = (isset($_GET['direction']) ? $_GET['direction'] : 'asc');
        $con = mysql_connect('localhost', 'root', '');
        if (!$con)
        {
            die('Could not connect: ' . mysql_error());
        }
    
        mysql_select_db("security_software", $con);
        $sql="SELECT * FROM internet_security ORDER by '".$column."' " . $direction;
    
    
        $result = mysql_query($sql);
        $response = array();
        $i=0;
        while($row = mysql_fetch_array($result))
        {
            $response[$i]['id']           =$row['id'];
            $response[$i]['title']        = $row['title'];
            $response[$i]['image']        = $row['image'];
            $response[$i]['description']  = $row['description'];
            $response[$i]['rating']       = $row['rating'];
            $response[$i]['download']     = $row['download'];  
            $response[$i]['buy']          = $row['buy'];
            $i++;
        }
        mysql_close($con); 
    ?>
    
    <div id="content">
        <table>
            <thead>
                <tr>
                    <td><a href="table.php?column=id<?= (isset($_GET['column']) && $_GET['column'] == 'id' && !isset($_GET['direction']) ? '&direction=desc' : ''); ?>">ID</a></td>
                    <td><a href="table.php?column=title<?= (isset($_GET['column']) && $_GET['column'] == 'title' && !isset($_GET['direction']) ? '&direction=desc' : ''); ?>">Title</a></td>
                    <td><a href="table.php?column=rating<?= (isset($_GET['column']) && $_GET['column'] == 'rating' && !isset($_GET['direction']) ? '&direction=desc' : ''); ?>">Rating</a></td>
                    <td><a href="table.php?column=download<?= (isset($_GET['column']) && $_GET['column'] == 'download' && !isset($_GET['direction']) ? '&direction=desc' : ''); ?>">Download</a></td>
                </tr>
            </thead>
            <tbody>
                <? foreach($response as $i => $row) : ?>
                <tr>
                    <td><?= $row['id']; ?></td>
                    <td><?= $row['title']; ?></td>
                    <td><?= $row['rating']; ?></td>
                    <td><?= $row['download']; ?></td>
                </tr>
                <? endforeach; ?>
            </tbody>
        </table>
    </div>
    

    The above code would go inside a single PHP file, without any other HTML etc. Then, on the page you want to display this table, you simply <? include('path-to-file.php'); ?> include it.

    Finally… At the top of the page you are displaying the table on, you would put:

    <?
        if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
        {
            include('path-to-file.php');
            die();
        }
    ?>
    

    The above code would then detect an Ajax request and serve only the table with the data in the new order.

    You would then need to use Javascript to replace the table with the new HTML via

    $('#content table thead a').live('click', function(e)
    {
        e.preventDefault();
        $.ajax(
        {
            url : $(this).attr('href'),
            success : function(resp)
            {
                $('#content').html($(resp).html());
            },
            error : function()
            {
                alert('There was a problem sorting your table...');
            }
        });
    });
    

    where resp is the variable that contains your Ajax response.

    Note: This is just a very simple and crude (oh, and untested) way to handle the situation. You would need to improve it your self to prevent any security related issues such as SQL Injection.

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

Sidebar

Related Questions

I have my beginner Ruby application working perfectly on my local server using Rack
I am using NHibernate for my project. i am quite a beginner at working
I am a beginner-verging-on-intermediate rails developer that is working hard to improve my skills.
As a beginner in Ocaml, I have this current working code: ... let ch_in
I've got all the tutorials up to beginner #5 translated and working, but I
I am a beginner to iOS development and have just started working with the
jQuery beginner here. Here is what I'm working on. I have an area map
I am a beginner and working on joomla 1.5. I have two question :
I am a beginner in PHP and am working on a script that can
First of all, I'm beginner. I've start working only a month ago. I'm currenlty

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.