I am trying to echo into a div but I am getting following error:
Notice: Undefined index: count on $SESSION['count']
when $SESSION['error'] is triggered, I am getting following error:
Undefined index: count on $SESSION['error']
when $SESSION['count'] is triggered, I am getting the similar error as above.
Here is the code in PHP.
<?php
if(isset($_SESSION['error'])){
} else {
foreach($_SESSION['search_output'] as $value){
$value['links'];
$value['title'];
$value['page_body'];
$title = $value['title'];
$link = $value['links'];
$body = $value['page_body'];
$search_output .= "<a href='".$link."'>".$title."</a> - $body<br><br>";}
}
?>
<div id="topResult">
<?php echo $_SESSION['error']; unset($_SESSION['error']);?>
<?php echo ($_SESSION['count']); unset($_SESSION['count']);?>
</div>
<div id="searchBox"><?php echo $search_output; ?></div>
Can't i just echo out the results like the $search_output variable?
Use
<?php if(isset($_SESSION['error'])) {echo $_SESSION['error']; unset($_SESSION['error']);} ?>
<?php if(isset($_SESSION['count'])) {echo ($_SESSION['count']); unset($_SESSION['count']);} ?>
Related
I'm having a problem with PHP code. I got some code from an e-book, but when I tried to run the system, it's giving some errors. I fixed some of the errors by giving proper quotation marks, but now I'm stuck with some other errors.
I'd be more than happy if someone helps me with the following error:
Warning: Undefined array key "Item_ID" in C:\xampp\htdocs\eCommerce\order.php on line 13
This is my code for order.php:
<?php
ob_start();
session_start();
if (isset ($_SESSION['Username'])){
$pageTitle ='Order';
include 'init.php';
?>
<div class="container">
<div class="row">
<?php
$Allitem = getAllFrom('items','Item_ID');
if ($_GET['Item_ID']){
foreach($Allitem as $item){
echo '<div class="col-sm-6 col-md-4">';
echo '<div class="thumbnail item-box">';
echo '<span class="price-tag">$ ' . $item['Price'] . '</span>';
echo ' <img class="img-responsive" src="../eCommerce/admin/layout/images/'. $item['Image'].' " alt="No Image Uploaded" />';
echo '<div class="caption">';
echo '<h3 class="items-name">'.$item['Name'] .'</h3>';
echo '</div>';
echo '</div>';
echo '</div>';
}
}
}
?>
</div>
<?php
include $tpl .'footer.php';
ob_end_flush();
?>
You are calling the index which is not in you $_GET parameters. You have to verify that the parameter is present or not. For this you have to change your if condition from
if($_GET['Item_ID']){
....
}
to
if(isset($_GET['Item_ID'])){
....
}
this will verify that the required parameter is present or not
I've been racking my brain for weeks trying to remove this block of code, it's from paid memberships pro plugin.
I need to remove the below section as it produces the file fields on the user profile.
need to remove it and put it in a loop of its own and then print it, as I need it to be in a separate <section> from the rest of the fields that are in that original loop.
//----Trying to remove this piece of code----//
?>
<strong><?php echo $field[0]; ?></strong>
<div class="Test"><?php echo pmpromd_display_file_field($meta_field); ?></div>
<?php
//---This is the FullSnippet with the above code included----//
if(!empty($fields_array))
{
foreach($fields_array as $field)
{
if(empty($field[0]))
break;
// Fix for a trailing space in the 'fields' shortcode attribute.
if ( $field[0] === ' ' ) {
break;
}
$field_val = $field[1];
$meta_field = $pu->$field_val;
if(!empty($meta_field))
{
?>
<section class="pmpro_member_directory_<?php echo esc_attr($field[1]); ?>">
<?php
if(is_array($meta_field) && !empty($meta_field['filename']) )
{
//this is a file field
?>
<strong><?php echo $field[0]; ?></strong>
<div class="brendan"><?php echo pmpromd_display_file_field($meta_field); ?></div>
<?php
}elseif(is_array($meta_field)){
//this is a general array, check for Register Helper options first
if(!empty($rh_fields[$field[1]])) {
foreach($meta_field as $key => $value)
$meta_field[$key] = $rh_fields[$field[1]][$value];
}
?>
<strong><?php echo $field[0]; ?></strong>
<ul class="servicesList"><?php echo '<li>'.implode("</li>\n<li>",$meta_field).'</li>';?></ul>
<?php
}
elseif(!empty($rh_fields[$field[1]]) && is_array($rh_fields[$field[1]]) )
{
?>
<strong><?php echo $field[0]; ?></strong>
<?php echo $rh_fields[$field[1]][$meta_field]; ?>
<?php
}
else
{
if($field[1] == 'user_url')
{
?>
<?php echo $field[0]; ?>
<?php
}
else
{
?>
<strong><?php echo $field[0]; ?></strong>
<?php
$meta_field_embed = wp_oembed_get($meta_field);
if(!empty($meta_field_embed)){
echo $meta_field_embed;
}else{
echo make_clickable($meta_field);
}
?>
<?php
}
}
?>
</section>
<?php
}
}
}
?>
I get the following PHP Notice in my opencart log file.
Undefined variable: http_type in /home/AAA/public_html/vqmod/vqcache/vq2-catalog_view_theme_template_product_product.tpl on line 3
Here is what I have in my product.php file's few first few lines
<?php if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
$http_type = "https:";} else {$http_type = "http:";}
<!---THIS IS LINE 3---> ?>
<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?>
<div id="content"><?php echo $content_top; ?>
<div class="breadcrumb" xmlns:v="<?php echo $http_type;?>//rdf.data-vocabulary.org/#" id="brd-crumbs" >
<ul>
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li typeof="v:Breadcrumb">
<?php echo $breadcrumb['separator']; ?><a property="v:title" rel="v:url" href="<?php echo $breadcrumb['href']; ?>"><span><?php echo $breadcrumb['text']; ?></span></a></li>
<?php } ?>
</ul>
</div>
Any help is highly appreciated
Firstly, it's just a notice so I expect everything is working as you would expect.
The notice is generated because when the $http_type variable is echoed, it hasn't necessarily been set to anything. If you add $http_type = ''; before the initial if statement, that will get rid of the notice.
I'm not that good at php. What i have is a list of items looped with endforeach. What I want is that the first loop will have a class of col-lg-12 and from the second one that class will become col-lg-6. How can I achive that?
Here's the code:
<?php $firstLoop = true;
foreach( $network_value as $key => $value ){
if( $firstLoop ){
echo '<div class="col-lg-12">';
}
echo '<div class="col-lg-6">';
$firstLoop = false;
} ?>
^This is the code that I've tried, but it's not working how i wanted.
<?php if ($img): ?>
<img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="" />
<?php endif; ?>
<h4>
<div class="circle"><?php echo $datePublic = date('d M', strtotime($page->getCollectionDatePublic())); ?></div>
<br>
<a class="blogTitle" href="<?php echo $url ?>" target="<?php echo $target ?>"><?php echo $title ?></a></h4>
<h6>Posted by <?php echo $author; ?></h6>
<br>
<p><?php echo $description ?></p>
</div>
<?php endforeach; ?>
The most simple way to do it is to add a counter and check if it is the first value in the counter.
<?php
$counter = 0;
foreach( $network_value as $key => $value )
{
if($counter == 0){
echo '<div class="col-lg-12">';
} else {
echo '<div class="col-lg-6">';
}
$counter++;
}
?>
Also I want to add that there are two ways of using foreach and if-statements, but you are trying to mix them, which is wrong.
The first method is using brackets "{" and "}":
foreach($users as $user) {
// do things for each user
echo $user->name; // Example of writing out users name
}
And if-statement:
if(true) {
// do something
}
The second method is using "foreach(statement):" and "endforeach;"
foreach($users as $user):
// do things for each user
echo $user->name; // Example of writing out users name
endforeach;
And if-statement:
if(true):
// do something
endif;
Edited:
In your case you can use:
<?php
foreach ($pages as $key=>$page):
if($key==0){
echo '<div class="col-lg-12">';
} if($key==1){
echo '<div class="col-lg-6">';
}
endforeach; ?>
Or you can use:
<?php
foreach ($pages as $key=>$page):
if($key==0){
echo '<div class="col-lg-12">';
} else {
echo '<div class="col-lg-6">';
}
endforeach; ?>
OLD:
foreach($array as $key=>$row){
if($key==0){
echo '<div class="col-lg-12"></div>';
}
if($key==5){
echo '<div class="col-lg-6"></div>';
}
// OR try use %
if($key%2 == 0){
echo '<div class="col-lg-12"></div>';
} else {
echo '<div class="col-lg-12"></div>';
}
I am newer to PHP and I have a problem changing the resultDiv contents
if(mysql_num_rows($res)==0)
{
echo "<script>document.getElementById('resultDiv').innerHTML='No such flight';</script>";
// echo "<script>alert('No Such filght');</script>";
echo "No such flight";
}
else{
echo "<table border='1'><th>flight#</th><th>Dep. City</th><th>Arrival City</th><th>Dep. Date</th><th>Arrival Date</th><th>Total Seats</th>";
while($row=mysql_fetch_array($res))
echo "<tr><td>".$row['id']."</td><td>".$row['depCity']."</td><td>".$row['arrivCity']."</td><td>".$row['depDate'].
"</td><td>".$row['arrivDate']."</td><td>".$row['totalSeats']."</td></tr>";
echo "</table>";
}
</div>
<div id="resultDiv">
Result Div
</div>
Please avoid to use mysql_* function as it is deprecated in latest version. You can use mysqli or PDO.
You can display message like this :-
<?php
$message = (mysql_num_rows($res) == 0) ? 'No Such Flight' : '';
?>
<div id="resultDiv">
<?php echo $message;?>
</div>
You can do it like so:
<div id="resultDiv">
<?php
if (mysql_num_rows($res) == 0) {
echo "No such flight";
} else {
echo "Flight found";
}
?>
</div>
you have misspelled "resultDiv" in get element by id, also define the div before the if condition.
<div id="resultDiv">
Result Div
</div>
if(mysql_num_rows($res)==0)
{
echo "<script>document.getElementById('resultDiv').innerHTML='No such flight';</script>";
echo "No such flight";
}