I have an if statement that only has to show some code if the value of $result37 = ncrteam... but how can I echo that HTML and PHP code? echo" "; is not working and echo ' '; Is also not working.
This is my code:
<?php
if ($result37 === "ncrteam") {
?>
Status:<br>
<select class="form-control" name="status" style="width: 300px">
<?php
while ($row15 = mysqli_fetch_assoc($result15)):; ?>
<option selected value=\"<?php echo $row15['status'];?>\"><?php echo $row15['status'];?></option>
<?php endwhile;?>
<?php while ($row16 = mysqli_fetch_assoc($result16)):; ?>
<option value=\"<?php echo $row16['statusname'];?>\"><?php echo $row16['statusname'];?></option>
<?php endwhile;?>
</select>
<?php
}
?>
This is not a complete answer, because it is unclear what exactly you are trying to do, but your question looks something like How do I build html based on values of my php variables and I will try to answer it as best I can
With the limited information I have from your question, I think this is the kind of thing you are trying to do:
<?php
...
$html = "";
if ($result37 === "ncrteam") {
while ($row15 = mysqli_fetch_assoc($result15))
{
$html .= "<option value=".$row15['status'].">";
}
}
?>
<html>
<body>
...
<select>
<?php echo $html; ?>
</select>
...
</body>
</html>
Related
I am working on a script now i am facing the problem with tag.
my code is below. I don't know what's wrong with my code because my link is not working.
<select size="5" multiple="multiple" class="form-control">
<?php
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
extract($row);
?>
<p class="notice">
<?php
if($row['userPic']) { ?>
<option><?php echo $headline ?></option>
<?php }
else { ?>
<?php echo '<option>'.$headline.'</option>'; ?>
<?php } ?>
</p>
<?php
} ?> </select>
I'm trying to echo a list into a textarea (to allow for simple copy and paste), I've got the list echoing out as flat html and its appearing as it should but I'd like it to be inside a textarea, here's what I've done so far...
<?php
include (ABSPATH.'/connect_include.php');
$AvDates = "SELECT * FROM DB_Available_Dates";
$AvDates = mysql_query($AvDates) or die(mysql_error());
if(mysql_num_rows($AvDates) > 0){
?>
<input value=
<ul>
<?php
while ($row_AvDates = mysql_fetch_assoc($AvDates)){
?>
<li><?php echo htmlentities($row_AvDates['Month']).' - '. htmlentities ($row_AvDates['the_days']); ?></li>
<?php
}
?>
</ul> />
<?php
}
?>
This isn't working though - how can I make this work?
I guess this might help you:
<textarea>
<?php
$anyVar = "This\nis\na\nstring";
echo $anyVar;
?>
</textarea>
Update: Demo for your example
<?php
include (ABSPATH.'/connect_include.php');
$AvDates="SELECT * FROM DB_Available_Dates";
$AvDates=mysql_query($AvDates) or die(mysql_error());
if(mysql_num_rows($AvDates)>0)
{
?>
<textarea>
<?php
while ($row_AvDates=mysql_fetch_assoc($AvDates))
{
echo htmlentities($row_AvDates['Month']) . " - " . htmlentities ($row_AvDates['the_days']) . "\n";
}
?>
</textarea>
<?php
}
?>
I have a problem to show my database values into a select box.
Here is my code
<select name="bugsolver">
<?php
if(count($yourBugs) > 0)
{
foreach( $emails as $key=> $singleEmail)
{ ?>
<option value="<?=$singleEmail['email']?>" selected='selected'> <?php echo $singleEmail['email']?></option>";
<?php }
} ?>
</select>
Your code should look like this:
<select name="bugsolver">
<?php
if(count($yourBugs) > 0):
foreach( $emails as $key=> $singleEmail ):
?>
<option value="<?php echo $singleEmail['email']; ?>">
<?php echo $singleEmail['email']; ?>
</option>
<?php
endforeach;
endif;
?>
</select>
When your code is easy to read (at least for you) it's easier to find bugs. If above code still doesn't work, do var_dump($yourBugs) and var_dump($emails) to check if these values are properly set. You can have disabled short tags (<?=) or variables are just empty.
Your code seems be OK. Try to test for $emails instead $yourBugs to get more info:
<?php if (count($emails)) : // test if $emails have values ?>
<select name="bugsolver">
foreach( $emails as $key=> $singleEmail) { /* ... */ }
</select>
<?php else : ?>
There are no emails to select ($emails is empty)
<?php endif; ?>
This for each / if statement displays changes, and then right below it it displays the changes made.
I am trying to write an if statement that tells it not to show the h2 and the #change_box if there are no changes.
Help would be greatly appreciated.
<h2 class="changes"> Changes: </h2>
<div id="change_box">
<? foreach ($audit['Events'] as $event):?>
<?if ( $event['Type'] != 'Comment'):?>
<span class="field">
<?= $event['Field']?>
</span>:
<?= $event['Value'] ?>
<?=($event['Previous'])?>
<?endif?>
<?endforeach?>
</div>
<?php
if ($changes) { // You'll have to set this variable
//Echo all of your HTML
else {
//Echo the stuff you'd rather show if they didn't change anything
}
?>
To give you an idea of how I'd write your code
<?php
if ($changes) {
echo '<h2 class="changes">Changes:</h2>';
echo '<div id="change_box">';
foreach ($audit['Events'] as $event) {
if ($event['Type'] != 'Comment') {
echo $event['Field'] . </span> . $event['Value'] . $event['Previous'];
}
}
echo "</div>"
}
?>
You could wrap your code with an if like
if(count($audit['Events'])>0)
{
//Your code
}
Wny do you open and close php tags every time? Would be better to make everything in PHP and echo whenever you want to print HTML code.
<?php
echo "<h2 class=\"changes\"> Changes: </h2>";
echo "<div id=\"change_box\">";
foreach ($audit['Events'] as $event) {
if ( $event['Type'] != 'Comment') {
echo "<span class=\"field\">".$event['Field']."</span>";
echo $event['Value'];
echo "(".$event['Previous'] .")";
}
}
echo "</div>";
?>
please make space after each <? and make sure you enabled short tags
<?php if(is_array($audit['Events']) && $audit['Events']):?>
<h2 class="changes"> Changes: </h2>
<div id="change_box">
<?php foreach ($audit['Events'] as $event):?>
<?php if ( $event['Type'] != 'Comment'):?>
<span class="field">
<?php echo $event['Field'];?>
</span>:
<?php echo $event['Value']; ?>
<?php echo $event['Previous'];?>
<?php endif;?>
<?php endforeach;endif;?>
</div>
I am attempting following code to populate an UnOrdered List dynamically. The same type of code I am successfully using to populate a DropDown. But when I changed the tags to UnOrdered List, it is not working. When run, it just displays some tags instead of the actual output.
Where is the error:
<?php
require("dbconnection.php");
require("dbaccess.php");
$divName = $_GET['DivName'];
$ulName = $_GET['ControlName'];
$query = $_GET['SqlQuery'];
echo $query;exit;
dbconnection::OpenConnection();
$result = dbaccess::GetRows($query);
?>
<ul id="<?php echo $ulName; ?>" name="<?php echo $ulName; ?>">
<?php while($row=mysql_fetch_array($result))
{ ?>
<li><?php echo $row[1]; ?>"></li>
<?php } ?>
</ul>
The code that I used to populate a DropDown is below: It works absolutely fine:
<?php
require("dbconnection.php");
require("dbaccess.php");
$dropdownControlName = $_GET['DropDownControlName'];
$query = $_GET['SqlQuery'];
dbconnection::OpenConnection();
$result = dbaccess::GetRows($query);
?>
<select id="<?php echo $dropdownControlName; ?>" name="<?php echo $dropdownControlName; ?>">
<option>Select from the list</option>
<?php while($row=mysql_fetch_array($result))
{ ?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
<?php } ?>
</select>
The error is here:
<li><?php echo $row[1]; ?>"></li>
should be this:
<li><?php echo $row[1]; ?></li>
Don't know Php but what this line doing :
echo $query;exit;
Are you sure that you have to use the second field of the result set?
<li><?php echo $row[1]; ?>"></li>
There is an extra >" there.
Can you show us the resulting html code ?
SORRY: I was away from the PC for some minutes before posting, just saw that I answered the same as the following answer.
HI,
I used your code and gave some constant values and i got the following out put.
Out Put:
1">
2">
3">
4">
Used code:
`
">
`
and final Conclusion is, this prints the unordered list and i think yo may check your
echo $row[1]; part for any html out puts.
Note: "> This tag comes because of in your code having this value