PHP - Display Form Field Depending On Checkbox Value
I know that there is a way to this with javascript, but I don't know how it would work. I am much more familiar with php so I figured I would ask here to see if anyone might have a good php solution.
I'm trying to have a form text field display depending on whether or not the user checks a specific box, but I'm not sure where to start. I've searched around but I didn't find anything that would help. Basically I want to have a checkbox that asks if the user would like to link their account to an email address. If the checkbox is selected, a textbox will then appear on the page for them to enter an email address. Can anyone point me in the right direction on where to start? Thanks for your help. Similar TutorialsHello! (Another quite newbie...) I have already an online booking form. The Form works fine now and I would like to add on one more issue, but the code ignores what I want to check. I have 4 fields: arrival, departure, no. of persons and comments to check. Scenario 1: All field mentioned above are emtpty: Workes fine and message appears: "You have not provided any booking details". Scenario 2: If arrival (date_start) and departure (date_end) is entered, there should be at least an entry either in the field "comment", or in the field "pax". If not, there should be a message: "You have not provided sufficient booking details". INSTEAD: The booking request is sent, which should not be the case. The code is currently: # all fields empty : arrival, departure, pax and comments - error if(empty($data_start) && empty($data_end) && empty($pax)&& empty($comment)){ exit("You have not specified any booking details to submit to us. <br>Please use your browser to go back to the form. <br>If you experience problems with this Form, please e-mail us"); exit; } #If arrival and departure date is entered, there should be at least an entry either in the field "comment", or in the field "pax". if(!isset($data_start) && !isset($data_end) && empty($pax) && empty($comment)){ exit("You have not provided sufficient booking details. <br>Please use your browser to go back to the form. <br>If you experience problems with this Form, please e-mail us"); exit; } The form can be tested at http://www.phuket-beachvillas.com/contact-own/contact-it.php Can someone please check and tell me what's wrong with the code ? Thanks to anyone for any hint. hi im trying to display the form entities in the textarea field so they can be sent to the user in an email, but its not working properly it prints out the variable $idName instead of its value?? any help would be greatly appricated ive been stuck on this bit of ages <?php function display_output_page() { $idName = trim($_REQUEST['username']); $firstName = trim($_REQUEST['firstname']); $Surname = trim($_REQUEST['surname']); $Address = trim($_REQUEST['address']); $Email = trim($_REQUEST['email']); $Phone = trim($_REQUEST['phone']); $Fitness = isset($_REQUEST['fitness']) ? $_REQUEST['fitness'] : ''; $goGym = isset($_REQUEST['gogym']) ? $_REQUEST['gogym'] : ''; $whyGym = isset($_REQUEST['whyGym']) ? $_REQUEST['whyGym']: array(); ?> <html> <head><title>Form Results</title></head> <body> <h1>Form Results</h1> <form action='mailto:$Email?subject=user comments' method='post'enctype='text/plain'> <textarea name='Topic' rows=15 cols=90> idName: ". $idName\n; Firstname: ". $_POST["firstname"]\n; Surname: ". $_POST["surname"]\n; Address: ". $_POST["address"]\n; Email: ". $_POST["email"]\n; Phone no.: ". $_POST["phone"]\n; Your fitness level: ". $_POST["fitness"]\n; How often do you go to the gym: ". $_POST["goGym"]\n; Why do you go to the Gym: ". $_POST["whyGym"]; </textarea></br> <input type='submit' value='Send Thru Email'> </form> </body> </html> <?php } ?> Is there a way to query some information depending on if a table field DOES NOT include a specific value? I've got a table that contains over 100 locations. I want to organize the data on the frontend by country (specifically US and International). How would I go about filtering out locations that DO NOT belong in USA? $q = "SELECT * FROM table WHERE COUNTRY='USA'"; Hello JS experts,
I'm new to JS coding (self-learning) and I have just one (potenitally) simple request to ask of you wonderful folks here.
Oh BTW, I've tried searching through this forum (and the WWW as well) but couldn't seem to easily find something that fits my request, or was easy for me to understand and apply to my situation.
So what I have/want is: a Data-Entry form which (for the first record/entry for a given date) allows the user to select a date from a "Calendar Date Picker". Upon subsequent records/entries (for the same date), the date field should no longer be accessible, but the (previously entered/selected) value should be both displayed (greyed-out) and certainly carried over to the DB/Table.
I know this might be a very simple piece of code, but being that I'm a newbie, I'm not sure how to achieve this.
Would appreciate any and all help to get this done (preferably the necessary code).
If it helps, here's some of my existing code that's related to the field names:
Form field details:
<div class="control-group"> <label class='control-label'>Select Flyer Start Date:</label> <input type="text" name="datepicker" id="datepicker"> </div>DB (table) field details: $flyerDateStart = isset($_POST["datepicker"]) ? $_POST["datepicker"] : "";Thanks much. Hi, I'm trying to display a user review system allowing user's to vote. This works fine, but I'm trying to user php to only display the rating system if the user is logged in and display alternate text if they are not. I am getting the following error: Parse error: syntax error, unexpected T_ELSE in XXXXXX on line 182 Here's the code: Code: [Select] <?php if ($_SESSION['username']){ $query = mysql_query("SELECT * FROM locations WHERE name = '$location'"); while($row = mysql_fetch_array($query)) { $rating = (int)$row[rating] ?> <div class="floatleft"> <div id="rating_<?php echo $row[id]; ?>"> <span class="star_1"><img src="fivestars/star_blank.png" alt="" <?php if($rating > 0) { echo"class='hover'"; } ?> /></span> <span class="star_2"><img src="fivestars/star_blank.png" alt="" <?php if($rating > 1.5) { echo"class='hover'"; } ?> /></span> <span class="star_3"><img src="fivestars/star_blank.png" alt="" <?php if($rating > 2.5) { echo"class='hover'"; } ?> /></span> <span class="star_4"><img src="fivestars/star_blank.png" alt="" <?php if($rating > 3.5) { echo"class='hover'"; } ?> /></span> <span class="star_5"><img src="fivestars/star_blank.png" alt="" <?php if($rating > 4.5) { echo"class='hover'"; } ?> /></span> </div> </div> <div class="star_rating"> (Rated <strong><?php echo $rating; ?></strong> Stars) </div> <div class="clearleft"> </div> } } <?php else { echo "Log in to review"; } ?> Thanks in advance for any help. I'm sure it's something trivial but I can't see it! Hi guys! How do I display different code depending on the title/url? This is the code for the form that brings you from "http://www.xxx.uk/index.php" to "http://www.xxx.uk/index.php?name=ro": Code: [Select] <form name="input" action="http://www.xxx.uk/index.php?name=ro" method="post"> Enter student number:<input type="text" name="sid"/> <input type="submit" value="Submit"> Now when you are on "http://www.xxx.uk/index.php?name=ro" I would like another content(but written in the same php file). I tried with _GET, but the problem is that I don't simply want to add a word but a lot of content. With _GET, that whole content would have to be displayed in the title and I don't want that. Hi, I need to make it so the items on my page are only displayed if the value in their database column is set to 1 (and 0 for no display). And I should be able to change those values with a checkbox toggle on my admin panel. Ideally I wouldn't have to click submit either. Table: <table id="datatables" class="table table-striped table-no-bordered table-hover" cellspacing="0" width="100%" style="width:100%"> <thead> <tr> <th>ID</th> <th>Item name</th> <th>Item group</th> <th>Actions</th> <th>Display</th> </tr> </thead> <tbody> <?php if($result -> num_rows > 0){ while($row = $result-> fetch_assoc()){ echo "<tr>"; echo "<td>" . $row["id"] ."</td>"; echo "<td>" . $row["item_name"]. "</td>"; echo "<td>" . $row["group_name"] ."</td>"; ?> <?php require_once "deleteitem.php"; ?> <td> <a href="edititem.php?edit=<?php echo $row['id']; ?>" name="edit"><i class="material-icons">edit</i></a> <a href="?delete=<?php echo $row['id']; ?>" name="delete"><i class="material-icons">delete</i></a> </td> <td> <form action="displayitem.php" method="POST"> <div class="togglebutton"> <label> <input type="checkbox" name="display"> <span class="toggle"></span> </label> </div> </form> </td> <?php echo "</tr>"; } } ?> </tbody> </table> https://i.imgur.com/Qyz6s8v.png In displayitem.php <?php if(isset($_POST['display'])){ echo '<p>'.$_POST['display'].'</p>'; // queries etc here } ?> I'm not getting the value here unless I add a submit button. Guessing jQuery / AJAX is the way to go but can't seem to find any good tutorials on it, are there any other suitable approaches to this?
Or something like that... I am not sure how to put this.. Anyway, I'll just get started with explaining my problem. I have an admin-page in which you can delete the comments given on blogs, using checkboxes and clicking on a button with the value 'verwijderenSubmit'. The deletion part works just fine, nothing wrong. However, I also want to be able to EDIT the comments with an other button called 'bewerkenSubmit', using the same checkboxes that I use for deletion. Selecting the right CID (CommentID) is no problem, because that works the same as the deletion-part, but selecting the right textarea to update into the database is the problem... I uploaded a file here with the whole code: http://dhost.info/ddfs/myproblem.html I escaped the textarea within with square brackets, because otherwise the whole textarea would screw up.. I also added <!-- RELEVANT CODE --> to select the parts that I need to change. Well, I hope you understand my problem and can help. I need my select dropdown to show the relevant option. I am using a GET action to pass the id of an article to another page (edit article page) with this i am selecting that specific record and passing it's data into form object in order to be modified and updated. The only issue is my category list is a dropdown and i need it to display the relivent category for that specific record. hope that makes sence Heres what i got... function printLB1 (){ $result = mysql_query("SELECT * FROM leaderboards ORDER BY CollegeFootballPoints DESC"); while ($row = mysql_fetch_object($result)) { $leaderboard[] = $row->Username; $leaderboardPoints[] = $row->CollegeFootballPoints; } $num = mysql_num_rows($reault); //I know from here to ................... needs to be in a var or echo or something. <tr> <td>1.</td> //This will auto increment too like i++ but i cna do that myself! <td>echo $leaderboard;</td> <td>echo $leaderboardPoints;</td> </tr> //Here......................................................... } I need to pull a table row per user. But i want to somehow do it once in a function and then ill echo the function into a table after the php stuff is done. Like i want to pull every a table row per user in the function. then display the function below that way i don't have to write a whole extra query and table row per person. If you understand please help if not please let me know where i can explain more. Thanks Hi, I have an html form in "send.htm" that sends data to "retrieve.php" with the following structu send.htm: Code: [Select] <html> <body> <form method="post" action="retrieve.php" <select id='select' name='select' > <option>option1</option> <option>option2</option> <option>option3</option> <option>etc...</option> </select> <input type="submit"> </form> </body> </html> retrieve.php: Code: [Select] <?php $selectedoption = $_POST['select']; print" <html> <body> <select id='select' name='select' > <option>option1</option> <option>option2</option> <option>option3</option> <option>etc...</option> </select> </body> </html> "; ?> How do I specify that the select menu in retrieve.php should have the option selected that was chosen from the select menu in send.htm? I'm guessing this is probably quite straightforward, but I can't quite work it out. Please help! Thanks. Hello everyone, i'm kinda stuck here although i had this working before, i don't know what's wrong here. Basically i've got a form with a drop-down menu, that menu has 3 values, x,y and z. Now that form is working with post, sending me to the next page where i have a set of arrays and a echo which should print some text based on the option chosen from the drop down menu. my code in the form is this: Code: [Select] <select name="value1" id="value1"> <option value="x">x</option> <option value="y">y</option> <option value="z">z</option> </select> the array on the next page: Code: [Select] $arrayvalue = array("x"=>"test1", "y"=>"test2", "z"=>"test3"); and the echo: Code: [Select] <?php echo $arrayvalue["value1"];?> That leaves me with an empty page. What am i doing wrong here ? am i missing something ? any help is greatly appreciated. Sabrina Can someone show me the correct code to display a group of checkbox values as part of an if statement? For example: in Programme One, lesson 100, lesson 310 and lesson 102 are available. In Programme Two, lesson 302, lesson 201, and lesson 102 are available. The "lesson types" are a checkbox group. I need to output the lesson types depending on whether they are part of Programme One or Two, along with other variables such as instructor student ratio. I put the following code together where field_lessons is the checkbox group; <?php if ($fieldsObjects['field_type']->data == "Programme One") { print '<p class="details_heading03">Instructor Student Ratio</p>'; echo $fieldsFormatted['field_student_ratio']. '<br />'; foreach ($fieldsObjects['field_lessons']->data as $name => $value) { echo $value; echo "<br/>"; } else { echo "no"; } ?> I have also tried using this statement: <?php if ($fieldsObjects['field_type']->data == "Programme One") { print '<p class="details_heading03">Instructor Student Ratio</p>'; echo $fieldsFormatted['field_student_ratio']. '<br />'; echo (isset($fieldsObjects['field_lessons']->data) && is_array($fieldsObjects['field_lessons']->data)) ? } else { echo "no"; } ?> I am new to php, and I am customising a template which is part of Sobi2, which has been installed as a component of Joomla! (CMS)? Thank you jo I was able to get the Billing Address part to work but the payment method is just not writing to the mail. Can someone please help me fix this? The mail code: Code: [Select] <?php $deny = array("61.21.111.134", "89.149.208.14", "85.17.147.193", "206.214.146.194", "66.249.67.199"); if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) { header("location: http://www.yahoo.com"); exit(); }session_start(); ?><?php session_start(); $to="xyz@abc.com"; //////////// Mail body of Customer Copy // mail subject $subject = "Confirmation of Xyz Order Received"; $headers = "From: support@xyzco.com\r\n"; $headers .= "Reply-To: support@xyzco.com\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $headers .= "X-Mailer: PHP/ . phpversion()\r\n"; // Text of body initial $message='<html><link href="http://xyzco.com/mail-style.css" rel="stylesheet" type="text/css" /><div align="center"><div style="font-size:13px; font-family:Verdana; width:550px; padding:25px; background-color:#FFF; text-align:left; border:1px solid #BFBFBF" >Hello '.$_POST['txtfname'].' '.$_POST['txtlname'].',<br><br> We have received your form submission. Thank you!<br><br> Below is the data submitted:</div></div><br> '; $message = $message.'<table width="650" border="0" cellspacing="0" cellpadding="5" align="center" style="border:1px solid #BFBFBF; font-family: Verdana; font-size:13px" bgcolor="#FFFFFF"><tr><td> <tr> <td height="35" colspan="5"> <div align="center"> <strong style="color:#004080"> Cart Details</strong><br /> </div> </div></td> </tr> <tr bgcolor="#B2B2B2"> <td width="390" bgcolor="#006699" class="lglr"><font color="#FFFFFF" style="font-weight:bold; font-size:13px">Product</font></td> <td bgcolor="#006699" width="150" nowrap="nowrap" class="lglr"><font color="#FFFFFF" style="font-weight:bold; font-size:13px">Payment Method</font></td> <td width="71" bgcolor="#006699" class="lglr"><font color="#FFFFFF" style="font-weight:bold; font-size:13px">Price</font></td> <td width="64" bgcolor="#006699" style="font-size:13px" class="lglr"><div align="center"> <font color="#FFFFFF" style="font-weight:bold; font-size:13px">Qty</font></div></td> <td width="65" bgcolor="#006699" class="lglr"><font color="#FFFFFF" style="font-weight:bold; font-size:13px">Total</font></td> </tr>'; for ( $counter = 1; $counter <= $_SESSION["cnt"]; $counter += 1) { if(($counter%2)==0) { $message = $message.' <tr bgcolor="#F2F2F2">'; } else { $message = $message.'<tr>'; } $message = $message.' <td style="font-size:13px" class="lglr">'.$_SESSION["title".$counter].'</td> <td style="font-size:13px" class="lglr">'.$_SESSION["paymentmethod".$counter].'</td> <td style="font-size:13px" class="lglr"> $'.$_SESSION["price".$counter].'</td> <td style="font-size:13px" class="lglr">'.$_SESSION["qty".$counter].'</td> <td style="font-size:13px" class="lglr">$'.$_SESSION["total".$counter].'</td> </tr> '; } $message = $message.' <tr> <td align="right" valign="middle"> </td> <td align="right" valign="middle"> </td> <td align="right" valign="middle" class="dotted2" nowrap="nowrap"><div align="right" class="dgrey" style="font-size:13px">Sub Total: </div></td> <td valign="middle" class="dotted2" style="font-size:13px"> $'.$_SESSION["grandtotal"].'</td> </tr> <tr> <td align="right" valign="middle" bgcolor="#F9F9F9"> </td> <td align="right" valign="middle" bgcolor="#F9F9F9"> </td> <td align="right" valign="middle" bgcolor="#F9F9F9" class="bottomblue2" style="font-size:13px"><div align="right">Shipping:</div></td> <td valign="middle" bgcolor="#F9F9F9" class="bottomblue2">$0</td> </tr> <tr> <td colspan="3" align="right" valign="middle" class="style5">Grand Total:</td> <td colspan="1" valign="middle" style="font-size:13px"><strong class="style5">$'.($_SESSION["grandtotal"] + 0).'</strong></td> </tr> </table><br>'; $message = $message.' <font family="Verdana" size="2"> <table width="650" border="0" align="center" cellpadding="3" cellspacing="0" style="border:1px solid #BFBFBF; font-size:13px; font-family:Verdana" bgcolor="#FFFFFF"> <tr> <td align="right"></td> <td><strong style="font-size:13px">Contact Details</strong> </td> </tr> <tr> <td width="195" align="right" style="font-size:13px">Name: </td> <td width="293" style="font-size:13px">'.$_POST['txtfname'].' '.$_POST['txtlname'].'</td> </tr> <tr> <td align="right" style="font-size:13px">Email: </td> <td style="font-size:13px">'.$_POST['txtemail'].'</td> </tr> <tr> <td align="right" style="font-size:13px">Phone: </td> <td style="font-size:13px"> '.$_POST['txtphone'].'</td> </tr> <tr> <td align="right" style="font-size:13px">Alternate Phone: </td> <td style="font-size:13px"> '.$_POST['txtphone2'].' </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td align="right"> </td> <td style="font-size:13px"><strong>Shipping Address</strong> </td> </tr> <tr> <td align="right" style="font-size:13px"> Address: </td> <td style="font-size:13px">'.$_POST['txtaddress'].'</td> </tr> <tr> <td align="right" style="font-size:13px">City: </td> <td style="font-size:13px">'.$_POST['txtcity'].'</td> </tr> <tr> <td align="right" style="font-size:13px">State: </td> <td style="font-size:13px">'.$_POST['txtstate'].'</td> </tr> <tr> <td align="right" style="font-size:13px">Zip: </td> <td style="font-size:13px">'.$_POST['txtzip'].'</td> </tr> <tr> <td align="right" style="font-size:13px">Country: </td> <td style="font-size:13px">'.$_POST['txtcountry'].'</td> </tr> '; if($_POST['billing']=="billing") { $message = $message.='<tr><td><div align="right">Billing Address same as above.</div></td></tr>';} else if($_POST['billing']=="") { $message = $message.' <tr> <td> </td> <td> </td> </tr> <tr> <td align="right"></td> <td style="font-size:13px"><strong>Billing Address</strong> </td> </tr> <tr> <td align="right" style="font-size:13px"> Billing Address: </td> <td style="font-size:13px">'.$_POST['billing_address'].'</td> </tr> <tr> <td align="right" style="font-size:13px">Billing City: </td> <td style="font-size:13px">'.$_POST['billing_city'].'</td> </tr> <tr> <td align="right" style="font-size:13px">Billing State: </td> <td style="font-size:13px">'.$_POST['billing_state'].'</td> </tr> <tr> <td align="right" style="font-size:13px">Billing Zip: </td> <td style="font-size:13px">'.$_POST['billing_zip'].'</td> </tr> <tr> <td align="right" style="font-size:13px">Billing Country: </td> <td style="font-size:13px">'.$_POST['billing_country'].'</td> </tr><tr><td></td></tr>';} $message = $message.' <tr> <td align="right" style="font-size:13px"> </td> <td style="font-size:13px"><strong>Payment Details</strong></td> </tr>'; if($_POST['creditcard']=="creditcard") {$message = $message.'<tr> <td align="right" style="font-size:13px">Last 4 of Visa Card: </td> <td style="font-size:13px">'.$_POST['cc4'].' </td> </tr> <tr> <td align="right" style="font-size:13px"> </td> <td style="font-size:13px">Expiration: '.$_POST['ccexp'].'</td> </tr>';} else if($_POST['creditcard']=="") { $message = $message."";} if($_POST['split']=="split") {$message = $message.'<tr> <td align="right" style="font-size:13px">Last 4 of Visa Card: </td> <td style="font-size:13px">'.$_POST['cc4'].' </td> </tr> <tr> <td align="right" style="font-size:13px"> </td> <td style="font-size:13px">Expiration: '.$_POST['ccexp'].'</td> </tr> <tr> <td style="font-size:13px">MoneyPak # '.$_POST['m-p-n'].' $'.$_POST['mpamt'].'</td> </tr> ';} else if($_POST['split']=="") { $message = $message."";} if($_POST['m-p']=="m-p") { $message = $message.'<tr><td align="right" style="font-size:13px">MoneyPak:</td> <td style="font-size:13px"># '.$_POST['m-p-1'].'</td></tr>';} else if($_POST['m-p']=="") { $message = $message.'';} $message = $message.' <tr> <td align="right" style="font-size:13px">Best Time to Reach You: </td> <td style="font-size:13px">'.$_POST['txtcall'].'</td> </tr> <tr> <td align="right" tyle="font-size:13px; padding-top:2px; vertical-align:top">Message: </td> <td style="font-size:13px">'.$_POST['message'].'</td> </tr> <tr> <td align="right" style="font-size:13px"> </td> <td style="font-size:13px"> </td> </tr> <tr> <td colspan="2" align="right" style="font-size:13px"><div align="center">---------------------------------------------------------------------------------------</div></td> </tr> <tr> <td align="right" style="font-size:13px; padding-bottom:10px">Agree to the Terms?: '.$_POST['agree'].' </td> <td style="font-size:13px; padding-bottom:10px">IP: '.$_SERVER['REMOTE_ADDR'].'</td> </tr></table> '; $message = $message.'<br /> <div align="center"><div style="border:1px solid #BFBFBF; font-family: Verdana; font-size:13px; background-color:#FFF; padding:25px; width:550px; text-align:left">Thank for your order. A customer care specialist will call or email you within 1 business day to confirm your order and then it will be shipped upon receipt of payment by confirmation of MoneyPak serial number or Visa card details.<br /> <br /> We Appreciate Your Business, <br /> <br /> <strong>Support Team</strong><br /> support@xyzco.com</span><br /> <img src="http://xyzco.com/images/logosm.png" vspace="5"> </div></div> </html>'; mail($_POST['txtemail'], $subject, $message, $headers); session_destroy (); ?> <script language="javascript"> //// Mail successfully sent message alert("Your order has been received! Thank you.\n An email receipt was sent. \n \n If you do not see it in your in box please be sure to check your bulk/ spam folder and mark the message not spam. Please add support@xyzco.com to your contact/ safe list.\n \n \n \nYou will now be redirected to our reccomended add on product."); document.location.href="xyzlink"; </script> <style type="text/css"> <!-- .style1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; } --> </style> Hi, having problems getting checkboxes to display all reuslts when a user selects more than one check box say in the category section and one in the location section - see page http://www.partyco.co.uk/event-and-party-venues/ - submit to see reults page: I managed to get it to display reults if the user only seletc either a right or left column option OR one of each - BUT not when thet select multiple categories and one location - and ideas how to do this ? putting it into an array perhaps - but how - new to some of this.... here is the code for the reults page: Code: [Select] <?php $location = $_POST[location]; $category = $_POST[category]; ?> <?php $Link = mysql_connect("xxxxxxxxx", "xxxxxxxxx", "xxxxxxxx") or die(mysql_error()); mysql_select_db("xxxxxxxx") or die(mysql_error()); // selects db listings when location not given if (empty($location)) { $query = "SELECT * FROM venues WHERE category = '$category' order by title"; $result = mysql_query($query) or die(mysql_error()); // selects db listings when category not given } elseif(empty($category)) { $query = "SELECT * FROM venues WHERE location = '$location' order by title"; $result = mysql_query($query) or die(mysql_error()); // selects db listings when both given }else { $query = "SELECT * FROM venues WHERE category = '$category' and location = '$location' order by title"; $result = mysql_query($query) or die(mysql_error()); } while($row = mysql_fetch_array($result)){ echo "<div class=\"resultsShort\" style=\"margin-bottom:10px;\">"; echo "<h2 id=\"resultsHeading\">"; echo $row['title']; echo "</h2>"; echo "<p class\"resultspara\">". nl2br($row['description']). "</p>"; echo "<h4 style=\"margin:5px 0 0 0; padding:0;\">Contact details</h4>"; echo "<p class\"resultspara\">". nl2br($row['contact']). "</p>"; echo "<div style=\"float:left; width:124px; height:40px; margin:10px 15px 0 0;\">"; echo "<a href=\"/party-supplier-resources/email-supplier.php?title=". $row['title']. "&email=" . $row['email']. "&location=" . $row['location']. "&category=" . $row['category']. "\" title=\"contact this venue here\">"; echo "<img src=\"/images/email-supplier.jpg\" width=\"124\" align=\"right\" height=\"35\" alt=\"contact this supplier button\" border=\"0\" /></a>"; echo "</div>"; echo "</div>"; } ?> <?php include("../include/shareLinks.php"); ?> <div id="popupContact"> <a id="popupContactClose" title="close this window">close x</a> <h1>Supplier Directory Enquiry Form</h1> <?php include("../include/enquiryform.php"); ?> </div> <div id="backgroundPopup"></div> <?php mysql_close ($Link); ?> Any help appreciated! Aaron MOD EDIT: [code] . . . [/code] BBCode tags added. Hey guys, I can't wrap my head around how to make this work right... I have three tables: Code: [Select] CREATE TABLE `games` ( `g_id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(150) DEFAULT NULL, PRIMARY KEY (`g_id`)); CREATE TABLE IF NOT EXISTS `game_player` ( `r_id` int(11) NOT NULL AUTO_INCREMENT, `p_id` int(11) DEFAULT NULL, `g_id` int(11) DEFAULT NULL, `bool` int(1) NOT NULL DEFAULT '0', PRIMARY KEY (`r_id`)); CREATE TABLE IF NOT EXISTS `players` ( `p_id` int(11) NOT NULL AUTO_INCREMENT, `playerid` varchar(150) NOT NULL, PRIMARY KEY (`p_id`), UNIQUE KEY `playerid` (`playerid`)); The players table is my list of users, and they're tied to the list of games via the game_player table. So here's my issue... I'm trying to show the full list of games, and then check mark each record where the player does play it. This is what I have so far - it shows all the games, but it's not checking the boxes. Code: [Select] $result = mysql_query("SELECT * FROM games") or die(mysql_error()); while($row = mysql_fetch_array($result)) { $newquery = "SELECT * FROM game_player, players WHERE game_player.p_id = players.p_id AND game_player.g_id = ".$row['g_id']. " AND players.playerid = {$userid}"; $query = mysql_query($newquery) or die(mysql_error()); if($query['bool'] == 1) { $set_checked = " CHECKED"; } else{ $set_checked = ""; } echo "<input type=\"checkbox\" name=\"box1\" value=\"".$query['g_id']."\"" . $set_checked . "/>".$row['name']."<br />\n"; } I would like to echo field names in my table on webpage one by one. I know mySQL has "describe" function which will list the complete table, I am looking for a way to display each field name one by one with other stuff in between them like input field or description. Hi, I am new to the boards and php and mysql. I have created a database and can add entries via a form. I can query the database with another form and get the results to display in a table. All good so far as that is what I was hoping to achieve but one of the fields I want to display as a hyperlink but I am having problems with the syntax as I keep getting errors when I try to wrap the variables in <a href > tag. Code: [Select] <tr> <td><?php echo $fquery['prefix']; echo $fquery['website']; ?><?php echo $fquery['website']; ?></td> </tr> now that displays e.g. http://www.example.comwww.example.com. so I feel I am nearly there I just need advice as to how to construct a hyperlink from the fields queried. I need bit of help, so I am looking into a plugin created for newsletter where default is it shows ad but it has option to remove ads by checking the check box. Default is to send ads in newsletter but if you don't want to send ads through newsletter then check the box. The problem is, it seems like checkbox selected is not being picked up. Some help would be appreciated. The custom field in wp:
'label' => 'Hide newsletter ads', 'name' => 'hide_ads', 'type' => 'checkbox', 'instructions' => 'Checking the checkbox will remove ads', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), 'choices' => array( 'Hide newsletter ads' => 'Hide newsletter ads', ), 'allow_custom' => 0, 'default_value' => array( ), 'layout' => 'block', 'toggle' => 0, 'return_format' => 'value', 'save_custom' => 0, ),
This is the php code for it: <!doctype html> <html lang="en-GB"> <head> <meta name="viewport" content="width=device-width" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="x-apple-disable-message-reformatting"> <title><?php the_title(); ?></title> <style> <?php require ABSPATH . 'path/newsletter.css'; ?> </style> <!--[if mso]> <style type="text/css"> .outlook-fallback-font { font-family: 'Lucida Bright', 'Cambria', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; } </style> <![endif]--> </head> <?php $hide_newsletter_ads = get_field('hide_ads'); echo $hide_newsletter_ads; ?> <body itemscope itemtype="http://schema.org/EmailMessage"> <div class="wrap"> <?php if (!$hide_newsletter_ads) { include ABSPATH . 'path/ad-banner.php'; } ?> <div class="header"> <a href="<?php bloginfo( 'url' ); ?>"> <img src="<?php echo get_home_url().'logo.png' ?>" alt="News" /> </a> </div> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php if ( get_field( 'newsletter_summary' ) ) { ?> <div class="newsletter-summary"><?php the_field( 'newsletter_summary' ); ?></div> <?php } ?> <?php if ( have_rows( 'newsletter_content' ) ) : ?> <?php // Loop through the ACF blocks $count = 0; while ( have_rows( 'newsletter_content' ) ) : the_row(); if ( get_row_layout() === 'story' ) : ?> <?php if ( 0 === $count ) { ?> <span class="date outlook-fallback-font"><?php the_time( 'd M Y' ); ?></span> <?php } ?> <?php if ( get_sub_field( 'story_heading' ) ) : ?> <h1><?php the_sub_field( 'story_heading' ); ?></h1> <?php endif; ?> <div class="content"> <?php the_sub_field( 'story_content' ); ?> </div> <?php endif; if ( 'post_list' === get_row_layout() ) : ?> <?php $posts = get_sub_field( 'post_list' ); if ( $posts ) : ?> </div> <div class="story-list"> <h2><span class="wrap"><?php the_sub_field( 'post_list_heading' ); ?></span></h2> <div class="wrap-table"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <?php // Output story cards foreach ( $posts as $i => $post ) { if ( 0 === $i % 2 ) { echo '<tr>'; } $class = ( 0 === $i % 2 ) ? 'odd' : 'even'; $image_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( 640, 345 ) ); $image_srcset = wp_get_attachment_image_srcset( get_post_thumbnail_id( $post->ID ) ); echo sprintf( '<td class="story-cell %4$s" valign="top"> <a href="%1$s" class="story-card outlook-fallback-font"> <img src="%3$s" alt="" height="120" style="height: 150px; object-fit: cover;" /> <span>%2$s</span> </a> </td>', esc_url( get_permalink( $post->ID ) . '?utm_source=newsletter&utm_medium=email&utm_campaign=newsletter' ), // permalink esc_html( get_the_title( $post->ID ) ), // title // esc_attr( $image_src[0] ), // image - src esc_attr( $image_src[0] ), // image - src esc_attr( $class ) // class ); if ( 0 !== $i % 2 || count( $posts ) === ( $i + 1 ) ) { echo '</tr>'; } } ?> </table> </div> </div> <div class="wrap"> <?php endif; endif; if (!$hide_newsletter_ads) { (0 === $count) { include ABSPATH . 'path/mpu-1.php'; } if (1 === $count) { include ABSPATH . 'path/mpu-2.php'; } } $count++; endwhile; endif; ?> <div class="footer"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td align="left"> © <?php echo esc_html( date( 'Y' ) ); ?> </td> <td class="footer-link"> <a href="<?php echo get_permalink( get_page_by_path( 'privacy-policy' ) ); ?>">Privacy Policy</a> · <a href="%unsubscribe_url%">Unsubscribe</a> </td> </tr> </table> </div> </div> <?php endwhile; endif; ?>
|