Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Apr 2011
    Posts
    92
    Thanks
    26
    Thanked 0 Times in 0 Posts

    getting a php variable from a hidden input value , to use in mysql query

    I created a modal window, and was able to send an ID value to a hidden input field that opens up in the modal window. I need to transfer the value of that ID so that I can use it in a mysql query, so I can grab more info from the database...

    So here is the modal window that pops up:

    Code:
    <div class="modal hide" id="myModal">
        <div class="modal-header">
        	<button type="button" class="close"data dismiss="modal">x</button>
        </div>
        <div class="modal-body">
        	<p>One fine body!</p>
        	<input type="hidden" name="d_id" value="123" id="d_id"/>
        </div>
        <div class="modal-footer">
        	<a href="#" class="btn btn-primary">Save changes</a>
        </div>
    </div>
    So I want to add this php to the code:

    PHP Code:
    $member_query mysql_query("SELECT name, job FROM members WHERE (member_id='$d_id')");
    while(
    $row mysql_fetch_array($member_query)){
        
    $member_name $row["name"];
        
    $member_job $row["job"];

    I was thinking to use some sort of javascript when the modal window loads like "onload getelementbyid"... so basically I need to somehow transfer the hidden input value (123), into a php variable $d_id. Is there an elegant way to do that?

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,227
    Thanks
    15
    Thanked 253 Times in 253 Posts
    Basically you're going to have to submit the data in a form, it will mean that a new page will be loaded, but you may need it to display the new data anyway. You may be able to send and receive the data by JSON or some other means, but how secure will that be vs post, and what liability would there be to reloading the page? Hardly any I should think, and the coding is very straightforward. Or maybe you could use the javascript .submit() function, but it will still reload the page.
    Last edited by DrDOS; 07-22-2012 at 10:24 PM.

  • Users who have thanked DrDOS for this post:

    Juniper747 (07-23-2012)

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,603
    Thanks
    80
    Thanked 4,500 Times in 4,464 Posts
    ??? Sounds to me more like a job for AJAX. Whether you would use JSON or not is up to you, though I would think if you are only going to send two values back to the HTML page (member_name and job, I am assuming?) I doubt you need JSON, at all.

    But it also seems to me that is the member_id is in a hidden field, why not just also put the member_name and job in hidden fields? That is, get *ALL* the information when you create the page, rather than going and getting some of it later via AJAX?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New Coder
    Join Date
    Apr 2011
    Posts
    92
    Thanks
    26
    Thanked 0 Times in 0 Posts
    But wouldn't that basically be an iframe? Can't I simply use the value that I already obtained from the hidden input and convert it to a php variable?

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,603
    Thanks
    80
    Thanked 4,500 Times in 4,464 Posts
    Quote Originally Posted by Juniper747 View Post
    But wouldn't that basically be an iframe? Can't I simply use the value that I already obtained from the hidden input and convert it to a php variable?
    My head hurts.

    You said this is a "modal dialog" and, by the HTML shown, I assume it is actually just a <div> that appears on top of the main page. Fine. Works for me.

    But now, apparently, you want to go get *NEW CONTENT* for the <div> (you *did* mention "geElementById", no?) from PHP.

    And I asked you: "WHY get NEW content from PHP? Why not simply PUT THE CONTENT THERE in the first place. *ALONG* with the d_id value???

    I *assume* that the main page here, including the HTML you showed us, is actually a PHP page. No? So why bother running off when the modal dialog pops up, getting stuff from PHP, when you could have used PHP to put it on the page in the first place????
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Juniper747 (07-23-2012)

  • #6
    New Coder
    Join Date
    Apr 2011
    Posts
    92
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Thanks for your replies... I was able to work it out.

    It was a bit more complicated than I originally explained. I was working with a concatenated list, so the element id's had to all be different for each different modal window.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •