Jump to content

How To Adjust The Position Of The Results Echoed By Php On My Site?


dkar

Recommended Posts

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

Link to comment
Share on other sites

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 by Kira
Link to comment
Share on other sites

"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 by dkar
Link to comment
Share on other sites

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') });

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.