doforumda Posted April 25, 2010 Share Posted April 25, 2010 hi i am trying to post hidden type data. the problem is when i press click link then it should display that postid for which user clicks click link. but it only displays the first post's postid here is my code <?php $connect = mysql_connect("localhost","user","pass"); $db = mysql_select_db("db"); $get_data = mysql_query("SELECT * FROM posts"); while($row = mysql_fetch_assoc($get_data)) { $postid = $row['postid']; $post = $row['post']; ?> <div> <?php echo $postid."<br>".$post; ?> <input type="hidden" name="click" id="click" value="<?php echo $postid ?>" /> <a class="click_here" href="#">Click</a> </div> <?php } ?> <script type="text/javascript" src="lib/jquery-1.4.min(Production).js"></script> <script> $(document).ready(function() { $('.click_here').click(function() { var clickval = $('#click').val(); alert(clickval); }); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/199669-need-help-in-posting-hidden-type-data/ Share on other sites More sharing options...
themistral Posted April 25, 2010 Share Posted April 25, 2010 You need to use a form with a submit button instead of an <a href> link. Quote Link to comment https://forums.phpfreaks.com/topic/199669-need-help-in-posting-hidden-type-data/#findComment-1047948 Share on other sites More sharing options...
doforumda Posted April 25, 2010 Author Share Posted April 25, 2010 yes i know it works that way but i need it this way. how can i do this way Quote Link to comment https://forums.phpfreaks.com/topic/199669-need-help-in-posting-hidden-type-data/#findComment-1047951 Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2010 Share Posted April 25, 2010 You can't. You'll have to set the value in a session var. $_SESSION['postid'] = $postid Quote Link to comment https://forums.phpfreaks.com/topic/199669-need-help-in-posting-hidden-type-data/#findComment-1047954 Share on other sites More sharing options...
doforumda Posted April 25, 2010 Author Share Posted April 25, 2010 is there any other way to do this, without using form and session var? Quote Link to comment https://forums.phpfreaks.com/topic/199669-need-help-in-posting-hidden-type-data/#findComment-1047958 Share on other sites More sharing options...
doforumda Posted April 25, 2010 Author Share Posted April 25, 2010 the purpose of doing this is, i ll have reply link instead of click here and when user clicks on reply then a hidden textarea will appear only below that particular post for which user clicks reply thats why i am trying to do this Quote Link to comment https://forums.phpfreaks.com/topic/199669-need-help-in-posting-hidden-type-data/#findComment-1047960 Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2010 Share Posted April 25, 2010 You can append the variable to the URL string, www.site.com/page.php?postid=$postid and use $_GET['postid'] to retrieve it. Nothing else immediately comes to mind . . . Quote Link to comment https://forums.phpfreaks.com/topic/199669-need-help-in-posting-hidden-type-data/#findComment-1047962 Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2010 Share Posted April 25, 2010 So the page doesn't reload when the link is clicked, it's handled by JQuery, correct? If that's the case, there should be a way to do this without needing to pass the value at all (I'd imagine). My javascript skills end at 'alert' though, so I'll not be able to help with that part of it. Quote Link to comment https://forums.phpfreaks.com/topic/199669-need-help-in-posting-hidden-type-data/#findComment-1047966 Share on other sites More sharing options...
doforumda Posted April 25, 2010 Author Share Posted April 25, 2010 yes it correct it is handled by jquery Quote Link to comment https://forums.phpfreaks.com/topic/199669-need-help-in-posting-hidden-type-data/#findComment-1047968 Share on other sites More sharing options...
doforumda Posted April 25, 2010 Author Share Posted April 25, 2010 i want to do something like this <?php $connect = mysql_connect("localhost","user","pass"); $db = mysql_select_db("db"); $get_data = mysql_query("SELECT * FROM posts"); while($row = mysql_fetch_assoc($get_data)) { $postid = $row['postid']; $post = $row['post']; ?> <div> <?php echo $postid."<br>".$post; ?> <style> .reply_container<?php echo $postid; ?> { display: none; } </style> <input type="hidden" name="click" id="click" value="<?php echo $_SESSION['postid']; ?>" /> <a class="click_here" href="#">Click</a> </div> <div class="reply_container<?php echo $postid; ?>"> <form action="" method="post"> <textarea name="reply" id="reply" rows="3" cols="40"></textarea> <input type="button" name="replybtn" id="replybtn" value="reply" /> </form> </div> <?php } ?> <div class="display"></div> <script type="text/javascript" src="lib/jquery-1.4.min(Production).js"></script> <script> $(document).ready(function() { $('.click_here').click(function() { var clickval = $('#click').val(); alert(clickval); $('.reply_container' + clickval).css('display','block'); }); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/199669-need-help-in-posting-hidden-type-data/#findComment-1047971 Share on other sites More sharing options...
doforumda Posted April 26, 2010 Author Share Posted April 26, 2010 I am still waiting for help Quote Link to comment https://forums.phpfreaks.com/topic/199669-need-help-in-posting-hidden-type-data/#findComment-1048616 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.