SQL Database to php website with javascript

john_d

New Member
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:\[code\] 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";}\[/code\]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: \[code\] <li class="hasmore"><a href="http://stackoverflow.com/questions/6795186/#" 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=http://stackoverflow.com/questions/6795186//"#\" onclick=\"showTables('PRINTER_TABLE'")\">" .$row['printer_model']."</a></li>\n"; } ?>\[/code\]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:\[code\] <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>"; }\[/code\]..... etcAny ideas?EDIT:I do now know how to put what I click on, into the url properly..\[code\] <? $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=http://stackoverflow.com/questions/6795186//"inventory_admin.php?product_id='".$product['printer_id']."'\" onclick=\"toggleVisibility('".$product['printer_model']."')\">" .$product['printer_model']."</a></li>\n"; } ?>\[/code\]or\[code\] <li><a href="http://stackoverflow.com/questions/6795186/inventory_admin.php?product_id=<?=$product['printer_id']?>" onclick="toggleVisibility('<?=$product['printer_model']?>')"><?=$product['printer_model']?></a></li>\[/code\]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...\[code\] <? 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 } ?>\[/code\]I have tried supressing all errors via this:\[code\] <?php error_reporting (E_ALL ^ E_NOTICE); ?>\[/code\]And the syntax error at page load still exist. My home page of this site does NOT have the "product_id=" after mysite.php
 
Top