Yuki Posted March 23, 2008 Share Posted March 23, 2008 To see the site I'll be referring to,To see the site I'll be referring to, please goto http://shahinrostami.com/webdevass2/login.php SOURCE: http://shahinrostami.com/webdevass2/admin.phps http://shahinrostami.com/webdevass2/question.phps Username: admin Passsword: istrator Basically, navigate to a Question within a module, you'll see a form at the bottom for adding questions. when you click that, I need to be able to echo out either the MySQL error or "New Question Added" so I have: mysql_query($query) or die('Error, insert query failed'); echo = "New question added"; admin.php contains the div I want to be using to print out notifications like that, it's the <?php echo "<div class=\"notification\">"; echo $notification; echo "</div>"; ?> problem is it's above the case switches that include the body. I don't understand how to get round this purely using PHP, help please! Quote Link to comment Share on other sites More sharing options...
p2grace Posted March 23, 2008 Share Posted March 23, 2008 Instead of echoing it there, assign it to a variable. Then below, in the appropriate location, echo out that variable. Quote Link to comment Share on other sites More sharing options...
Yuki Posted March 23, 2008 Author Share Posted March 23, 2008 no you see that's the problem, it needs to be echo'd in a div above the div where it can be assigned, have alook at the source, I've already tried what you suggested Quote Link to comment Share on other sites More sharing options...
Yuki Posted March 23, 2008 Author Share Posted March 23, 2008 Most my code is procedural, the only thing that I've made my own function for is when I have to re-use the EXACT same code twice. The part that needs to print out the message is the parent, I consider the include the child (conceptually in this scenario) $notification; echo $notification; // question.php has a form in it that inserts questions into the db include "question.php"; now, I want $notification to print out the mysql error message. Problem is, it's echo'd before the include, if it was after, all would be fine, I could do it like the previous poster stated, cast it into a variable, and print it out. Quote Link to comment Share on other sites More sharing options...
Yuki Posted March 23, 2008 Author Share Posted March 23, 2008 any ideas? Quote Link to comment Share on other sites More sharing options...
Jeremysr Posted March 23, 2008 Share Posted March 23, 2008 Why can't you echo it inside the question.php file? Quote Link to comment Share on other sites More sharing options...
Yuki Posted March 23, 2008 Author Share Posted March 23, 2008 because the site layout isn't like that, check the link, it needs to be echo'd out inside the red thin box Quote Link to comment Share on other sites More sharing options...
Yuki Posted March 23, 2008 Author Share Posted March 23, 2008 is nothing possible then? Quote Link to comment Share on other sites More sharing options...
p2grace Posted March 23, 2008 Share Posted March 23, 2008 Either you need to rethink the logic behind the system, or you need to use javascript/ajax (your preference) to update the div with the correct content. Quote Link to comment Share on other sites More sharing options...
Yuki Posted March 23, 2008 Author Share Posted March 23, 2008 It's going to have to be AJAX/Javascript. Was trying to avoid learning any of that until this project is over, I understand the concepts though, anyone have any links to tutorials/manuals with simple explenations of something as simple as I'm trying to do? ONE div on the page that needs to have something echo'd out to it AFTER it's displayed Quote Link to comment Share on other sites More sharing options...
p2grace Posted March 23, 2008 Share Posted March 23, 2008 If you have the id of the div you could use this in your php script. Javascript Example: <?php // the code you want to echo $echo = "this is the html code"; // script to display it echo "<script type='text/javascript'>document.getElementById('id_of_div').innerHTML = '".$echo."';</script>"; ?> Quote Link to comment Share on other sites More sharing options...
Yuki Posted March 23, 2008 Author Share Posted March 23, 2008 I'll try that when I get back to work, looks very simple and I can understand it! Hope it works fine, thank you very much. Quote Link to comment Share on other sites More sharing options...
Yuki Posted March 23, 2008 Author Share Posted March 23, 2008 Cool it works, now I just need a way of hiding the DIV whe there's no text output to it, any ideas? Help! Quote Link to comment Share on other sites More sharing options...
p2grace Posted March 23, 2008 Share Posted March 23, 2008 By default have it shown to display none. Then change the display to block with javascript. Quote Link to comment Share on other sites More sharing options...
Yuki Posted March 23, 2008 Author Share Posted March 23, 2008 Makes sense but I can't seem to get my head round it. The Stylesheet is included, .css file .notification{ background-color: #DB4105; color: #FFF8E3; width: 60%; display: none; } I've added display: none; what would I pass through using javascript Quote Link to comment Share on other sites More sharing options...
p2grace Posted March 23, 2008 Share Posted March 23, 2008 Don't add display none to the css stylesheet, hard-code it into the div. Here's how it should work. <!-- FOR THE DIV --> <div id="div_id" style="display: none;"></div> <?php // the code you want to echo $echo = "this is the html code"; // script to display it echo "<script type='text/javascript'> var divid = document.getElementById('div_id'); divid.style.display = 'block'; divid.innerHTML = '".$echo."'; </script>"; ?> I believe that should work. I didn't test it. Quote Link to comment Share on other sites More sharing options...
Yuki Posted March 23, 2008 Author Share Posted March 23, 2008 Hey I tested it, it doesn't work, doesn't display the box Quote Link to comment Share on other sites More sharing options...
p2grace Posted March 23, 2008 Share Posted March 23, 2008 Hmm try this instead: <!-- FOR THE DIV --> <div id="div_id" style="display: hidden;"></div> <?php // the code you want to echo $echo = "this is the html code"; // script to display it echo "<script type='text/javascript'> var divid = document.getElementById('div_id'); divid.style.visibility = 'visible'; divid.innerHTML = '".$echo."'; </script>"; ?> See if that works. Quote Link to comment Share on other sites More sharing options...
Yuki Posted March 23, 2008 Author Share Posted March 23, 2008 display: hidden doesn't hidethe div, it's still visible.. Quote Link to comment Share on other sites More sharing options...
p2grace Posted March 23, 2008 Share Posted March 23, 2008 sorry, it's supposed to be visibility: hidden. Quote Link to comment Share on other sites More sharing options...
Yuki Posted March 24, 2008 Author Share Posted March 24, 2008 Hey, I managed to get it working with the original code you gave me and http://www.devpapers.com/article/72 thak you Quote Link to comment 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.