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! Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/ 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. Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-498570 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 Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-498593 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. Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-498607 Share on other sites More sharing options...
Yuki Posted March 23, 2008 Author Share Posted March 23, 2008 any ideas? Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-498669 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? Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-498688 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 Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-498810 Share on other sites More sharing options...
Yuki Posted March 23, 2008 Author Share Posted March 23, 2008 is nothing possible then? Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-498856 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. Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-498861 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 Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-498867 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>"; ?> Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-498871 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. Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-498899 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! Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-498979 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. Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-498996 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 Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-499014 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. Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-499017 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 Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-499023 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. Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-499027 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.. Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-499030 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. Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-499070 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 Link to comment https://forums.phpfreaks.com/topic/97442-confusing-problem/#findComment-499094 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.