I have two tables , Post and Category .
Post
pid title result content cid
1 Option1 Opt content1 2
2 Option2 Opt content2 2
3 Option3 Opt content3 3
Category
cid cname
1 Cat 1
2 Cat 2
3 Cat 3
This is my insert.php
This is my cat.php which displays posts of particular category.
This is my category menu list on home page .
This is javascript.
Everything is getting inserted to database correctly . But im not able to display the posts of specific category onclick .
I have given the complete code . What i want is , when i click on Cat 1 or Cat 2 or Cat 3 on home page , i need to display all data from post table of the selected category in #display div .
I am getting an error saying , cid is undefined variable .
Do tell me anything else to be added or it would be better if you write the required code for me .
Thank you.
Post
pid title result content cid
1 Option1 Opt content1 2
2 Option2 Opt content2 2
3 Option3 Opt content3 3
Category
cid cname
1 Cat 1
2 Cat 2
3 Cat 3
This is my insert.php
Code:
mysql_connect('localhost','root','');
mysql_select_db("database") or die("Unable to select database");
$title=$_POST['post_title'];
$result=$_POST['post_result'];
$content=$_POST['post_content'];
$sid=$_POST['cid'];
$date=$_POST['date'];
$insertquery="INSERT INTO review (post_title,post_result,post_content,cid,date)
VALUES('$title','$result','$content',$sid,NOW())";
$result=mysql_query($insertquery);
if(! $result )
{
die('Could not enter data: ' . mysql_error());
}
else {
echo "Entered data successfully\n";
header('Location:home.php');
}
Code:
$link = mysql_connect("localhost","root","");
mysql_select_db("database");
$query="SELECT * FROM category WHERE cid='$cid'";
$result = mysql_query($query) or die("Query to get data failed with error: ".mysql_error());
while($row = mysql_num_rows($result)) {
echo //details goes here
}
Code:
<ul> <li><a class="my-button" href="#">Cat 1</a></li> <li><a class="my-button" href="#">Cat 2</a></li> <li><a class="my-button" href="#">Cat 3</a></li> </ul>
Code:
<script>
$(document).ready(function() {
$('body').on('click', '.my-button', function() {
$("#display").load("cat.php");
});
});
</script>
I have given the complete code . What i want is , when i click on Cat 1 or Cat 2 or Cat 3 on home page , i need to display all data from post table of the selected category in #display div .
I am getting an error saying , cid is undefined variable .
Do tell me anything else to be added or it would be better if you write the required code for me .
Thank you.
Comment