The problem is this: There are 2 buttons on one page, when you click on each of their buttons, there is an ajax request and output, let's say it looks like this now
$(".btn1").click(function() { $.ajax({ type: "POST", data: "categ=" + categ, url: "serverscript/page1.php", success: function(data) { $(".block1").html(data); } }); page1.php
include './config.php'; $categ=$_REQUEST['categ']; $STH = $DBH->query('SELECT * from table1 where categ= "' . $categ. '" '); $STH->setFetchMode(PDO::FETCH_ASSOC); while($row = $STH->fetch()) { echo $row{'name'} } And about the same at 2 buttons
$(".btn2").click(function() { $.ajax({ type: "POST", data: "categ2=" + categ, url: "serverscript/page1.php", success: function(data) { $(".block2").html(data); } }); page2.php
include './config.php'; $categ2=$_REQUEST['categ2']; $STH = $DBH->query('SELECT * from table1 where categ2= "' . $categ2. '" '); $STH->setFetchMode(PDO::FETCH_ASSOC); while($row = $STH->fetch()) { echo $row{'name'} } Something like this, the question is how can I create 1 php file and do an ajax request for a specific piece of code, like wrapping something in a function. In order not to do 2 files page1 and page2, but to stir up 1 where these two pieces are. I hope you understand me
categorytable with categories in the database, and thecategory_idcolumn in the table pointing to the table with categories .... and then the query is reduced to the querySELECT * from table1 where category_id = $id;.... and if the categories are added, it is not necessary to writecaeg2,categ4and other nonsense ..... but also interestingly - what is the point of using PDO without prepared variables? - Alexey Shimansky