SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Code check: calling simple PHP function doesn't work

    I'm trying to trigger this function:
    Code:
    <?php
    function messageNoResults() {
    echo "<script>document.getElementById('messages').innerHTML = '<p>There are no results for that combo.</p>'<script>";
    }
    ?>
    I'm calling this function like this after two table queries have completed along with their mysql_num_count:
    Code:
    if ($counta == 0 && $countb == 0) { messageNoResults(); }
    The message should be inserted at the top of the page:
    Code:
    <!-- warning messages displayed here -->
    <div id="messages" style="color:red; text-align:center; visibility:visible;"></div>
    I can successfully echo each of these counts, and they will return 0 each, but the function is not called. Any reason why?
    Steve Husting

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,278
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    This works.

    PHP Code:
    function messageNoResults() {
        echo 
    "<script>document.getElementById('messages').innerHTML = '<p>There are no results for that combo.</p>'<script>";
    }

    $counta 0;
    $countb 0;

    if (
    $counta == && $countb == 0) { messageNoResults(); } 
    So the issue must be somewhere in the code we haven't seen.
    "First make it work. Then make it better."

  3. #3
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I was afraid of that.
    Steve Husting

  4. #4
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,840
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    The script has two open scripts tags, try replacing the second occurrence with a closing script tag.
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014

  5. #5
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by John_Betong View Post
    The script has two open scripts tags, try replacing the second occurrence with a closing script tag.
    Thank you! Thank you! Thank you!
    Steve Husting

  6. #6
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,840
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by StevenHu View Post
    Thank you! Thank you! Thank you!
    Just one thank you was enough

    Glad I was able to help.
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014


Bookmarks

Posting Permissions

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