0

I'm making a company phone directory and I'm having a hard time passing the user's phone number into the modal to make it so they can call or text using tel: and mms:. This is what I have and it's definitely not working.

php

<div class="list-block">   
<ul>
<?php
  $result2 = mysql_query("SELECT * FROM users WHERE terminationDate = '0000-00-00' ORDER BY `firstName`") or die("Query 2 Failed: $result2");
  while ($row2 = mysql_fetch_array($result2))
  {   
    echo "
        <li>
          <a href='?cellPhone=".$row2['cellPhone']."' class='open-3-modal item-link item-content'>
            <div class=\"item-media\"><img height=\"30px\" width=\"30px\" src=\"/photos/".$row2['firstName']."_".$row2['lastName'].".jpg\"></div>
            <div class='item-inner'>
              <div class='item-title'><strong>".$row2['firstName']."</strong> ".$row2['lastName']."</div>
            </div>
          </a>
        </li>
      ";
  }
?>
</ul>

js

    <script>$$('.open-3-modal').on('click', function () {
    myApp.modal({
    title:  'Call or Text',
    text: '',
    buttons: [
      {
        text: '<?php $result2 = mysql_query("SELECT * FROM users WHERE terminationDate = '0000-00-00' AND cellPhone = '".$_GET['cellPhone']."'") or die("Query 2 Failed: $result2");
              while ($row2 = mysql_fetch_array($result2))
              { echo '<a href="tel:'.$row2['cellPhone'].'" class="tab-link">Call</a>'; } ?>',
      },
      {
        text: '<a href="#" class="tab-link">Text</a>',
      },
      {
        text: 'Cancel',
        bold: true,
        close: function() {
          myApp.alert('Canceled')
        }
      },
     ]
   })
 });

I'm pretty rusty with JS as you can probably tell. What's the best method of passing the information over to jQuery?

1 Answers1

0

PHP will not work that way, because it's processed by the server before it ever gets to the browser. If you add it in at the client-side, it will not do anything.

What I would do is create a separate PHP file that does what you want--creates the markup you're needing and sends it to the browser. Then load the contents of that page into the modal via AJAX. There are many ways to do this. Here's a quick (untested) example:

    var newText;

    $.ajax({
      url: "your-file.php",
    }).done(function(html) {
        newText = html;
    });

   $$('.open-3-modal').on('click', function () {
        myApp.modal({
        title:  'Call or Text',
        text: '',
        buttons: [
          {
            text:  newText;
          },

     // etc. etc.
Barry T. Smith
  • 1,021
  • 7
  • 10