Why does the br html tag is ignored in the browser?
<p>
<?php
$footer_1 = the_field('footer_1');
$footer_2 = the_field('footer_2');
$footer_3 = the_field('footer_3');
if (!empty($footer_1)) {
the_field('footer_1');
echo "<br />";
}
if (!empty($footer_2)) {
the_field('footer_2');
echo "<br />";
}
if (!empty($footer_3)) {
the_field('footer_3');
}
?>
</p>
Edit: The browser code outputs the p element as one piece of text. No br tag displayed there either. The three variables are text fields from Advanced Custom Fields.
the_field is used to actually echo out the custom field data, so you cannot assign it to a variable. Use get_field instead, like so:
<p>
<?php
$footer_1 = get_field('footer_1');
$footer_2 = get_field('footer_2');
$footer_3 = get_field('footer_3');
if (!empty($footer_1)) {
echo $footer_1 . '<br>';
}
if (!empty($footer_2)) {
echo $footer_2 . '<br>';
}
if (!empty($footer_3)) {
echo $footer_3;
}
?>
</p>
Related
Part of the code is
while ($row = mysqli_fetch_assoc($result))
{
echo "$row[firstname] $row[lastname]";
echo "<hr>";
echo "<strong>Date Referred:</strong> $row[cf_831]";
echo "<br/>";
echo "<strong>Date Today:</strong> $today";
echo "<br/>";
}
How do I style this part for example?
"$row[firstname] $row[lastname]"
You can try
echo '<p class="mystyle">' . $row['firstname'] . " " . $row['lastname'] . '</p>';
Then add CSS
.mystyle {
}
Addition to Sidsec9's answer: if you are afraid of stylesheets, you can also consider:
echo '<p style="color: red; font-size: 10pt;">' . $row['firstname'] . " " . $row['lastname'] . '</p>';
You could also use styles to get rid of , for example using margin-right or padding-right properties.
echo '<p id="name"> '. $row[firstname] $row[lastname] .'</p>';
Css you only using for name alone use id else use class and use the single css for all values.
#name
{
color: red;
}
You can wrap it in a class, and fix it with a stylesheet. I also changed the echo, you're allowed to close the PHP tag, do some HTML and then open PHP again.
<?=$variable?> is short echo, it is the same as <?php echo $variable; ?>.
while ($row = mysqli_fetch_assoc($result)){
?>
<span class="Example"><?=$row[firstname].' '.$row[lastname]?></span>
<hr>
<strong>Date Referred:</strong> <?=$row[cf_831]?>
<br/>
<strong>Date Today:</strong> <?=$today?>
<br/>
<?php
}
A better method would be making and html file, say example.com, and place <!-- FIRSTNAME -->,<!-- LASTNAME --> AND <!-- TODAY --> instead of the variables. Then, using php:
$totalResult = "";
$template_one = file_get_contents("example.html");
while ($row = mysqli_fetch_assoc($result)){
$item = $template_one;
$item = str_replace("<!-- FIRSTNAME -->", $row['firstname'], $item);
$item = str_replace("<!-- LASTNAME -->", $row['lastname'], $item);
$totalResult.= $item; // add to totel result
)
// $today doesnt change in the loop, do it once after the loop is done:
$totalResult = str_replace("<!-- TODAY -->", $today, $totalResult);
echo $totalResult; // Now you have the result in a pretty variable
I have come this far and seem to be stuck on this trivial output issue, apologies in advance.
The $getexhibitions is an array and works when only this aspect of code is running. I have then added $results based on a LIKE keyword link that is intended to be an array within the array.
My problem is that the output is supposed to show $getexhibitions->title with the list of each $results->sponsor underneath. Java then creates a drop down with specific sponsor information. This will then repeat for the preceeding 8 years as so.
As you can see the code is getting stuck and i feel as though this may be a div or { problem or it may be more with the array code. Thanks in advance.
http://tenmoregirls.com/tenmoregirls/sponsors.php
<?php
$current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$query_getexhibitions = $mysqli->query("SELECT * FROM exhibitions ORDER BY year DESC");
if ($query_getexhibitions) {
while($getexhibitions = $query_getexhibitions->fetch_object()) {
echo "<a>$getexhibitions->year | $getexhibitions->title</a>", "<br />";
$sponsorlink = $getexhibitions->year;
$result = $mysqli->query("SELECT * FROM sponsors WHERE (`year` LIKE '%".$sponsorlink."%')");
if ($result) {
while($results = $result->fetch_object()) {
echo "<a href = \"javascript:void(0)\" class=\"subheading\" onclick = \"document.getElementById($results->id).style.display='block'\" >$results->sponsor</a>", "<br />";
echo "<div id=\"$results->id\" style=\"display: none;\">
<img src=\"exhibitstyles/links/close.png\" alt=\"close\" width=\"20\"/><br />";
echo '<img src="sponsorimages/'.$results->logo.'">';
echo $results->summary, "<br />";
echo "$results->website", "<br /><br /><br />";
} "</div>"; } "</div>";
}} exit(); ?>
It's probably not a problem with PHP and MYSQLI, but just with a wrong closing div tag, which is outside the loop. There is also one additional closing tag that don't seem to refer to anything. Try to move </div> tag inside the loop and delete the other one.
Edit:
You were also missing echo command before "</div>"; tag, because you used ; on the end of the previous line. You also can't use , between multiple echo parameters. . is a concatenation operator for strings in php. Whereas . is a concatenation operator for strings, echo construction also allows the usage of , between arguments. My bad.
Try this:
while($getexhibitions = $query_getexhibitions->fetch_object()) {
echo "<a>$getexhibitions->year | $getexhibitions->title</a><br />";
$sponsorlink = $getexhibitions->year;
$result = $mysqli->query("SELECT * FROM sponsors WHERE (`year` LIKE '%".$sponsorlink."%')");
if ($result) {
while($results = $result->fetch_object()) {
echo "<a href = \"javascript:void(0)\" class=\"subheading\" onclick = \"document.getElementById($results->id).style.display='block'\" >$results->sponsor</a><br />";
echo "<div id=\"$results->id\" style=\"display: none;\">
<img src=\"exhibitstyles/links/close.png\" alt=\"close\" width=\"20\"/><br />";
echo '<img src="sponsorimages/'.$results->logo.'">';
echo $results->summary . "<br />";
echo "$results->website<br /><br /><br />";
echo "</div>";
}
}
}
<?
//LUHN ALGORITHM PHP CONVERSION
// CREDIT CARD NUMBER CHECKER BY JACK BELLAMY - JACKBELLAMY.CO.UK
//----------- RETREIVE THE STRING FROM THE FORM POST -------------//
$var = $_POST['cardnumber'];
//----------- SPLIT THE 16 CHARACTOR STRING INTO INDIVIDUAL CHARACTERS AND ASSIGN TO INDIVIDUAL VARIABLES ---------------//
$n0 = $var[0];
$n1 = $var[1];
$n2 = $var[2];
$n3 = $var[3];
$n4 = $var[4];
$n5 = $var[5];
$n6 = $var[6];
$n7 = $var[7];
$n8 = $var[8];
$n9 = $var[9];
$n10 = $var[10];
$n11 = $var[11];
$n12 = $var[12];
$n13 = $var[13];
$n14 = $var[14];
$n15 = $var[15];
// ---------------------CHECKING THE CARDNUMBER FORM POST SUBMITS ALL VALUES PROPERLY
/*
echo $n0;
echo $n1;
echo $n2;
echo $n3;
echo $n4;
echo $n5;
echo $n6;
echo $n7;
echo $n8;
echo $n9;
echo $n10;
echo $n11;
echo $n12;
echo $n13;
echo $n14;
echo $n15;
*/
//-------ASSIGNING THE NEW VARIABLE VALUES ------------//
$n14_new = ($n14*2);
$n12_new = ($n12*2);
$n10_new = ($n10*2);
$n8_new = ($n8*2);
$n6_new = ($n6*2);
$n4_new = ($n4*2);
$n2_new = ($n2*2);
$n0_new = ($n0*2);
//!-----!------!//
//------------------------TESTING WITH THE NEW VARAIBLE *2
/*
echo $n0_new;
echo $n1;
echo $n2_new;
echo $n3;
echo $n4_new;
echo $n5;
echo $n6_new;
echo $n7;
echo $n8_new;
echo $n9;
echo $n10_new;
echo $n11;
echo $n12_new;
echo $n13;
echo $n14_new;
echo $n15;
*/
//--------- THE MATHS FOR THE COMPLETE SUM ------------ //
$isitlegit = ($n0_new+$n1+$n2_new+$n3+$n4_new+$n5+$n6_new+$n7+$n8_new+$n9+$n10_new+$n11+$n12_new+$n13+$n14_new+$n15);
//!----MATHS-----!//
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="veri-styles.css"
</head>
<body>
<div class="container">
<div class="main-wrapper">
<div id ="verification-wrapper">
<form action="" method="post" enctype="application/x-www-form-urlencoded">
<div id="input-holder">
<input name="cardnumber" type="text" class="input-style" placeholder=""> </input>
<button class="button-style">Verify my card</button>
</div>
</form>
<div class="result-class">
<?php
if(isset($isitlegit) && ($isitlegit % 5 == 0)) { // it's good
$new = "<img src='correct.jpg' />";
} elseif(isset($isitlegit) && ($isitlegit % 5 != 0)) { // it's bad
$new = "<img src='incorrect.jpg' />";
} elseif(!isset($isitlegit)) { // make sure this is not set
$new = "<img src='card-number-required.jpg' />";
}
echo $new;
?>
</div>
</div>
</div>
</body>
</html>
You have three states you need to account for, 'open', 'correct', and 'incorrect' To do that you start with an 'open' state.
$new = "<img src='please_enter your card number.jpg' />";
echo $new;
You would use that in the first condition of your test -
if(isset($var) && ($isitlegit % 5 == 0)) { // it's good
$new = "<img src='correct.jpg' />";
} elseif(isset($var) && ($isitlegit % 5 != 0)) { // it's bad
$new = "<img src='incorrect.jpg' />";
} else { // the default view
$new = "<img src='please_enter your card number.jpg' />";
}
echo $new;
Once submitted you can only have one of two states, never to return to the default.
In addition you have left your stylesheet declaration un-closed. Please change it to this -
<link rel="stylesheet" type="text/css" href="veri-styles.css" />
if(false===$submitted){
echo "Please type your card details here";
} else {
if($isitlegit % 5 == 0) {
$new = "<img src='correct.jpg' />";
echo $new;
}
else {
$new = "<img src='incorrect.jpg' />";
echo $new;
}
}
The best way I can think of to achieve this is with AJAX. Create a div on your page where your initial message is displayed, and then use an AJAX call to submit the form data to a script you'll use to validate it, and within that script, echo either a "Success! Your card has been verified" or a "Unable to validate your card" message. Then have your AJAX function change the .innerHTML of the div to the responseText element. You can see this answer for a good starting point, as well as a note about using the jQuery library to simplify your AJAX implementation.
Edit: In response to another user's downvote, here's some code.
First, let's give your HTML form a call to an AJAX object we'll create. So change your HTML form code to this:
<form onSubmit="return process()">
process() is a javaScript function we're going to set up later with the AJAX call. You already have a div established where you want this data to appear, but we need to give it an id, so change:
<div class="result-class">
please enter your card number<img src='correct.jpg' />
</div>
to this:
<div class="result-class" id="result">
Please enter your card number.
</div>
And also assign an id to your text input:
<input name="cardnumber" type="text" class="input-style" placeholder="" id="cardnumber"> </input>
Now we'll create the javaScript function. (This is easier with jQuery, but I wrote it in plain javaScript so you won't need the dependancy if you're not familiar with how to use jQuery.
function process(){
var xmlhttp = new XMLHttpRequest();
var cardnumber = document.getElementById("cardnumber").value;
var result = document.getElementById("result");
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
result.innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","validate.php?cardnumber=" + cardnumber,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send();
return false;
}
Now, use whatever php script you were going to use to validate the cc# and save it as a separate script called validate.php Use $_GET['cardnumber'] variable to fetch the cardnumber data sent from the form, run it through whatever validation process you are using. Use an if statement to create the responseText element for our AJAX function. You might have your script set some variable to boolean true or false to check this. I'll use $validated here.
if($validated){
echo 'Your card has been verified!';
} else {
echo 'Unable to validate your card.';
}
The AJAX function will change the text inside the "result" div to whatever text is echoed by your validate.php script.
This should get you on the right track, barring any syntax errors, I just wrote this all off the cuff.
Here is my code that returns a list of pictures, depending on how many of clients are connected to my server.
<div>
<?php
$Query = new MinecraftQuery( );
try
{
$Query->Connect( '64.31.40.146', 25575 );
if(($Players = $Query->GetPlayers()) !== false) {
foreach($Players as $Player) {
echo "<img title=".$Player." src=https://minotar.net/avatar/".$Player."/32.png>
<p>"."</p>";
}
}
}
catch( MinecraftQueryException $e )
{
echo $e->getMessage( );
}
?>
</div>
Though, when I do this. It displays the images stacked vertically.
http://i.imgur.com/FwvNAlB.png
What would be the best way to force the images to go horizontally?
It is due to you have <p> tag. Change your echo for this:
echo "<img title=".$Player." src=https://minotar.net/avatar/".$Player."/32.png>";
By default <p> tag change line.
Just remove the
<p>"."</p>
I don't know why you are adding it, but that is causing the problem.
Also add quotes and and a final "/" to the img tag.
So that line would be:
echo "<img title='".$Player."' src='https://minotar.net/avatar/".$Player."/32.png' />";
I have created a form that is handled by some PHP and echoed so it can be printed by the user. My problem is that when it prints it is printing everything. I would like to only print the text and not the print button or the url. I'll post the PHP code below.
<?php
$beq = $_REQUEST["beq"];
$blq = $_REQUEST["blq"];
$bwq = $_REQUEST["bwq"];
if ($beq>0)
{
echo ("Berry (SPR0110) " .$beq);
}
if ($blq>0)
{
echo ("<br />Black (SPA0212) " .$blq);
}
echo '<br /><br />Print';
?>
Quickest way:
<style type="text/css">
#media print {
.hide-on-print { display:none; }
}
</style>
<?
$beq = $_REQUEST["beq"];
$blq = $_REQUEST["blq"];
$bwq = $_REQUEST["bwq"];
if ($beq>0)
{
echo ("Berry (SPR0110) " .$beq);
}
if ($blq>0)
{
echo ("<br />Black (SPA0212) " .$blq);
}
echo '<div class="hide-on-print"><br /><br />Print</div>';
create a stylesheet with screen and print rules
Good rules for setting up print css?