Jump to content

Recommended Posts

Hey all so Im trying to put data through an AJAX call into this div

 

		 <div class="scroll-pane2 blue small" style="">
		 <p id="bulletinBodyArea" style="margin-right:20px;"></p>
	 </div>

 

The AJAX is being triggered when one clicks on one of the links being fed from the database

 

		 <div class="bulletinSectionAccordion rounded">
		 <p class="blue" style="font-size:19px;margin-left:23px;margin-top:15px;margin-bottom:10px;">Archives</p>
	 <?php


		 $query = "SELECT * FROM `bulletin` LEFT JOIN `bulletininschool` ON `bulletin`.`id`=`bulletininschool`.`bulletin` WHERE `school` = 2 ";
		 $result=$connection->query($query);

		 while($row = $result->fetch_array()) {
		 echo '<p class="medium titi" style="margin-left:23px;">'.$row['title'].'</p>';
		 }
	 ?>
	 </div>

 

It gets called and then passes the data

 

	 $(".titi").click(
	 getBody
 );

 function getBody(){
	 $("#bulletinBodyArea").load('update/getBody.php');
 };

 

And this is the AJAX function

 

 <?php
$section='bulletin';
$table="bulletin";
$schoolSelectorTable="bulletininschool";
$schoolSelector="bulletin";

$db_host = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "isl";


mysql_connect($db_host, $db_user, $db_pass, $db_name);
mysql_select_db("isl") or die(mysql_error());


$states = mysql_query("SELECT * FROM `bulletin` LEFT JOIN `bulletininschool` ON `bulletin`.`id`=`bulletininschool`.`bulletin` WHERE `school` = 2" );


while($state = mysql_fetch_array($states)){
echo "<p>".$state['body']."</p>";
}
?>

 

Now the links that one clicks that are fed from the database are actually article titles, and when one clicks on a specific title the AJAX call should go and fetch the body text associated with that article. But I'm having trouble understanding how I should go through that. I'm doing the correct queries and getting the titles and the bodies but I just cant figure out how to associate them. Do I pass a variable to the AJAX call?

 

Thank you

Edited by Frisbetarian
Link to comment
https://forums.phpfreaks.com/topic/272406-passing-php-data-through-an-ajax-call/
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.