Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have very small knowledge about PHP and HTML, so I need some help.
I'm trying to make my forum homepage (the gate) grid by getting images from the post, changing its size, and adding it to the page. For example:
Anyway, the code that i have is:
{else}
<?php $t= 0;?>
<table class="grid" border="0" width="100%" cellpadding="0" style="border-collapse: collapse" align="center">
<tr class="row">
{Des::while}{LastNews_subjectList}
<?php
if ($PowerBB->_CONF['info_row']['portal_columns'] == '1' )
{
$columns_News = "3";
}
else
{
$columns_News = "2";
}
if($t== $columns_News){
$t=0;
echo "</tr><tr>";
}?>
<td class="post-position" valign="top">
<table class="cell" border="1" width="100" class="border" cellpadding="0" style="border-collapse: collapse" align="center">
<tr>
<td class="rowthumb" valign="top">
<a href="index.php?page=topic&show=1&id={$LastNews_subjectList['id']}" title="<?php echo $title;?>">
<?php
$x = 1;
$images = array();
$PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'] = stripslashes($PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text']);
preg_match_all('/src=([\'"])?((?(1).*?|\S+))(?(1)\1)/', $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'], $images);
foreach ($images[2] as $src)
{
if($src)
{
echo '<img border="0" width="200" height="200" src="'.$src.'" alt="'.$PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['title'].'">';
}
break;
}
if(!preg_match_all('/src=([\'"])?((?(1).*?|\S+))(?(1)\1)/', $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'], $images))
{
echo '<img border="0" width="200" height="200" src="look/portal/images/traffic_cone.png" alt="'.$PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['title'].'">';
}
?>
</a>
</td>
</tr>
<tr>
<td class="cell-title" valign="top">
<?php
$PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['title'] = $PowerBB->Powerparse->censor_words($PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['title']);
$title = $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['title'];
$num = "20";
$title = $PowerBB->functions->words_count($title,$num);?>
<?php echo $title;?>
<br />
<a href="index.php?page=topic&show=1&id={$LastNews_subjectList['id']}" title="Read More">
<div id="read_more_button">
{$lang['SubjectVisitor']}:
({$LastNews_subjectList['visitor']})
{$lang['usercp_reputations']}:
({$LastNews_subjectList['rating']})
</div>
</a>
</td>
</tr>
</table> <br />
</td>
<?php $t= $t+1;?>
{/Des::while}
</tr>
</table>
{if {$PagerLastNews}}
<table border="1" width="100%" cellpadding="0" style="border-collapse: collapse"><tr>
<tr>
<td class="row3">
<span class="r-right">
{$PagerLastNews}
</span>
</td>
</tr>
</table>
So what do I have to do? I have tried several times and played around but I cant do it, so I hope I find the answer here.
Thanks in advance! goodbye.
Do not use table for this. If you want to reach the layout you attached as an image for example.
I do not know how you collect the images, but of course you need them.
This library can help you out with the grid thingie. I used that, so I know. It should help you out. It has examples too, how to implement it for your site.
Masonry - Cascading Grid Layout library
Because of the comment...
You get the images in a PHP array. Print them out. The result should be something like this:
<ul class="js-masonry" id="gallery-container">
<li class="grid-sizer"></li>
<li class="item">
<img alt="Test title 1" src="/cache/b/6/9/f/c/b69fcffb670eb78227c9f407bf7fcc4db94f4c13.jpeg" class="img-responsive">
</li>
<li class="item">
<img alt="Test title 23" src="/cache/c/1/f/0/0/c1f0045723688ac91a92ac9b49ea13c00bbb1683.jpeg" class="img-responsive">
</li>
<li class="item">
<img alt="Test title 2" src="/cache/5/1/7/1/a/5171a4e0264f19486a8033fffcf8e1a0e62d0587.jpeg" class="img-responsive">
</li>
</ul>
You download the js library. And include it:
(or use the CDN as i use here for dev...)
<script src="https://cdnjs.cloudflare.com/ajax/libs/masonry/3.3.0/masonry.pkgd.min.js" type="text/javascript"></script>
Then run the script, after the page downloads
<script type="text/javascript">
$(document).ready(function() {
var $container = $('#gallery-container').masonry();
$container.imagesLoaded( function() {
$container.masonry(
{
"columnWidth": ".grid-sizer",
"itemSelector": ".item",
"gutter":10
});
});
});
</script>
As you can see I used the imagesLoaded library also.
imagesLoaded
Related
Hi I have written code to delete a record (Just changing the status of the record from 1 to 0). Delete is working fine.
But the problem is, after deleting the record, it's not deleting immediately after I click on refresh button. it's removing the record from the list. This is the code which I have written for that.
Controller:
function index()
{
$data['records'] = $this->career_model->get_jobs_list();
$data['mainpage']='career';
$data['mode']='all';
$this->load->view('templates/template',$data);
}
function delete()
{
$this->career_model->delete($this->uri->segment(3));
$this->flash->success('<h2>Successfully deleted the record.<h2>');
redirect('careers');
}
Model:
function get_jobs_list()
{
$this->db->Select('jobs_list.*');
$this->db->From('jobs_list');
$this->db->where(array('jobs_list.status'=>1));
$q=$this->db->get();
if($q->num_rows()>0)
{
return $q->result();
}
else
{
return false;
}
}
function delete($jobs_id)
{
$data=array('status'=>0);
$this->db->where(array('jobs_id'=>$jobs_id));
$this->db->update('jobs_list',$data);
}
View:
<div id="mydiv">
<?php echo $this->flash->display('success', TRUE);?>
</div>
<script>
setTimeout(function() {
$('#mydiv').hide('fast');
}, 10000);
</script>
<div id="main">
<div class="full_w">
<div class="h_title">
<div class="lefttitle fl">
Categories
</div>
<div class="rightbutton fr">
<a class="button add" href="<?php echo site_url()?>/careers/add">Add </a>
<a class="button del" href="<?php echo site_url()?>/careers/deactivated">Deactivated </a>
</div>
</div>
<table>
<thead>
<tr>
<th scope="col">S.No</th>
<th scope="col">Job List</th>
<th scope="col" style="width: 65px;">Modify</th>
</tr>
</thead>
<tbody>
<?php if(isset($records) && is_array($records) && count($records)>0): ?>
<?php $i=0;foreach($records as $r):$i++;?>
<tr>
<td class="align-center"><?php echo $i;?></td>
<td><?php echo $r->job_name;?></td>
<td>
</td>
</tr>
<?php endforeach ;endif;?>
</tbody>
</table>
</div>
</div>
<div class="clear"></div>
try redirect('/careers', 'refresh');
from the docs
The optional second parameter allows you to force a particular
redirection method. The available methods are auto, location and
refresh, with location being faster but less reliable on IIS servers.
The default is auto, which will attempt to intelligently choose the
method based on the server environment.
Try with adding single quote in the model get_jobs_list() function.
change $this->db->where(array('jobs_list.status'=>1)); to $this->db->where(array('jobs_list.status'=>'1'));
I just learning about simple_html_dom.php, I try to get only all the p attribute content in entry-content class and make it to one paragraph or one sentence.
here the raw html file from the website that i want to get the content.
<div class="entry-content">
<p><img class="alignnone" src="xxxxxxxxxxx" width="800" height="450" /></p>
<p>data1<span id="more-287848"></span></p>
<p>data2</p>
<p>data3</p>
<p>data4</p>
<p>......</p>
<p>......</p>
<p>dataN</p>
<div class="wpa wpmrec">
<a class="wpa-about" href="https://wordpress.com/about-these-ads/" rel="nofollow"></a>
<div class="u">
<script type='text/javascript'>
(function(g){g.__ATA.initAd({sectionId:34789711, width:300, height:250});})(window);
</script>
</div>
</div>
</div>
here my code to get it :
<?php
require_once __DIR__.'/simple_html_dom.php';
$html = new simple_html_dom();
$html->load_file('https://xxxxxxxxx');
$isi = $html->find('div[class="entry-content"]',0)->innertext;
?>
<table border="1">
<thead>
<tr>
<td><?php echo $isi; ?></td>
</tr>
</thead>
</table>
how to do it? thank you guys.
You should be able to iterate all of the <p> elements and adding the text to a variable. I have not tried this, but something like this:
$complete = "";
foreach($html->find('div.entry-content p') as $p)
{
$complete .= $p->plaintext;
echo $p->plaintext;
}
echo $complete;
There's a lot of information in the documentation here:
http://simplehtmldom.sourceforge.net/manual.htm
I have a problem with this page
the green go logo next to the image is meant to visit the promotions site saved on my database. But it loads the same page in a new tab.
My code for this is:
<img alt="" title="" src="GO.png" height="50" width="50" align="right" />
Any ideas why it does not work?
If you need any code for any of my pages then please let me know and I will edit this and add it.
Thanks.
HOW DO I HREF MY GO IMAGE TO A LINK SAVED UNDER promo_link IN MY DATABASE TABLE?
<?php
include_once('include/connection.php');
include_once('include/article.php');
$article = new article;
**if(isset($_GET['id'])) {
$id = $_GET['id'];
$data = $article->fetch_data($id);**
$articles = $article->fetch_all();
?>
<html>
<head>
<title>xclo mobi</title>
<link rel="stylesheet" href="other.css" />
</head>
<body>
<?php include_once('header.php'); ?>
<div class="container">
Category = ???
<?php foreach ($articles as $article) {
if ($article['promo_cat'] === $_GET['id']) { ?>
<div class="border">
<a href="single.php?id=<?php echo $article['promo_title']; ?>" style="text-decoration: none">
<img src="<?php echo $article['promo_image']; ?>" border="0" class="img" align="left"><br />
**<img alt="" title="" src="GO.png" height="50" width="50" align="right" />**
<br /><br /><br /><br />
<font class="title"><em><center><?php echo $article['promo_title']; ?></center></em></font>
<br /><br />
<font class="content"><em><center><?php echo $article['promo_content']; ?></center></em></font>
</div><br/><br />
</a>
<?php } } } ?>
</div>
<?php include_once('footer.php'); ?>
</body>
</html>
Your href attribute is empty and because you're using target="_blank" clicking on the link will open the same page in a different tab.
The $data['promo_link'] is empty. I can't tell why because there is no code.
Edit
It seems you forgot the brackets
replace $article = new article; with $article = new article();
also $article->fetch_data($id) is probably returning an empty value.
As I can see, your id value is "FREE". make sure that article->fetch_data("FREE") returns what you expecting it to return.
I also suggest changing you code style.
This is much more easy to read:
if ($param){
echo '<div>' . $data["bla"] . '</div>';
}
mixing your PHP code and yout HTML code makes it hard to read and understand.
Note: <font class="title"><em><center><?php echo $article['promo_title']; ?></center></em></font> is deprecated. Use CSS:
HTML/PHP code:
echo '<div class="title">' . $article['promo_title'] . '</div>';
And the CSS:
.title{
text-align: center;
font-size: 1.5em;
}
I've got a new online store written in PHP and MySQL.
<div class="content-area">
<div class="page-heading">
<h1>Store</h1>
</div>
<p style="padding-top: 5px;"><strong>You are here:</strong> Home ยป Store</p>
<table border="0" cellpadding="0" cellspacing="0" width="500">
<?php
$categories=mysql_query("SELECT * FROM categories WHERE parent='0' ORDER by owner ASC, title ASC");
while($categoriesRow=mysql_fetch_array($categories)) {
$categoriesSub=mysql_query("SELECT * FROM categories WHERE parent='$categoriesRow[id]'");
?>
<tr>
<td valign="top">
<div class="product_list">
<div class="image_product">
<img alt="<?php echo $categoriesRow['title']; ?>" src="<?php echo $cls->truska(true); ?>/theme_section_image.gif" border="0" style="vertical-align: middle;" />
</div>
<div>
<h3 class="product"><?php echo $categoriesRow['title']; ?> <?php if(mysql_num_rows($categoriesSub) > 0) { ?>(<?php while($categoriesSubRow=mysql_fetch_array($categoriesSub)) { }?>)<?php } ?></h3>
</div>
</div>
</td>
</tr>
<tr>
<td class="dotted_line_blue" colspan="1">
<img src="<?php echo $cls->truska(true); ?>/theme_shim.gif" height="1" width="1" alt=" " />
</td>
</tr>
<?php
}
?>
</table>
</div>
Where my second While loop is, I need to work out what is the last result, so I can omit a comma from my while loop.
It will show as 'Lego (Lego City, Lego Starwars,)' but I want it to show as 'Lego (Lego City, Lego Starwars)'.
How can I get if the current result is the last?
You can fix this by coming at it from the other direction.
Instead of appending a comma after each result except the last, try pre-pending a comma on every result except the first.
Set up a variable called $first outside your loop, and set it to 1. Inside the loop:
if ($first == 0) {
echo ",";
} else {
$first = 0;
}
don't add the comma if it is the first result, and add it before in all the next ones.
Just build your array of results and implode it. This takes care of any counting automatically:
$comma_separated = implode(",", $array);
You shouldn't use plain mysql access, look at PDO.
Answering your question, try something like this:
$items = array();
while ($row = mysql_fetch_assoc($result)) {
$items[] = $row['foo'];
}
echo implode(', ', $items);
I've tried making my hole tr tag to be clickable so I made this code
<?php foreach ($data['forums'] as $forum): ?>
<?php #var_dump($forum); ?>
<tr class="fix head">
<th class="fix ltext"><strong><?php echo $forum['name'] ?></strong></th>
<th class="fix rtext"><strong>Trending</strong></th>
<th class="fix ltext"><strong>Latest Post</strong></th>
</tr>
<?php foreach ($forum['children'] as $child): ?>
<?php #var_dump($child); ?>
<tr class="fix">
<a href="#">
<td class="fix ltext cl">
<strong><?php echo $child['name']; ?></strong>
<p><?php echo $child['description_html']; ?></p>
</td>
<td class="fix rtext cr">1423</td>
</a>
<td class="fix ltext cr cl">
tanya jawab sesuatu by <a class="u" href="#">=awdwad</a>
</td>
</tr>
<?php endforeach ?>
<?php endforeach ?>
on the view
The problem is
The link should be just above the highlighted part and below it. How could it be above far away, below my body tag?
Does ayone have any experience that could possibly generate this error?
Well, you've put the a tag where it's not allowed, so any browser's answer is legitimate. You should put an a into each td. Perhaps, you may alternatively handle click event for tr element, but that would require javascript.
The problem is that that is an invalid place for an <a>. No DTD will allow what you have tried to do.
Your approach is all wrong. You have to use Javascript to make a whole <tr> clickable. AFAIK, there is no way to do this in any HTML variant alone.
Try something like this:
<table>
<tr id="my_clickable_tr">
<td>Stuff</td>
<td>Stuff</td>
<td>Stuff</td>
</tr>
<!-- More table stuff -->
</table>
<script type="text/javascript">
document.getElementById('my_clickable_tr').onclick = function () {
window.location.href = 'http://wherever.you.want/to/send/the.clicker';
};
</script>
Anchor tags (a) are not allowed as children of table row (tr) tags, see the documentation here. Only table header (th) and table data (td) tags are allowed.