CSS Data-Badge, Value not appearing from database - php

I have this list in welcome.php
<li>
<img src="images/referral.png" > Referral
</li>
Here I am trying to populate the circle with value from database. I am getting the right value, but its not appearing in the circle. Pardon my CSS please.
Copied this code from here http://www.cssportal.com/blog/create-css-notification-badge/
In the same welcome.php, CSS code is
.badge1 {
position:relative;
}
.badge1[data-badge]:before {
content:attr(data-badge);
position:absolute;
top:0px;
right:0px;
font-size:.7em;
background:green;
color:white;
width:18px;height:18px;
text-align:center;
line-height:18px;
border-radius:50%;
box-shadow:0 0 1px #211;
}
The php value I am trying to echo here comes from a php block after this code.
Code is:
<html><li>
<a href="#" class="badge1" data-badge="<?php echo "$row_cnt"; ?>" value = "
<?php echo "$row_cnt"; ?>"><img src="images/referral.png" > Referral</a>
</li>
</html>
<?php
// Get $row_cnt
?>
So how do I access this $row_cnt value above?
Any help would be helpful.

Remove quotation marks:
<?php echo $row_cnt; ?>
or even
<?=$row_cnt?>

You can not put " inside " so use the escape \ before it
or remove it in echo before the variable

Related

Adding Bullets to Preset Textarea Output - PHP

I am trying to add bullets to my defined texture output. I simply created a textarea in php with some preset text. How can I preface each piece of preset text with a bullet. I want the text in my textarea to look like this:
Name:
Address:
DOB:
Favorite Drink:
Here is my PHP code:
<?php
echo "<textarea name='' id='' style='width: 565px;' rows='8' cols='60'>";
echo "Name:";
echo "Address:";
echo "DOB:";
echo "Favorite Drink:";
echo "</textarea>";
?>
Thanks so much for your help!
If you must use a textarea, you can add the 'bullet' HTML entity in the string...
<?php
echo "<textarea name='' id='' style='width: 565px;' rows='8' cols='60'>";
echo "• Name:";
echo "• Address:";
echo "• DOB:";
echo "• Favorite Drink:";
echo "</textarea>";
?>
Otherwise, you can go with an unordered list as #Tim Hunter suggested:
<?php
echo "<ul>";
echo "<li>Name:</li>";
echo "<li>Address:</li>";
echo "<li>DOB:</li>";
echo "<li>Favorite Drink:</li>";
echo "</ul>";
?>
To write something in text area with bullets prefix, I code it with div instead of textarea, follow the below code snippets.
<?php
echo '<div class="editable" contenteditable="true">
<ul>
<li>List item1</li>
<li>List item2</li>
<li>List item3</li>
......
<li>List item(n)</li>
</ul>
</div>';
?>
I don't think it's possible to add bullet points inside a regular textarea. You could make an editable section or div with bullet points in it, but I don't think this works well with a form.
Also, putting the bullet points inside the textarea will allow users to delete them.
Since I assume you would be submitting the input in a form at some point, why not use regular inputs wrapped in li elements? That way, you can use the inputs in a submittable form, and the bullet points can't be deleted.
You can even style it to look like one big textarea!
<style>
#form { border: solid #666 1px; border-radius: 3px; }
#form input { border: 0; -webkit-appearance: none; background-color: unset; }
#form input:focus { outline: none; }
</style>
<form id="form">
<ul>
<li>Name: <input type="text" placeholder="Name"></li>
<li>Address: <input type="text" placeholder="Address"></li>
<li>DOB: <input type="text" placeholder="DOB"></li>
<li>Favorite Drink: <input type="text" placeholder="Favorite Drink"></li>
</ul>
</form>
http://jsfiddle.net/7tw21m3o/ <--- in action

How to add CSS style on a div under a PHP tag

Basically,I have a div under a php tag. I have already tried adding a style for it but none of it was working. I just need to apply a margin right. maybe my code was incorrect. some help? here is the jsfiddle link.
CSS:
.result_text{
margin-right: 25%;:
}
.result_text a{
margin-right: 25%;
}
PHP:
<?php
echo "<div class='result_text'> <a href='#' > This is a sample text </a> </div>" ;
?>
https://jsfiddle.net/cpj9s2p5/
Try like this:
<?php
echo "<div class='result_text' style='margin-right: 20px;'> <a href='#' > This is a sample text</a></div>";
?>
<?php echo "<div class='result_text'>"." <a href='#' >"." This is a sample text"." </a>"." </div>" ; ?>
Read more about concat.
<?php
echo "<div class='result_text' style='margin-right: 20px !important;'> <a href='#' > This is a sample text </a> </div>" ;
?>
dont forget !important in your style
The problem with your fiddle is that you don't have PHP running, it is just HTML and <?php echo "<div class='result_text'> is being commented out. If you had PHP running on a server this code should work as intended.

How to return PHP within PHP - AJAX

Beginner to PHP, so I am pretty sure this is a stupid question...but, was hoping someone can help me out.
I have a html/php form, which basically dynamically pulls in values from a DB for a dropdown.
//HTML/PHP (original page)
<div style="position: relative; float: left; width:236px; margin-right: 20px;">
<div id="variablebox" style="position: relative; float: left; width:215px; border: solid #0096D6; border-width: 1px; padding: 10px;">
<H2>Step 2: Select Variable Type</H2>
<form id="var" enctype="multipart/form-data">
<span style="float: left; margin-top:8px;">
<label class="fieldlabel"><span>Variable Type:</span></label></br>
<select id="variabletype" name="variabletype" class="selectfieldshadow">
<option value="">Select</option>
<?php
$list=mysqli_query($con, 'SELECT * FROM valuelist');
while($row_list=mysqli_fetch_array($list)){
?>
<option value="<?php echo $row_list['valuelistid']; ?>">
<?php echo $row_list['valuename']; ?>
</option>
<?php
}
?>
</select>
</span>
When this form is submitted, it basically submits to PHP file via AJAX and then return the same form to the screen within the same DIV.
//PHP Page
echo "<H2>Step 2: Select Variable Type</H2>";
echo "<form id='var' enctype='multipart/form-data'>";
echo "<span style='float: left; margin-top:8px;'>";
echo "<label class='fieldlabel'><span>Variable Type:</span></label></br>";
echo "<select id='variabletype' name='variabletype' class='selectfieldshadow'>";
echo "<option value=''>Select</option>";
echo "<?php";
echo "$list=mysqli_query($con, 'SELECT * FROM valuelist');";
echo "while($row_list=mysqli_fetch_array($list)){";
echo "?>";
echo "<option value="<?php echo $row_list['valuelistid']; ?>">";
echo "<?php echo $row_list['valuename']; ?>";
echo "</select>";
echo "</span>";
echo "<span style='position: relative; float: left; display: inline-block; margin-top: 7px; font: 12px Lucida Grande,Helvetica,Arial,Verdana,sans-serif; padding-right: 60px;'>";
echo "<p>Add Value Control Screenshot:</p>";
echo "<input id='controlimage' type='file' name='controlimage'>";
echo "</span>";
I keep getting errors with my output...T_Variable this and Exception that...my question is, am I going about doing this correctly? I mean, looking at my PHP file that will return content back to the original page, do I have to echo php tags so they work on the original page when returned? ie. echo "<?php" etc..
Any assistance would be much appreciated!
echo is used to output content. As it's currently written, you're just trying to display the PHP code. To execute it, you'll have to restructure your code as follows:
<!-- some HTML code -->
<?php
// display stuff
?>
<!-- continue with HTML -->
Well first of all, PHP is all rendered server-side. So that means returning PHP in an AJAX response doesn't make sense. It won't render on the client side.
Second of all, those echos look crazy too. There are several different ways to output large text like that. Personally, I like to just close the PHP tag and write it. So your second file could look like this instead:
// end all PHP for now
?>
<H2>Step 2: Select Variable Type</H2>
<form id='var' enctype='multipart/form-data'>
<span style='float: left; margin-top:8px;'>
...
<input id='controlimage' type='file' name='controlimage'>
</span>
<?php
// continue writing PHP here
Send PHP is a nonsens cause PHP is a Server side language (run on server and not on the client, the browser).
Why don't you run your PHP code in this script and return the result. (Just display it)
But, please, make us proud of our favorite language and its beginners:
Use mysqli_fetch_assoc() instead of mysqli_fetch_array()
Use only one echo to do a multiline display, PHP natively supports it.
Indent your code, you will really like how it's more readable.
Use jQuery, its AJAX methods and autocomplete widget. Somebody did the job for you. ;-)

php search result images show across and fill a CSS div

I'm using dreamweaver and php to return a list of images based on search critiera.
I have used Dreamweaver's repeat function and can get the images to repeat below each other (as below).
<table width="100" height="38" border="1">
<?php do { ?>
<tr>
<td width="38">
<img class='example' src="images/<?php echo $row_getresult['image_name']; ?>.png"/><br>
</a></td></tr>
<?php } while ($row_getamenityaccommodation = mysql_fetch_assoc($getamenityaccommodation));
?>
</table>
How can I get the images to go across from each other within a CSS Div e.g. float:left; width:45%; so that if there are more images than what would fit in 45%, the images would continue onto a new line?
Would somehow 'printing' the array work?
Remove the table and replace with
<div style='width:45%'>
<?php do{ ?>
<img style='float:left;class='example' src="images/<?php echo $row_getresult['image_name']; ?>.png"/>
<?php } while ($row_getamenityaccommodation = mysql_fetch_assoc($getamenityaccommodation)); ?>
</div>
or for a more semantic version use a ul since you are showing a list of images.
<ul class='gallery'>
<?php do{ ?>
<li><img style='float:left;class='example' src="images/<?php echo $row_getresult['image_name']; ?>.png"/></li>
<?php } while ($row_getamenityaccommodation = mysql_fetch_assoc($getamenityaccommodation)); ?>
</ul>
and in css
ul.gallery {
width: 45%;
list-style: none;
margin:0; padding:0;
}
ul.gallery li {
float:left;
padding: 5px;
}

How can i change the font color of a variable in PHP inside echo

echo $display;
so we know the default color is black. But i want to change it to white. Tried codes such as
"<div style=\"color: white;\">$display</div>";
but it doesn't work. Can you help me with this guys? thanks in advance.
<?php
$Color = "red";
$Text = "This text is red";
echo '<div style="Color:'.$Color.'">'.$Text.'</div>';
?>
In php, you can use . to add variables together. In this case, the final output of the echo line is:
<div style="Color:red">This text is red</div>
An example of this code in use can be seen here.
<span style="color:white;"><?php echo $display; ?></span>
Hope it might help.
<?php
$yourtext = "Some text";
?>
<div style="color:<?php echo ((#$_GET["color"]) && !empty(#$_GET["color"])) ? $_GET["color"] : "black"; ?>" ><?php echo $yourtext; ?></div>
In Url http://yoursite.you/yourpage.php?color=white
Green
Yellow
Blue
etc...
If applied color doesn't work even inline-style, so you can use !important word, cos maybe all div colors come from css file and suppress inline-styles.
"<div style=\"color: white !important;\">$display</div>";
If you have a div and you want to change its text and color of text, then simply copy and paste this code it will work for you.
echo "<script type='text/javascript'>";
echo"var ele= document.getElementById('login_status');
ele.innerHTML ='* Your <font color=#ff3322> Email </font> is incorrect ';";
echo "</script>";
I know this is an old question but I write the answer in case someone has the same question and does not know where to look. I think you wanted to print links so this is why the previous methods didn't work.Inside your php file write the following:
echo "<html>
<head>
<style>
/* unvisited link */
a:link {
color: red;
}
/* visited link */
a:visited {
color: green;
}
/* mouse over link */
a:hover {
color: hotpink;
}
/* selected link */
a:active {
color: blue;
}
</style>
</head>
<body>
$variableYouWantToChangeColor
</body>
</html>";
You can change/remove parts of the css so it fits your needs.
its usable with bootstrap
<p class="text-primary"><?php echo $distance; ?></p>
i found that when i try echo result from a calculation
<p class="text-primary"><?php echo round ($distance,2); ?></p>

Categories