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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:02:06+00:00 2026-05-24T02:02:06+00:00

I seem to be stuck on a concept in database query and website development.

  • 0

I seem to be stuck on a concept in database query and website development.

I have a website that will reflect what data is stored in a database and the website needs to change depending on that data: therefore, my menu system will not be hardcoded in. It builds my menu system based off a query of all the models in my database. The action of clicking on the menu will show tables without changing the page (a simple javascript “showtables” function). like so:

        function showTables(TABLE_NAME)
{
    if(TABLE_NAME != "PRINTER_TABLE")
    {
        document.getElementById("PRINTER_TABLE").style.display ="none";

    }
    if(TABLE_NAME != "show_ALL_PRINTERS")
    {
        document.getElementById("show_ALL_PRINTERS").style.display ="none";
    }
    document.getElementById(TABLE_NAME).style.display ="block";
}

I did not include all of my other if statements because there are about 15 of them. These statements will hide everything and the only show the formatted table of “TABLE_NAME” at the end of that script.

My problem is that, if all of the data will not be hardcoded in either HTML or PHP, I need to pass into my function “showTables” a model type or ID that will come from my query.

My Menu system code snipet:

     <li class="hasmore"><a href="#" onClick="showTables('show_ALL_PRINTERS')"><span>Printer Parts</span></a>
      <ul class="dropdown">
      <?php
        include 'connection.php';

        $query = "SELECT * FROM all_printers";
        $result = mysql_query($query);
        while($row = mysql_fetch_array($result))
        {
            #echo "<h3>" . $row['printer_model'] . "</h3>";
            echo "<li><a href=\"#\" onclick=\"showTables('PRINTER_TABLE'")\">" .$row['printer_model']."</a></li>\n";
        }
    ?>

This puts the model into the menu system and the “PRINTER_TABLE” will access my showTables function, which then will show that table. But there are many different printer models and I need to tell my table query what specific model to get info on.

I hope this makes sense as there is a lot of logic behind it. Maybe there is an easier way..?

In my tables I have:

    <table id="table">
    <thead>
          <tr>
              <th scope="col" id="table">Type</th>
              <th scope="col" id="table">Size</th>
              <th scope="col" id="table">S/N</th>
              <th scope="col" id="table">Model</th>
              <th scope="col" id="table">Connection Type</th>
              <th scope="col" id="table">Surplus</th>
              <th scope="col" id="table">Amount</th>
          </tr>
     </thead>
     <tbody>     
            <?php
            include 'connection.php';
            $query_misc = "SELECT * FROM all_parts WHERE part_type='MISC'";
            $result_misc = mysql_query($query_misc);
            while($row = mysql_fetch_array($result_misc))
            {
                echo "<tr>";
                echo "<td><div align=\"center\">".$row['part_type']."</div></td>";
                echo "<td><div align=\"center\">".$row['part_size']."</div></td>";
                echo "<td><div align=\"center\">".$row['part_sn']."</div></td>";
                echo "<td><div align=\"center\">".$row['part_model']."</div></td>";
                echo "<td><div align=\"center\">".$row['part_connection']."</div></td>";
                echo "<td><div align=\"center\">".$row['part_surplus']."</div></td>";
                echo "<td><div align=\"center\">".$row['part_temp_amount']."/".$row['part_amount']."</div></td>";
                echo "</tr>";
            }

….. etc

Any ideas?

EDIT:

I do now know how to put what I click on, into the url properly..

    <?
        $query = 'SELECT printer_id, printer_model FROM printer_table WHERE 1 ORDER BY name';
        $products = mysql_query($query);
        while ($product = mysql_fetch_assoc($products)) :
    {
        echo "<li><a href=\"inventory_admin.php?product_id='".$product['printer_id']."'\" onclick=\"toggleVisibility('".$product['printer_model']."')\">" .$product['printer_model']."</a></li>\n";
    }

     ?>

or

    <li><a href="inventory_admin.php?product_id=<?=$product['printer_id']?>" onclick="toggleVisibility('<?=$product['printer_model']?>')"><?=$product['printer_model']?></a></li>

doesnt work properly, because i need to call the suggested part list php part, but do not know where to do so..

EDIT:

I placed that php within a div and the echos will fill out my table, but how am I suppose to call that div to only run when that onclick action? I know that is not how divs work, It would seem I would need a JS function but I know you cannot do php within JS. AJAX perhaps?

EDIT—————————————————-

The call here to the DB is correct, tested it manually without any errors, but I am still receiving a syntax error upon loading my home page. Here is my call to the DB via PHP…

    <?
    if (!isset($_GET['action']))
    {
        //If not isset -> set with dumy value
        $_GET['action'] = "undefine";
    } 
    include 'connection.php';
    $query = 'SELECT ppart_table.* FROM ppart_table LEFT JOIN printer_part_relation ON ppart_table.part_id = printer_part_relation.part_id WHERE printer_part_relation.printer_id ='.mysql_real_escape_string($_GET['printer_id']);

    $parts = mysql_query($query) or die("Query failed with error: ".mysql_error());
    while ($row = mysql_fetch_assoc($parts)) 
    {
        echo table blah blah    
    }       
?>

I have tried supressing all errors via this:

    <?php error_reporting (E_ALL ^ E_NOTICE); ?>

And the syntax error at page load still exist.

My home page of this site does NOT have the “product_id=” after mysite.php

  • 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-24T02:02:06+00:00Added an answer on May 24, 2026 at 2:02 am

    I would recommend using PHP’s PDO class for database access. I would also recommend using JQuery for all of you javascripting. It makes things VERY simple. It would also be advantagious to keep your display code away from your business logic (two languages should for the most part not be in the same source file ie: HTML/PHP/Javascript). I will stick with what is familiar for now however. perhaps something like this?

    menu

    <ul>
    
       <?
          $query = 'SELECT id, name FROM product_category_table WHERE 1 ORDER BY name';
          $product_categories = mysql_query($query);
          while ($product_category = mysql_fetch_assoc($product_categories)) :
       ?>
    
       <li>
          <a href="#" onclick="toggleVisibility('<?= $product_category['id'] ?>')">$product_category['name']</a>
          <ul id="<?= $product_category['id'] ?>" style="display: none;">
    
             <?
                $query = 'SELECT id, name FROM product_table WHERE category_id = ' . $product_category['id'] . ' ORDER BY name';
                $products = mysql_query($query);
                while ($product = mysql_fetch_assoc($products)) :
             ?>
    
             <li><a href="thispage.php?product_id=<?= $product['id'] ?>"><?= $product['name'] ?></a></li>
    
             <?
                endwhile;
             ?>
    
          </ul>
       </li>
    
       <?
          endwhile;
       ?>
    
    </ul>
    

    javascript

    function toggleVisibility(category) {
       var element = document.getElementById(category);
       if (element.style.display == 'none') {
          element.style.display = 'block';
       } else {
          element.style.display = 'none';
       }
    }
    

    part list

    <?
    $query = 'SELECT part_table.* FROM part_table LEFT JOIN product_to_part_associations_table ON parts_table.id = product_to_part_associations_table.part_id WHERE product_to_part_associations_table.product_id = ' . mysql_real_escape_string($_GET['product_id']);
    $parts = mysql_query($query);
    while ($part = mysql_fetch_assoc($parts)) {
       echo part table blah blah
    }
    ?>
    

    db tables

    product_category_table
    id, name, etc
    
    product_table
    id, category_id, name, etc
    
    part_table
    id, name, etc
    
    part_to_product_association_table
    id, product_id, part_id
    

    set the proper indexes on your table columns for speed. the part_to_product_association table allows for a many to many relationship between records in the product table and records in the parts table (needed in the case one part could be used in multiple products, and one product can use multiple parts).

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

Sidebar

Related Questions

Do stack-based languages have a concept of scope? It would seem to me that
I seem to be stuck in Kafka-land, with a java.lang.String that I can't seem
I'm working on learning Objective-C/Coaoa, but I've seem to have gotten a bit stuck
I'm working on a sheet that accesses a legacy data source via MS Query.
This is a followup to this question . I seem to be stuck on
I seem to be mentally stuck in a Flyweight pattern dilemma. First, let's say
Seem to be having an issue with std::auto_ptr and assignment, such that the object
I seem to make this mistake every time I set up a new development
I have an existing application that controls a machine and want to add a
Seem to be stuck trying to only update images in a selected div, when

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.