dkar Posted September 23, 2012 Share Posted September 23, 2012 Hi, I am new in php and trying to build a database driven web site. In every step I deal with a new problem . In the image I attached I have a diagram of how the website looks. As you can see I have a side bar with two dropdown menus and on the right is the main content of the page. The procedure goes like this: When I select a value from the drop down menu and click the button, a request is sent through Ajax to the database (I use the $.ajax function). All the php code is written in a different file which I define in the url of ajax method. That way my page is not refreshed every time that I click the button. But the problem is that the results are not appearing where I want. As you can see in the diagram(attached) I want them to be in the main content of the page (1) but they appear on the sidebar (2). This must be really easy question but as I said I started learning only some time ago. Any suggestions? Thanks Dimitris Quote Link to comment https://forums.phpfreaks.com/topic/268697-how-to-adjust-the-position-of-the-results-echoed-by-php-on-my-site/ Share on other sites More sharing options...
smoseley Posted September 23, 2012 Share Posted September 23, 2012 There's no attachment. You really should post your code, too, to get help. The question as it stands is so abstract, the only help I could give you would be "Move the echo to the correct place in the HTML." Quote Link to comment https://forums.phpfreaks.com/topic/268697-how-to-adjust-the-position-of-the-results-echoed-by-php-on-my-site/#findComment-1380287 Share on other sites More sharing options...
codefossa Posted September 23, 2012 Share Posted September 23, 2012 (edited) First off, this is a Javascript / Ajax question, but anyways ... // Uses ID "mybutton" for the button, and "mydiv" for the div. var btn = $("#mybutton"), div = $("#mydiv"); // URL loaded into the div. var url = 'mypage.php'; btn.click(function() { div.load(url); }); Edited September 23, 2012 by Kira Quote Link to comment https://forums.phpfreaks.com/topic/268697-how-to-adjust-the-position-of-the-results-echoed-by-php-on-my-site/#findComment-1380299 Share on other sites More sharing options...
dkar Posted September 23, 2012 Author Share Posted September 23, 2012 (edited) "Move the echo to the correct place in the HTML." But what will I echo? The php code is this: <?php include('connect.php'); $category = $_POST['datastr']; $query = "SELECT Information from activities where Activities='$category'"; $result = mysqli_query($dbcon, $query) or die('no available data'); echo "<table>"; //echo "<tr> <th>Results</th></tr>"; $num_results = 0; while ($row=mysqli_fetch_array($result, MYSQLI_ASSOC)) { echo "<tr><td>"; echo $row['Information']; echo "</td></tr>"; $num_results=$num_results+1; } // Here I print the number of the results of each search if ($num_results==1 && $category!="Click to select"){ echo "<div align=\"center\" id=\"result\">$num_results result for $category was found!</div>" ; } else if($category!="Click to select") { echo "<div id=\"r2\" align=\"center\" id=\"result_2\">$num_results results for $category were found!</div>" ; } // End of if echo "</table>"; // End of printed table ?> This code runs when I choose some value from the dropdown menu of my html code. The html code is divided in two div tags. The first one is the sidebar and the other one is the main content. I want to echo the results in the main content div. But I don't know how. <div id="content"> echo ???? </div> Now everything they appear under the dropdown menus in the sidebar.. Thanks D. Edited September 23, 2012 by dkar Quote Link to comment https://forums.phpfreaks.com/topic/268697-how-to-adjust-the-position-of-the-results-echoed-by-php-on-my-site/#findComment-1380334 Share on other sites More sharing options...
codefossa Posted September 23, 2012 Share Posted September 23, 2012 If you're not loading it with the page, you don't add the PHP there. The PHP page should only print out what you want from it (not a whole HTML page), or if you are taking part of another page, load it into a variable div and sort through what you need. To just load the contents of that page, you would $("#content").load('page.php'); You can do this when they click whatever by using $("#btn").click(function() { $("#content").load('page.php') }); Quote Link to comment https://forums.phpfreaks.com/topic/268697-how-to-adjust-the-position-of-the-results-echoed-by-php-on-my-site/#findComment-1380340 Share on other sites More sharing options...
smoseley Posted September 23, 2012 Share Posted September 23, 2012 +1 to Kira's solution. Missed the part that it was an AJAX load. Quote Link to comment https://forums.phpfreaks.com/topic/268697-how-to-adjust-the-position-of-the-results-echoed-by-php-on-my-site/#findComment-1380348 Share on other sites More sharing options...
dkar Posted September 24, 2012 Author Share Posted September 24, 2012 The php code that I have it prints a table that has all the information that I want from the database. My problem is that I can not position this table where I want on my html site. My problem that the php code is echoed by default on the sidebar of my html site but I want to echo the results on the main content. I don't know if this is possible though.. Quote Link to comment https://forums.phpfreaks.com/topic/268697-how-to-adjust-the-position-of-the-results-echoed-by-php-on-my-site/#findComment-1380556 Share on other sites More sharing options...
Christian F. Posted September 24, 2012 Share Posted September 24, 2012 It is possible. After all, it's you who told it to print stuff in the first place. Quote Link to comment https://forums.phpfreaks.com/topic/268697-how-to-adjust-the-position-of-the-results-echoed-by-php-on-my-site/#findComment-1380567 Share on other sites More sharing options...
dkar Posted September 24, 2012 Author Share Posted September 24, 2012 Yup that's true But I don't know how to tell it to print the stuff where I want.. Quote Link to comment https://forums.phpfreaks.com/topic/268697-how-to-adjust-the-position-of-the-results-echoed-by-php-on-my-site/#findComment-1380584 Share on other sites More sharing options...
dkar Posted September 24, 2012 Author Share Posted September 24, 2012 Ok. Solved it. Thanx for the help! Dimitris Quote Link to comment https://forums.phpfreaks.com/topic/268697-how-to-adjust-the-position-of-the-results-echoed-by-php-on-my-site/#findComment-1380621 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.