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

  • Home
  • SEARCH
  • 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 7662925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:55:33+00:00 2026-05-31T13:55:33+00:00

I really need help. My problem now is i want to display the books

  • 0

I really need help.

My problem now is i want to display the books details, which the data is from mysql.

I tell step-by-step.

  1. i have table books in mysql

  2. from the table, i called the title and price using php, which display like this :

Title : One
Price : 20$


Title : Two
Price : 35$


my php code is :

<?php

$db_host="localhost";
$db_username="root";
$db_pass="";
$db_name="";

@mysql_connect("$db_host","$db_username","$db_pass") or die("Could not connect to database.");

@mysql_select_db("$db_name") or die("No database");


$q=mysql_query("SELECT * FROM books ");

while($result = mysql_fetch_array( $q )) 
 {

 echo "<b>Title:</b> ".$result['title'] . " <br> ";
 echo "<b>Price:</b> RM".$result['price_myr'] ."<br>"; 
 echo "<br>";

 }

?>
  1. Here the problem start. I want to display the book details ( author, publisher, descrp, etc…) when user click on the list above ( step 2) . So can anyone give me the idea on how can i do that ? How to make the book list available for click and then it display the details.

example :

User click on listview ; Title:One ,
the details about the book popup or load.

I guess i need to use Ajax, but i dont know how.

Hope members here can help. Much thanks !

  • 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-05-31T13:55:34+00:00Added an answer on May 31, 2026 at 1:55 pm

    You should wrap each book in <div> tags, and create an onclick function for each one.

    Whether it has the information pre-loaded or fetches the information on-demand is up to you. If you have a ton of books listed on the page, pre-loading the information might cause performance issues, so it may be better to load the book information on-demand, via AJAX.

    Here is what your code might look like, using AJAX:

    // styling should be done in a CSS file, but for the simplicity of the example, including it inline
    echo "<div id=\"divBookInfo\" style=\"display:none; position:fixed; bottom:0; right:0;\">
        </div>\n";
    
    $q = mysql_query("SELECT title, price_myr FROM books");
    
    while ($result = mysql_fetch_array($q))
    {
        echo "<div onclick=\"showBookInfo({$result["bookID"]})\">
                <b>Title:</b> {$result["title"]} <br />
                <b>Price:</b> {$result["price_myr"]} <br />
            </div>\n";
    }
    

    And your JavaScript function:

    function showBookInfo(bookID)
    {
        var xmlhttp;
        if (window.XMLHttpRequest)
            xmlhttp = new XMLHttpRequest();
        else
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    
        xmlhttp.onreadystatechange = function()
        {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
            {
                document.getElementById("divBookInfo").innerHTML = xmlhttp.responseText;
                document.getElementById("divBookInfo").style.display = "block";
            }
        }
        xmlhttp.open("GET", "getBookInfo.php?bookID="+ bookID, true);
        xmlhttp.send();
    }
    

    getBookInfo.php:

    <?php
    
    $db_host="localhost";
    $db_username="root";
    $db_pass="";
    $db_name="";
    
    @mysql_connect($db_host, $db_username, $db_pass) or die("Could not connect to database.");
    
    @mysql_select_db($db_name) or die("No database");
    
    $q = mysql_query("SELECT author, publisher, description, ... FROM books WHERE bookID = '". mysql_real_escape_string($_GET["bookID"]) ."'");
    
    list($author, $publisher, $description, ...) = mysql_fetch_row($q);
    
    echo "<b>Author:</b> {$author} <br />
        <b>Publisher:</b> {$publisher} <br />
        <b>Description:</b> {$description} <br />";
    ?>
    

    ALSO

    One other side-note is that you should avoid the use of the or die() syntax in a PHP script that is generating your HTML. See this link for some reasons why.

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

Sidebar

Related Questions

I really need your help since I have a frustrating problem. I'm downloading data
I would really appreciate any help with the following problem: I need to be
I have run into this problem again and now really need to know how
I am stuck and need outside help from JSF experts with the following problem:
I really need your help. I'm working on this problem for weeks or months
I really need help with this last part of my program. I need to
I Really need help in this ... I'm building an application where I need
I really need help this time - Joomla 2.5 and latest K2. I'm using
I really need help on this one. I am having a simple login form
I really need help here. I'm desperate at this point. I have NSOperation that

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.