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.
Related
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'm running into a strange scenario involving a widget and the lay-out. I've created a layout that overrides the original column 2 lay-out. It calls a widget in the file and in that widget display a table on the side-bar of some information that I would like to show the user. The layout sidetable.php looks like this
<?php $this->beginContent('//layouts/main'); ?>
<div class="row-fluid">
<div class="span3">
<?php
$this->widget('ListSummaryWidget', array('totaldue'=>$totaldue));
?>
<table class="table">
</table>
</div><!-- sidebar span3 -->
<div class="span9">
<div class="main">
<?php echo $content; ?>
</div><!-- content -->
</div>
</div>
<?php $this->endContent(); ?>
Now all this works - displaying a datatable on the left hand column of the screen. However, something strange happens. Whenever I git rid of
<table class="table">
</table>
The whole view breaks - showing a ridiculous structure/layout that doesn't look much at all like the original. This is confusing/intriguing. In my widget I declare the exact same table and yet it does not seem to matter that I declare this table. Here is the code for my widget's view
<table class="table list_summary table-bordered">
<form action="<?php echo Yii::app()->createUrl('recipient/processpayment', array('id'=>$id)) ?>" method="post" >
<tr class="primary"><td> <h4>List Summary </h4> </td></tr>
<tr ><td>
<?php echo $numpeople; ?> Recipient(s)
</td></tr>
<tr ><td>
Total Due: <?php echo $totaldue ?> Rwf
</td></tr>
<tr> <td>
<h4> Mobile Money Accounts: </h4>
<?php
/*
foreach($accounts as $account)
{
echo $account->name; ?>: <?php echo $account->balance; ?> Rwf<br> <?php
}
*/
?>
</td> </tr>
<tr> <td>
<button class="btn btn-block btn-primary " type="submit">Pay Now</button> </td> </tr>
</td></tr>
</form>
Could anyone explain why this is happening? Though it's not the worst thing in the world - I'm really intrigued as to why I'm required to have some html when I have the same html in the widget's view.
Resolved:
I didn't end the table in my widget. I should have added at the end
</table>
I want to use a custom template system in my php application,
What I want is I want to keep away my php codes from design, I would like to use a tpl file for designs and a php file for php codes
I dont want to use any ready maid scripts. Can any one point out some links link or useful info how to build a php templating system to achieve this
Thank you
The way I do it is to create a template file(.tpl if you wish) and insert markers which will be replaced with str_replace in PHP. The code will look something like this:
For template.tpl file
<body>
<b>Something: </b> <!-- marker -->
</body>
For the PHP
$template = file_get_contents('template.tpl');
$some_data = 'Some Text'; //could be anything as long as the data is in a variable
$template = str_replace('<!-- marker -->', $some_data, $template);
echo $template;
That's it in a nutshell but it can get a lot more complex. The marker can be anything as long as it's unique.
I want to keep away my php codes from design, I would like to use a tpl file for designs
...and mix your tpl codes with "design"!
what's the difference then? :)
PHP itself is efficient templating system.
And nowadays most developers agreed that dividing your PHP code to business logic part and display logic part is most preferable way.
It can be very limited subset of PHP of course. You will need an output operator (<?=$var?>) one, a condition <? if(): ?>...<? endif ?>, a loop <? foreach(): ?>...<? endforeach ?> and include.
An example of such a template:
<table>
<? foreach ($data as $row): ?>
<tr>
<td><b><?=$row['name'] ?></td>
<td><?=$row['date'] ?></td>
</tr>
<tr>
<td colspan=2><?=$row['body'] ?></td>
</tr>
<? if ($row['answer']): ?>
<tr>
<td colspan=2 valign="top">
<table>
<tr>
<td valign="top"><b>Answer: </b></td>
<td><?=$row['answer'] ?></td>
</tr>
</table>
</td>
</tr>
<? endif ?>
<? if($admin): ?>
<tr>
<td colspan=2>
<? if($row['del']): ?>
show
<? else: ?>
hide
<? endif ?>
edit
</td>
</tr>
<? endif ?>
<? endforeach ?>
</table>
<?php
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=London');
$information = $xml->xpath("/xml_api_reply/weather/forecast_information");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
?>
<html>
<head>
<title>Google Weather API</title>
</head>
<body>
<h1><?php print $information[0]->city['data']; ?></h1>
<h2>Today's weather</h2>
<div class="weather">
<img src="<?php echo 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"?>
<span class="condition">
<?php echo round(conver_f_c($current[0]->temp_f['data'])); ?>° C,
<?php echo $current[0]->condition['data'] ?>
</span>
</div>
<h2>Forecast</h2>
<?php foreach ($forecast_list as $forecast) : ?>
<div class="weather">
<img src="<?php echo 'http://www.google.com' . $forecast->icon['data']?>" alt="weather"?>
<div><?php echo $forecast->day_of_week['data']; ?></div>
<span class="condition">
<?php echo round(conver_f_c($forecast->low['data'])); ?>° C - <?php echo round(conver_f_c($forecast->high['data'])); ?>° C,
<?php echo $forecast->condition['data'] ?>
</span>
</div>
<?php endforeach ?>
</body>
</html>
<?php
function conver_f_c($F){
return $C = ($F − 32) * 5/9;
}
I want Out somthing like this manner of the horizontal ,
Even i tried UL LI WITH display inline but it goes failed,
Tell me some good suggestion for my probme,
I want exactly like horizontal, expecting exactly like screen shot ,
Tell me How to render using php
Thanks
alt text http://img163.imageshack.us/img163/7518/weatherhori.jpg
Above snippet present display out verticly , i want o change that verticle to horizonatal ,
somthing like this screen shot
<table>...</table>
Update
From your latest comment so far:
i know how to fetch array and display
it, but i dont know to fetch and
display in the verticl manner that is
the stuck up
I feel this is going to be a stupid answer but it appears to be what you don't understand...
The web is based in a markup language called HTML. This language has tags (delimited by angle-brackets) that allow you to define the structure of a document. On top of this, you have another language called CSS. This other lang allow you to define how HTML is going to be displayed on screen.
You may argue that you already have a web page and you've written it with the PHP language instead of the two other langs I've mentioned. That's not enterely true: you code in PHP, sure, but you use PHP to generate HTML. And it's HTML what finally reaches the browser (Firefox, Explorer...). PHP is executed in the web server, not in the browser. The browser can only see whatever HTML you've generated.
To sum up: you have to forget about PHP, Google and the whole weather thingy. You first need to write a static HTML document and style it with CSS. Once you've done with it, you can finally replace the parts of the information that are dynamic with values taken from your PHP variables.
And since you seem to need a table to display tabular data, the appropriate HTML tag is <table>:
<table>
<tr>
<th>Web</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
</tr>
<tr>
<td><img src="/path/to/pics/cloudy.png" width="25" height="25" alt="Cloudy"></td>
<td><img src="/path/to/pics/sunny.png" width="25" height="25" alt="Sunny"></td>
<td><img src="/path/to/pics/rainy.png" width="25" height="25" alt="Rainy"></td>
<td><img src="/path/to/pics/cloudy.png" width="25" height="25" alt="Cloudy"></td>
</tr>
<tr>
<td>26ºC</td>
<td>26ºC</td>
<td>22ºC</td>
<td>25ºC</td>
</tr>
<table>
I suggest you find some tutorials about basic HTML and CSS. They'll be of invaluable help.
This is what's done by Google :
http://jsfiddle.net/bW8NA/1
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
When mixing PHP and HTML, what is the proper indentation style to use? Do I indent so that the outputted HTML has correct indentation, or so that the PHP/HTML mix looks properly formatted (and is thus easier to read)?
For example, say I have a foreach loop outputting table rows. Which one below is correct?
PHP/HTML mix looks correct:
<table>
<?php foreach ($rows as $row): ?>
<tr>
<?php if ($row->foo()): ?>
<?php echo $row ?>
<?php else: ?>
Something else
<?php endif ?>
</tr>
<?php endforeach ?>
</table>
Outputted HTML looks correct:
<table>
<?php foreach ($rows as $row): ?>
<tr>
<?php if ($row->foo()): ?>
<?php echo $row ?>
<?php else: ?>
Something else
<?php endif ?>
</tr>
<?php endforeach ?>
</table>
I've found that when I run into this situation (quite frequently), I don't have a standard style to use. I know that there may not be a "correct" answer, but I'd love to hear thoughts from other developers.
The PHP and the HTML should each be indented so that they are correct with respect to themselves in source form, irrespective of each other and of outputted form:
<table>
<?php foreach ($rows as $row): ?>
<tr>
<?php if ($row->foo()): ?>
<?php echo $row ?>
<?php else: ?>
Something else
<?php endif ?>
</tr>
<?php endforeach ?>
</table>
I often pondered this question too, but then I realized, who cares what the HTML output looks like? Your users shouldn't be looking at your HTML anyway. It's for YOU to read, and maybe a couple other developers. Keep the source code as clean as possible and forget about what the output looks like.
If you need to debug the output, use Chrome Developer Tools, Firebug, or even F12 Tools.
I generally put opening php tags at the beginning of the line, but indent whatever is inside the tags to match the html formatting. I don't do this, however, for simple echo statements since I use short-open tags. I think it makes simpler it when browsing through the file to find all the declarations.
<table>
<? foreach ($foo as $bar): ?>
<tr>
<? foreach ($bar as $baz): ?>
<td><?=$baz?></td>
<? endforeach ?>
</tr>
<? endforeach ?>
</table>
Direct answer to your question: If you need to read the HTML output often, it might be a good thing to output well indented HTML. But the more common case will be that you need to read your php source code, so it is more important that the source is easily readable.
Alternative to the two options you mentioned: See chaos' or tj111's answer.
Better still in my opinion: Don't mix HTML and php, use a template engine instead.
You can always use a bit of whitespace too to help readability. Building on chaos' indentation:
<table>
<?php foreach ($rows as $row): ?>
<tr>
<?php if ($row->foo()): ?>
<?php echo $row ?>
<?php else: ?>
Something else
<?php endif ?>
</tr>
<?php endforeach ?>
</table
The only downside with this is if you have a lot of mixed code it can make your document twice as long, which makes for more scrolling. Although if you have this much mixed code you may want to consider a templating engine.
You should not be bothered about markup indentation in the production environment. Neither should you use Tidy or other HTML purifiers. There are valid use cases, e.g. when you allow HTML input (but consider using Markdown instead), though these are rare.
Most often HTML beautifiers-filters are abused to hide the underlying issues with the code. Don't. Correct your markup manually.
If you need to indent your code only in the development environment, you can use either of the above. However, beware that these libraries will attempt to fix your markup (that's their primary purpose; indentation is a by-product). I've written Regular Expression based indentation tool Dindent.
Dindent will convert markup like this:
<!DOCTYPE html>
<html>
<head></head>
<body>
<script>
console.log('te> <st');
function () {
test; <!-- <a> -->
}
</script>
<div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<div><table border="1" style="background-color: red;"><tr><td>A cell test!</td>
<td colspan="2" rowspan="2"><table border="1" style="background-color: green;"><tr> <td>Cell</td><td colspan="2" rowspan="2"></td></tr><tr>
<td><input><input><input></td></tr><tr><td>Cell</td><td>Cell</td><td>Ce
ll</td></tr></table></td></tr><tr><td>Test <span>Ce ll</span></td></tr><tr><td>Cell</td><td>Cell</td><td>Cell</td></tr></table></div></div>
</body>
</html>
To this:
<!DOCTYPE html>
<html>
<head></head>
<body>
<script>
console.log('te> <st');
function () {
test; <!-- <a> -->
}
</script>
<div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<div>
<table border="1" style="background-color: red;">
<tr>
<td>A cell test!</td>
<td colspan="2" rowspan="2">
<table border="1" style="background-color: green;">
<tr>
<td>Cell</td>
<td colspan="2" rowspan="2"></td>
</tr>
<tr>
<td>
<input>
<input>
<input>
</td>
</tr>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Ce ll</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>Test <span>Ce ll</span></td>
</tr>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
</table>
</div>
</div>
</body>
</html>
Dindent will not attempt to sanitise or otherwise interfere with your code beyond adding indentation. This is to make your development/debugging easier. Not for production.