PHP - Dynamically Displaying/hiding Content Using Php
Hi!
So I have got some code that looks like this: Code: [Select] if (isset($_GET['view_log'])) { // show content (text from db) } When I click the button named "view_log" everything displays just fine, however I would like to be able to click the button again and make the content disappear. Is this possible using only PHP?? Thanks for the help!:) It is greatly appreciated! Similar TutorialsLet's say I have a script that updates the database every 5 minutes. Or fwrites to a text file at an interval. How do I say create a dynamic textbook or label that displays this information and automatically UPDATES on the page without the user clicking on REFRESH? Hi, I have some files stored in mysql db. I have created a web page which shows the list of tutorials from db. at first i was creating a separate php page for each tutorial, but later i have decided that it would be easier and simpler if i can create one php page and whenever i click the tutorials it will change the content of this page. example: when i click "tut002" from list. it will change the content of tutorials.php . I have these tutorials in .html format here is the code i have in turorials.php once again, whenever i click a tutorial this include part needs to change automatically to whatever i click Code: [Select] echo '<div class="content">'; include ("inc/tut001.html"); echo '</div>'; it will be really appreciated if you have a sample code for this. sorry for my english. thank to whoever interested in this matter. Hi, I have a table row that has a dropdown and two textboxes in it. I would like to use a button that allows me to add another row beneath the existing row. It cannot be added to the bottom of the table as there is further content beneath. The content of the dropdown comes from a database query. The dropdown on the new row should have the selection in the first row greyed out. I expect this will need to be a js function but i dont really know where to start with it being dynamic content. This is the table as it stands if this provides clarity of my intentions - picture below echo "<form method='post' id='staffOrderForm'>"; $stmt->close(); echo "<table id='staffOrderTable' class='table table-striped table-bordered mt-3 text-center'>"; foreach($daterange as $date){ echo" <tr> <th class='table-dark' colspan='3'>".$date->format("l - jS F Y")."</th> </tr> <tr> <th class='' colspan='3'>Management </th> </tr> <tr> <th class='col-4'>Name</th> <th class='col-4'>Start Time</th> <th class='col-4'>End Time</th> </tr> <tr> <td> <select class='custom-select managerSelect'>"; $managerRoleId = 1; $stmt = $conn->prepare(" SELECT user_firstname, user_lastname, user_id FROM ssm_user WHERE user_role_id = ? "); $stmt->bind_param("i", $managerRoleId); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($ufn, $uln, $uid); while($stmt->fetch()){echo "<option>".$ufn." ".$uln."</option>";}; echo"</select> </td> <td><input class='form-control' type='' name=''></td> <td><input class='form-control' type='' name=''></td> </tr> <tr> <th colspan='3'>Chefs</th> <tr/> <tr> <th class='col-4'>Name</th> <th class='col-4'>Start Time</th> <th class='col-4'>End Time</th> </tr> <tr> <td> <select class='custom-select chefSelect'>"; $chefRoleId = 2; $stmt = $conn->prepare(" SELECT user_firstname, user_lastname, user_id FROM ssm_user WHERE user_role_id = ? "); $stmt->bind_param("i", $chefRoleId); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($ufn, $uln, $uid); while($stmt->fetch()){echo "<option>".$ufn." ".$uln."</option>";}; echo"</select> </td> <td><input class='form-control' type='' name=''></td> <td><input class='form-control' type='' name=''></td> </tr>"; } echo "</table></form>"; I appreciate that i will likely have to add a button with an onclick but from there i am pretty lost. As always i appreciate the help provided. Hi! I'm a total stupid newbie. Please humor me. So, I'm trying to make a guestbook, just as practice. So far I have a form that writes entries to a file, each entry on a new line. Entries look like this: Code: [Select] 11:11 am, Oct 12th, 2010|name|website|message My dividing character between parts of the entries is the vertical bar. I don't know if that's a bad idea. As I said, I'm a newb. I should probably find out how to make a code that makes it so people can't use that character in the form. Anyway, this is my code so far trying to display the entries. So far, I just want to show the date of the first entry. $file = fopen("posts.txt", 'rb'); while(!feof($file) && fgetc($file) != "|"){ $date = $date.fgetc($file); } echo $date; fclose($file); I already have a problem. The code does stop at the vertical bar, but instead of showing the date as "11:11 am, Oct 12th, 2010" it shows "11 m c 2h 00". I'm just super confused, and I don't know what to do. Thanks. (: Hello! Looking for some advice regarding displaying content from my databases on my members websites via an iframe. Here's what I want to do; Members on my site are rated and reviewed, what I wanted to do was create a piece of code that they could embed on their website to show their reviews. My first instincts where to create an iframe and use the source to pass get variables to my server to identify the member and then use these in a query to select member reviews. Here is the code; For their site; Code: [Select] <iframe frameborder="0" height="250px" width="700px" scrolling="auto" src="http://www.mysite.co.uk/reviews.php?ID=9999&aKey=123456"></iframe> Passes the member ID and a unique access key for that member. The page on my site; (reviews.php) include_once $_SERVER['DOCUMENT_ROOT'] . // path to script files $ID=mysql_real_escape_string($_GET['ID']); $aKey=mysql_real_escape_string($_GET['aKey']); if(empty($aKey) || empty($ID)){ die("Key or ID not set,Selection Error"); exit;} $reviewresult = mysql_query("SELECT Name,Review,Date FROM Reviews WHERE ID='$ID' AND aKey='$aKey' Order by RAND() Limit 10"); //if there is at least one review if($reviewresult && mysql_num_rows($reviewresult) > 0) { while($review = mysql_fetch_array($reviewresult)) { // output reviews } } Are there any security risks with this script? Do you think it is the best method to accomplish what I want? Are there better alternatives? Any suggestions or room for improvement? Thanks! Hi all, I'm not sure if this is a PHP question or javascript, so if it needs to be moved can an admin please do so... Anyway, basically I have the following code: Code: [Select] <a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">View Availability</a> This pops up a divs with a black alpha background, so that it appears the new content is displaying over the top of the current content. This all works fine, however the content I am displaying in the top level div is (or should be) dynamic. In order for the content to be useful I need to grab the id. Normally I would simply do this: Code: [Select] <a href = "[b]url.php?uniqueidentifier=<?php echo $row['id'];?>[/b]" onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">View Availability</a> However what happens in this instance is that the page loads with the javascript and the id in the url but it then disappears... Has anyone got any ideas on how I might be able to get around this? Many thanks, Greens85 Hi Guys what I need to do is display data from two different tables that equal the same value in a specific field Table one has ID Title Course content table two has ID Title Start date End date I need a query that says if title from table one matches title from table 2 then will display the start and end date from table two sorry if this is really simple I am a newbie thanks inadvance Hi, When i am getting the part of the text using the function substr, am getting this kind of problem , (text in the end not printing properly) how to solve this. تسر مؤسسة مهارات التقنية ومؤسسة اشبكة الثنائية ان تطلع جميع عملاءها بإصدار نظام تاتش لإدارة الموقع الالكترونية من يوم السبت ا� This is the code am using $sub_string_content = substr(strip_tags($temp['News_Content'],'<p></a><ul><li><div><span>'),0,300); Thanks, Hello - I'm opening my website up to visitors for free, and trying to bypass a login screen to go straight into the data content that was appearing after a user logged in. I have an index.php file that included the following code at the beginning: <?php session_start(); include("database.php"); include("login.php"); include("/vservers/skyranks/db_connect.php"); ?> <?header("Cache-control: private"); ?> <html> I deleted the "include("login.php"); line, and was successful at bypassing the username and login screen. However, the page that is supposed to display the data content is incomplete. In fact, it only displays my company's logo. Any ideas as to why the data content is not showing up? Thank you for any help with this, as my php is quite novice at this point. Regards - Joe I am wanting HTML to render within a table and sourcing the data from another file. In an attempt to do this, I tried: Code: [Select] <TABLE class="main"> <TR> <TD> <?php readfile('./1/index.html'); ?> </TD> </TR> </TABLE> This does not work and I am wondering if anyone knows how it can be done - or even if it can be done? Hello,
I recently posted here about an issue I was having with my database orientated products page.
I have now run into another problem where say if, /db.php was typed or /db.php?p=IDoNotExist was typed, it returns blank.
I have in my code the desired content to be displayed, but it just doesn't seem to want to make a show.
I was also wondering if it is possible to show different content for whatever the URL is, so for no parameter, the content about the products, and a non existent one, maybe "Product not found"?
Here is my code:
<?php $db=mysql_connect ("localhost", "webwibco_charlie", "Hello123") or die ('I cannot connect to the database because: ' . mysql_error()); $mydb=mysql_select_db("webwibco_products"); include("header.php"); $status = htmlspecialchars( @$_GET ['p'] ); if ($status == "floorpuzzles") { echo "<h1>Our Floor Puzzles</h1>"; $sql="SELECT ID, Name, Tags, Description, Category FROM products WHERE Category LIKE '%" . FloorPuzzles . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; echo "<div class=\"box\">"; echo "<h1>$Name</h1>"; echo "<div class=\"floorbox\"><a href=\"?p=$ID\"><img src=\"images/products/catalogue/big/floorpuzzles/$ID.jpg\" class=\"small\"></a></div>"; echo "<h2>$Description</h2>"; echo "</div>"; } ?> <? }else{ if ($status == $_GET["p"]) { $sql="SELECT ID, Name, Tags, Description, Pieces, Size, Barcode, Category FROM products WHERE ID = '" . $_GET['p'] . "'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; $Pieces =$row['Pieces']; $Size =$row['Size']; $Barcode =$row['Barcode']; echo "<div class=\"1\">"; echo "<h1>$Name</h1>"; echo "<div class=\"bigbox\">"; echo "<div class=\"floorbox\"><img src=\"images/products/catalogue/big/floorpuzzles/$ID.jpg\" class=\"big\"></div>"; echo "</div>"; echo "</div>"; echo "<div class=\"2\">"; echo "<p>Puzzle Pieces: $Pieces</p> <p>Puzzle Size: $Size</p> <p>Barcode: $Barcode</p>"; echo "</div>"; } }else{ ?> <? echo"<h1>Our Products</h1> <p>Our jigsaw puzzles are hand cut by skilled craftsmen and therefore each one is unique with self-correcting pieces. There is a strict quality control process at all stages by our highly experienced staff. The puzzles are durable and provide fun and excitement, enhancing learning and a child’s development.<p> <p>All of our jigsaws are made using materials from sustainable resources grown in managed forests. Where possible we support companies in the UK and source our components locally, most of our suppliers are in the East Midlands, many in Derbyshire and Nottinghamshire. We keep packaging to a minimum and take our environmental and ethical responsibilities very seriously.</p> <p>Reducing waste and recycling was a way of life for us before it became fashionable. We are constantly searching for new ideas and consult teachers when developing our jigsaws, which are often used within the national curriculum.</p> <p>As well as making our own range, we manufacture for leading suppliers to the education market. Check for \"Made in Britain\" and it is probably made by us.</p> <p>We have a wide variety of products available for viewing, from classic floor puzzles to innovative inset trays. You can take a look at all our products on this page, simply use the navigation buttons to your left.</p>"; }} include("footer.php"); ?>The final echo is what I wish to be displayed on the URL without or with an invalid parameter. Here is my site URL: http://www.webwib.co...saws/search.php (note that only the "Floor Puzzles" category has content within it). Thank you in advance for assistance. Hi people! I have this code: if ($_POST['remember'] == true) { // COOKIES ON! $time = time() + 20000; setcookie(user, $username, $time); setcookie(pass, $password, $time); header("Location: index.php"); echo "<h1 class='welcome'>Welcome ".$_COOKIE['user']." |</h1>"; echo "<div id='divlogin' style='visibility:hidden'></div>"; echo "<a href='logout.php'><h1 class='logout'><b>Logout</b></h1></a>"; }elseif ($_POST['remember'] == false){ echo "<div id='divlogin' style='visibility:hidden'></div>"; echo "Div hidden!"; } "remember" - is a checkbox. So, if the checkbox is checked then I will activate the cookies and hide the divlogin (till now everything is fine), but if the checkbox isn't checked, I will just hide the divlogin (and this don't happen), however, the echo "Div hidden!" works nicely. The code detects if the checkbox is checked or not, the only problem is that if isn't checked the div doens't hide. Any ideas? Thanks Hi! I have got an array which contains messages for different types of errors on my website (for login errors and such). My problem is however, that when the array is empty it still shows the message box (the CSS). here is the code I am using: Code: [Select] public function showMessages() { if (count($this->_messages > 0)) { echo '<div id="messages">'; foreach ($this->_messages as $msg) { echo $msg . '<br />'; } echo '</div>'; } } I am starting to think that I need to be doing this in JavaScript. I would prefer to do it using PHP only, if it is possible though. Thanks for the help! When I display my database entries, I want to hide some of the data. As you can see in this example: http://www.beat-the-spread.net/week1.php What I'd like to do is leave all the cells blank where the spread is zero. Here's the code I'm using: Code: [Select] while($row = mysql_fetch_array( $result )) { $i=1; if ($row['game_id']='$i') { echo "<tr><td>"; echo $row['date']; echo "</td><td>"; echo $row['team_name']; echo "</td><td>"; echo $row['owner']; echo "</td><td>"; echo $row['pt_spread']; echo "</td><td>"; echo $row['team_pts']; echo "</td><td>"; echo $row['team_bet']; echo "</td><td>"; echo $row['team_cover']; echo "</td><td>"; echo $row['owner_pts']; echo "</td></tr>"; if ($table_row_count % 2 && $table_row_count != 0) { echo ' <tr style="height: 8px"></tr> '; } $table_row_count++; } $i++; } echo "</table>"; I've been fooling with this for a couple hours and can't seem to find a decent way to do this. Can anybody help with this? Thanks. Hello, What if I wanted to publish a php program but want to hide the code so that even buyers would not get a look at it despite having the program fully functioning on their servers, is there a means through which I can hide the code so that it won't be shown even when the .php files are opened in a text editor? Hi all I have a website which has a payment system on it, I use sagepay, paypal and a few others. They all have relatively similar forms, in which the total amount to be paid is passed in a hidden form field, such as <input type="hidden" name="amount" value="25"> all the payment gateways I use have the same or similar method to send the total amount (ie: 25) for example, my paypal form is like <form action="https://www.paypal.com/cgi-bin/webscr" name="paypal_form" method="post">"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="item_name" value="items"> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="notify_url" value="complete.php"> <input type="hidden" name="return" value="complete.php"> <input type="hidden" name="cancel_return" value="complete.php"> <input type="submit" name="submit" value="PayPal" /> </form> this is all fine, apart from the user can use things like "firebug" to alter the total to be paid, so they can change $25 to $4 for example. So my question is, is there anyway with PHP to send over these form values are hidden variables. My idea was to post my form fields apart from the "cost" to a PHP script, then get PHP to grab the total from the database and dump the value in cost field and send it along with the other posted values. So really, is there anyway to get PHP to process a form data in a hidden enviroment, so my payment form URL is something like process.php and then process.php on my server deals with the sending of the paypal form data, but in a way that the user cannot see this data, so they basically never get to see the paypal form and any of its contents. Hopefully that kind of makes sense I have tried so many ideas, but cannot seem to find a solution, although when I do, hopefully the same method can be used on all my payment forms. Thanks tons in advance Hi, I will start off trying to explain what I am trying to make the best I can. What I want to create is a script that gets the gold value from this website: http://www.lbma.org.uk/pages/index.cfm?page_id=46&title=current_statistics and then save it to a variable which I will use to calculate values of different gold karats. Here is the content in bold I need on the website I linked: Quote LONDON GOLD FIXING USD GBP EUR AM 1588.00 1005.127 1251.083 PM 1589.50 1004.741 1249.803 So what help do I need? Well, I don't expect you to figure out the calculating part for me but some help how to get that content pointed out above and save it to a variable is what I would appreciate getting some help with. I don't know much PHP, only some and I have been trying to figure this out for a day now without any success. I suppose php get contents and/or curl should be used here but I don't know how really. I would very much appreciate the help I can get on this. Thank you! Hi there, Is it possible to hide text on a page using PHP? For example, hide the word "hello" every time it appears on the page? Or have it display in a different color? I am building a member-based website, and I've got a bunch of buttons that lead from page to page. The links for these buttons are generated based on user ID and subsequent pages receive this variable as well. So, if you hover over the buttons, you get a link like this: http://www.mysite.com?id=423 How can I hide the last part? The '?id=423'? I must use this format of variable, and cannot resort to session variables. Is there a way to hide this portion of the links?? Hi all, I am going to be offering downloads on my site to members. However i want to somehow hide the download link so that they are unable to copy and paste and give it to their friends. IE, they have to be logged into my site to be able to download it else its not possible. Any ideas? Thanks Jake! PS. Not sure if this is the correct forum. |