This error makes no sense. Here is the code block and my explanation below.
<?php foreach($rows as $value): ?>
<?php echo $value['authorname'] . "<br />\n";?>
<?php echo $value['title'] . "<br />\n";?>
<?php echo $value['rating'] . "<br />\n";?>
<?php echo $value['imagelocation'] . "<br />\n";?>
<div class="block">
<div class="row">
<div class="col-md-4 col-md-8">
<div class="widget-block">
<input id="rate1" value="<?php echo $value['rating'];?>" type="number" class="rating" data-max="5" data-min="0" data-size="sm" data-show-clear="false" readOnly="readOnly">
<img class="img-responsive wow fadeInLeftBig animated" data-wow-duration="1.5s" src=<?php echo $value['$imagelocation'];?> alt=<?php echo $value['$authorname'];?>>
<br>
Buy this book
</div>
</div>
<div class="col-md-6 col-md-8">
<div class="section-sub-title">
<article class="section-title-body white">
<h1 class="head-title">Author: <span><?php echo $value['$authorname'];?> -</span> <?php echo $value['$title'];?></h1>
<span class="point-line hidden-xs hidden-sm"></span>
<p>
<?php echo $value['$review'];?>
</p>
</article>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
The echo statements right after the start of the foreach loop prints out each variable fine. It isn't until we get down to the html that there are issues.
This code feeds an array of data from a DB then builds blocks of html code depending on the amount of data. In this case, I am pulling 8 records so this loop creates 8 copies of this code block. The thing that is frustrating is the variable "$rating" injects in all 8 blocks but none of the other variables do even though they print correctly on the page in the echo statements.
Maybe it is the data in the variable? For example as the code is parsed the first variable evaluated is $rating and works. The next one is the src property in the img tag $imagelocation and has an actual value of img\book_covers\TrueConviction.jpg
Are _ and . special characters and causing the issue? My return values would have _ . \ and spaces.
Thanks for any help.
I was right that it was the data IN the variables. The answer was urldecode. This solved my problems. I did this to all my variables.
$cleanauthorname = urldecode($value['authorname']);?>
Related
How to give the content of $topic_image to a variable like this at the source part?
The problem is here: --> src="image/<?php echo $topi_image?>" .
$display_content=<<<END_OF_TEXT
<div>
<img src="image/<?php echo $topic_image ?>" style="width:200px;height:150px;">
<p style="float:left">$topic_pris</p>
<p style="float:left">$topic_title</p>
<p style="float:left">$topic_name</p>
</div>
END_OF_TEXT;
Heredoc expands variables itself. You don't need the whole <?php echo $topic_image ?>, just the variable:
$display_content=<<<END_OF_TEXT
<div>
<img src="image/${topic_image}" style="width:200px;height:150px;">
<p style="float:left">$topic_pris</p>
<p style="float:left">$topic_title</p>
<p style="float:left">$topic_name</p>
</div>
END_OF_TEXT;
I returning my data to build a list group. All is fine but when the data contains <pre> tag it messes my display.
My list group as follows.
if (isset($BS_array)){
//Create a list group to show results
echo '<div class="list-group">';
foreach($BS_array as $result){
?>
<!-- Build list group -->
<div class="list-group-item list-group-item-action" aria-current="true">
<div class="d-flex w-100 justify-content-between">
<!-- Incident number goes here -->
<h5 style="cursor: pointer;" id="<?php echo $result['number']; ?>" onclick="getINCDetails(this.id)" class="mb-1"><?php echo $result['number']; ?></h5>
</div>
<!-- Description goes here -->
<p class="mb-1"><?php echo $result['description']; ?></p>
<small>
<?php
//List BS in INC card
echo $result['state'];
?>
</small>
</div>
<?php
}
echo '</div>';
}
?>
The way when all goes ok should be like this.
But at times, $result['description'], contains the word <pre>, which messes things up.
It will look like this.
How do I fix/circumvent this problem?
If you dont require html tags to actually work on the description just use htmlentities():
<?php echo htmlentities($result['description']); ?>
That will actually show instead of the browser considering it html tag.
Issue
I'm currently attempting to create a "cell" for each mysql row similar to how twitter has it, but for some reason i'm logging
PHP Parse error: parse error, expecting `','' or `';''
Code
I'm fairly new to PHP I am unsure of why my code is creating this error.
<?php
while ($row = mysql_fetch_array($rs)) {
$unformatted = $row['mcap_HKD'];
$output = number_format($unformatted);
$time = time_elapsed_string($row['time']);
echo
"<div class="content">
<div class="headers">
<div class="info">
<strong class="scode">".$row['scode']."</strong><br>
<span class="sname">".$row['sname']."</span><br>
<span class="industry">".$row['main_industry']."</span>
</div>
<small class="time">."$time."</small>
</div>
<div class="news">
".$row['title']."
</div>
</div>";
}
I know that through testing that I am able to reach the server and that it will output the data just fine on its own, and even when i output single variables onto one div, but for some reason this is not working when i put extra divs like i do above. I have attempted to echo each line by itself but it still returns the same error.
Issue
PHP use " as a string delimiter (it has several string delimiters). When, in you echo statement, you are not escaping the ", it's as if you stop the string. So PHP is waiting for a string concatenation . or , or the ; end of statement character.
Resolution
You must escape " characters in you echo statement as such: \" ; it should look like:
Escape string delimiters
echo
"<div class=\"content\">
<div class=\"headers\">
<div class=\"info\">
<strong class=\"scode\">".$row['scode']."</strong><br>
<span class=\"sname\">".$row['sname']."</span><br>
<span class=\"industry\">".$row['main_industry']."</span>
</div>
<small class=\"time\">."$time."</small>
</div>
<div class=\"news\">
".$row['title']."
</div>
</div>";
Mix HTML and PHP
or do something like:
<?php while ($row = mysql_fetch_array($rs)): ?>
<?php
$unformatted = $row['mcap_HKD'];
$output = number_format($unformatted);
$time = time_elapsed_string($row['time']);
?>
<div class="content">
<div class="headers">
<div class="info">
<strong class="scode"><?= $row['scode']; ?></strong><br>
<span class="sname"><?= $row['sname']; ?></span><br>
<span class="industry"><?= $row['main_industry']; ?></span>
</div>
<small class="time"><?= $time; ?></small>
</div>
<div class="news">
<?= $row['title']; ?>
</div>
</div>
<?php endwhile; ?>
This has the benefit to not use PHP to print HTML tags, and with the <?= PHP opening tags, it's more readable!
I hope this helps you! :)
This is my code in the php file. excontent is an array, $rebuild is a string.
<div class="about-hero">
<h2><span class="accel"><?php echo $excontent[0] . " "; ?></span><?php echo $rebuild; ?> </h2>
</div>
This is what I get when I inspect the element:
<div class="about-hero">
<h2>
<span class="accel">
<p>
"Accelerate is a marketing agency located in NYC. A great blah blah blah."
</p>
</span>
</h2>
</div>
Any ideas why its putting in a p tag??? Its something with the PHP and I'm new to PHP. I tried it with just strings and it works fine. I'm changing the color of the first word in a sentence (following the design) the rebuild is the rest of the sentence. They both echo fine on their own and show the correct content.
I'm assuming the <p> tag is on the $excontent[0] variable. In this case, you could try removing all HTML tags from it:
<div class="about-hero">
<h2><span class="accel"><?php echo strip_tags($excontent[0]) . " "; ?></span><?php echo $rebuild; ?> </h2>
</div>
Or removing just the trailing and leading <p> and </p>:
<div class="about-hero">
<h2><span class="accel"><?php echo substr(trim(substr(trim($excontent[0]), 3, strlen($excontent[0]))), 0, -4) . " "; ?></span><?php echo $rebuild; ?> </h2>
</div>
Your Browser will not "put" something into your HTML without any reason.
The first result of the Array is the place you should look at. You didn't provided your PHP Code, but im sure that result is where you find the <p> Tag ...
Just try this in JavaScript:
alert(<?PHP echo $excontent[0]; ?>);
I'm working on this (NSFW), I created 12 subpages but only 10 are showing in the list.
I'm not using any limit() or pagination() in the snippet nor in the panel config, I can't find where this limit is regulated. My guess is a numbering issue, because if in the panel I drag up the 11th subpage up, anything below will not be displayed.
Any clue?
php:
<section id="entries">
<ul>
<li>
<div class="line asger">
<div class="text">00</div>
<div class="text bold">Asger Carlsen</div>
</div>
</li>
<?php $n = 1; foreach($pages->children()->visible()->sortBy('date', 'asc') as $entries): ?>
<li>
<div class="line">
<div class="text">0<?php echo $n++; ?></div>
<div class="table"><div class="text bold"><?php echo kirbytext($entries->title()) ?></div></div>
<div class="text"><?php echo kirbytext($entries->kind()) ?></div>
</div>
<div class="description hidden">
<?php echo kirbytext($entries->description()) ?>
</div>
<div class="left-half">
<img class="images hidden" src="<?php echo $entries->images()->first()->url() ?>" alt="<?php echo html($entries->title()) ?>" />
</div>
</li>
<?php endforeach ?>
</ul>
</section>
Folder structure: https://www.dropbox.com/s/8gigspwup0kwqei/Screenshot%202014-09-03%2015.39.51.png?dl=0
Your folder-structure is defiantly correct. You only could try to rename 04-2001 to something like 04-foo2001 but i don`t think that this causes your issue.
I had some quite similar behavior once. It was caused by image-metadata txt's that had the same name like the page-content txt's. So maybe it would be helpful if you show us your complete folder-structure including the files/filenames.
Next idea: Are you sure you have no invalid markdown in your txt's?
PS: This should be a comment, but i’m at 49 reputation, so i’m not allowed to comment ;) cheers!
It was probably a combination of .txt name conflict plus a missing image from a page.