I am trying to do pagination for my forum. I am trying to get the results to show from the db, although everything is everywhere.
here is my code:
<!-- start with the table -->
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="53%" align="center" bgcolor="#E6E6E6" style="padding:5px;"><strong>Topic / Thread Starter</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6" style="padding:5px;"><strong>Replies/Views</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6" style="padding:5px;"><strong>Last Post By</strong></td>
</tr>
<div id="p1" class="pagedemo _current" style="">
<?php
$sql="SELECT * FROM forum ORDER BY datetime DESC";
$result=mysql_query($sql);
$i = 1;
$z = 1;
while($rows = mysql_fetch_array($result)){ // Start looping table row
if(($i % 4) != 0)
{ ?>
<tr>
<td bgcolor="#FFFFFF" style="padding:5px;"><a class="normal" href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><br /><span style="color:#666; font-size:12px;">Started By <?php echo "<a class='normal' href='http://www.example.com/view_profile.php?user=".getID($rows[username])."'>"; ?> <? echo $rows['username']; ?></a></span></td>
<td align="center" bgcolor="#FFFFFF">Replies: <? echo $rows['reply']; ?><br />Views: <? echo $rows['view']; ?></td>
<td align="center" background="http://example.com/images/forum_fade_bckg.png"><span style="color:#666; font-size:12px;">
<?php echo "<a class='normal' href='http://www.example.com/view_profile.php?user=".getID($rows[lastPoster])."'>"; ?> <?php echo $rows['lastPoster']; ?></a><br /><?php $date = substr($rows['datetime'],0,12);
if($date == date("M d, Y")) {
echo "Today, " . substr($rows['datetime'],-8);
} else {
echo $rows['datetime'];
}?> </span></td>
</tr>
<?php
// do whatever for the page... (this is inside the div)
$message = $row['message'];
echo $i . " " . $message. "<br>";
$i+=1;
}
else
{
$z+=1;
// GET ONLY NUMBERS HERE THAT ARE DIVISIBLE BY 4!!!!
// this is the end of the starting page, and the begining of the next page
echo '<br>---end---</div>
<div id="p'.$z.'" class="pagedemo" style="display:none;">---start---<br>NEXT PAGE!!!!!!!'; //
}
}
?>
</div>
The results, instead of staying in the div, are actually below the div. when I take out everything b/w the <tr> and </tr>, it all fits into the div. What am I doing wrong?
If you view the source of the page the issue should be apparent. I see a few mistakes that could be the problem.
The TABLE at the top of the snippet ends the TR tag then a DIV starts. A DIV should only reside within a TD, TH or outside the TABLE. Also in the snippet you provided there is no ending table tag. With all the other issues that is probably the one that is messing the browser up.
Please adjust structure to be similar to this:
<div>...</div>
<table>
<tr>
<td>Some tags in here(A, DIV, SPAN, etc.)</td>
</tr>
<tr>
<td>...</td>
<td>...</td>
</tr>
</table>
<div>...</div>
Also it would be worthwhile to migrate certain attributes to css properties in the style tag. For example the background, bgcolor, align, and width attributes in your snippet.
Sorry if that does not fix the issue its hard to debug without being able to see the issue.
Related
good day all,
since i'm new in Code Igniter 4 (i was a native PHP self-learner) and i'm new in MVC, my question is how can i show multiple tables in one page ?
i have a dashboard view with 2 tables inside. one is for display students data and the other is for teachers data. there is no relation between tables, so i can't join the tables.
i have successfully show one of the table (student or teacher) but i can't show both tables in dashboard at once. i think i have to pass 2 models into controller function but i just can't figure it out how to do it.
any help will be appreciated
here is parts of my codes (successfully showing data from 1 table) :
Controller
use App\Models\mStudent;
class Admin extends BaseController
{
public function index()
{
$model = new mStudent();
$data['title'] = 'Students';
$data['getStudents'] = $model->getStudents();
echo view('admin/header', $data);
echo view('admin/top_menu');
echo view('admin/side_menu');
echo view('admin/dashboard', $data);
echo view('admin/footer');
}
Model
public function getStudents()
{
return $this->findAll();
}
public function getTeachers()
{
return $this->findAll();
}
View
<!-- students table-->
<table class="table table-bordered text-sm">
<thead>
<tr>
<th style="width: 10px; text-align: center;">No</th>
<th style="text-align: center;">NAME</th>
<th style="text-align: center;">Class</th>
</tr>
</thead>
<tbody>
<?php $no = 1;
foreach ($getStudents as $students) { ?>
<tr>
<td><?= $no; ?></td>
<td><?= $students['name'] ?></td>
<td><?= $students['class'] ?></td>
</tr>
<?php $no++;
} ?>
</tbody>
</table>
<!-- teacher table-->
<table class="table table-bordered text-sm" id="defaulttable">
<thead>
<tr>
<th style="width: 10px; text-align: center;">No</th>
<th style="text-align: center;">NAME</th>
<th style="text-align: center;">ID</th>
</tr>
</thead>
<tbody>
<?php $no = 1;
foreach ($getTeachers as $teachers) { ?>
<tr>
<td><?= $no; ?></td>
<td><?= $teachers['name'] ?></td>
<td><?= $teachers['id'] ?></td>
</tr>
<?php $no++;
} ?>
</tbody>
</table>
Adding Dynamic Data to the View
In your Controller, right below $data['getStudents'] = $model->getStudents(); add:
$data['getTeachers'] = $model->getTeachers();
Addendum
Then in your model, return the respective result sets. I.e:
Model
public function getStudents()
{
return $this->db->table("students")->get()->getResultArray();
}
public function getTeachers()
{
return $this->db->table("teachers")->get()->getResultArray();
}
this is what i looking for
Controller
use App\Models\mStudent;
use App\Models\mTeacher;
class Admin extends BaseController
{
public function index()
{
$model_student = new mStudent();
$model_teacher = new mTeacher();
$data = array(
'student' => $model_student->getStudents(),
'teacher' => $model_teacher->getTeachers()
);
echo view('admin/header');
echo view('admin/top_menu');
echo view('admin/side_menu');
echo view('admin/dashboard', $data);
echo view('admin/footer');
}
View
Students :
<select name="stdid">
<?php foreach ($student as $std) : ?>
<option value="<?= $std['stdid']; ?>"><?= $std['stdname']; ?></option>
<?php endforeach; ?>
</select>
Teachers :
<select name="tcrid">
<?php foreach ($teacher as $tcr) : ?>
<option value="<?= $tcr['tcrid']; ?>"><?= $tcr['tcrname']; ?></option>
<?php endforeach; ?>
</select>
hope this will help someone out there
My Bokeh version is 2.3.1. I'm able to use the CustomJSHover to specify some javascript to execute on hover, with the input being a field (from a column data source). However, I'm trying to map different CustomJSHover's to the same field, and specify them differently in the HTML. An example snippet of what I have is
customjs = CustomJSHover(code="""///do some javascript here on the value var.""")
hover_points = HoverTool(tooltips="""
<div $x{custom} id=$index style="font-size:12px; font-family:arial; color:white; background:black; padding:10px;">
<div>
<span style="font-weight:bold;">Name:</span>
<span>#input_x{custom}</span>
</div>
""",
formatters={
'#input_x' :customjs
},
point_policy='snap_to_data')
This works great, but I want to have multiple custom formaters on input_x. If I try something like this
c1 = CustomJSHover(code="console.log(1);")
c2 = CustomJSHover(code="console.log(2);")
hover_highlight_line = HoverTool(tooltips="""
<div style="font-size:12px; font-family:arial; color:white; background:black; padding:10px;">
<table>
<tr>
<th style="text-align: center;">1</th>
<th style="text-align: center;">2</th>
</tr>
<tr>
<td style="padding:5px;">#input_x{c2}</td>
<td style="padding:5px;">#input_x{c1}</td>
</tr>
</table>
</div>
""",
formatters= {
'#input_x':c1,
'#input_x':c2
},
I only get the console log for c2. Is this possible to achieve? Thanks.
After sleeping on it, I finally found out how to do this.
Within the bracket, you can map a prefix to a formatter. This is in the docs, but the doc's don't tell you how to use it. Within the CustomJSCode argument, you can access this prefix (or if you want just specify the name) with the format variable.
c1 = CustomJSHover(code="""
if(format == 'agg'){ return //do something with agg}
else if(format == 'mean'){return //do something to get the mean}
""")
hover_highlight_line = HoverTool(tooltips="""
<div style="font-size:12px; font-family:arial; color:white; background:black; padding:10px;">
<table>
<tr>
<th style="text-align: center;">1</th>
<th style="text-align: center;">2</th>
</tr>
<tr>
<td style="padding:5px;">#input_x{agg}</td>
<td style="padding:5px;">#input_x{mean}</td>
</tr>
</table>
</div>
""",
formatters= {
'#input_x':c1,
},
If there is a better way to do this, please post an answer. Thanks.
I'm working on adding an export/downloading feature to a Laravel 5 application. I found the Laravel-Excel library (http://www.maatwebsite.nl/laravel-excel/docs), which seems perfect -- ideally, I will be able to take a Laravel View or html and make a downloadable Excel file.
So far, I've gotten the creation and storage to work. I can create an Excel file, and it's okay (it's the right data and View), and on the server in storage/exports/ I see "Report.xls" - which is right save path. The issue I'm having is I cannot seem to download the file through the browser after creating it.
The Laravel-Excel library has ->download('xls') and ->export('xls') methods, but these only seems to return the raw content, which is visible in the developer's console:
On the right, you can see the file was created and stored as "Report.xls", and presumably the raw content is the right content - but I don't know why it's just spitting raw content into the console. I can open the Report.xls file in Excel, so I know it's not corrupted.
I also tried to use the Laravel 5 Response::download() function and set headers for the download, but it also spit out raw content in the console instead of downloading the file:
The code I'm using is an AJAX call that hits a Controller method, and the controller method just triggers a Service method called "downloadReportFile()":
public function downloadReportFile($requestData, $fileType) {
$configJSON = \Report::loadConfigFile($requestData['reportName']);
$today = Carbon::today()->format('Y-m-d');
$FileViewdata = array(
'config' => $configJSON,
'html' => $requestData['report_html']
);
\Excel::create("Report", function($excel) use ($FileViewdata) {
$excel->setTitle($FileViewdata['config']['title']);
$excel->setDescription($FileViewdata['config']['description']);
$excel->sheet("page 1", function($sheet) {
$sheet->loadView("reports.sample");
});
})->store('xls', storage_path('exports')); // ->export('xls');
$report_excelFilepath = storage_path('exports') . "/Report.xls";
return response()->download($report_excelFilepath, "Report.xls", [
'Content-Type' => 'application/vnd.ms-excel',
'Content-Disposition' => "attachment; filename='Report.xls'"
]);
}
The View being made into the Excel file is a simple table - the same table as in the screenshots. Here's the template/HTML of the View:
<div class="container full-width-container">
<link href="http://192.168.33.10/css/reports.css" rel="stylesheet">
<div id="results" class="row">
<div class="col-xs-12">
<h2 class="report-title">Active Products </h2>
<br>
<div class="row">
<div class="col-xs-12">
<div class="table-responsive report-component" name="table" template="table">
<table id="report-table" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<td class="report-table-th">ENGINE</td>
<td class="report-table-th">PRODUCT COUNT</td>
<td class="report-table-th">PRODUCT PRICE</td>
</tr>
</thead>
<tbody>
<tr class="results-cell">
<td class="report-table-cell">
<p>Meows</p>
</td>
<td class="report-table-cell">
<p>1,234</p>
</td>
<td class="report-table-cell">
<p>781230.00</p>
</td>
</tr>
</tbody>
<tbody>
<tr class="results-cell">
<td class="report-table-cell">
<p>Paws</p>
</td>
<td class="report-table-cell">
<p>10,777</p>
</td>
<td class="report-table-cell">
<p>3919823.00</p>
</td>
</tr>
</tbody>
<tbody>
<tr class="results-cell">
<td class="report-table-cell">
<p>Meow Mobile</p>
</td>
<td class="report-table-cell">
<p>177</p>
</td>
<td class="report-table-cell">
<p>334323.00</p>
</td>
</tr>
</tbody>
<tbody>
<tr class="results-cell">
<td class="report-table-cell">
<p>Tails Cloud</p>
</td>
<td class="report-table-cell">
<p>335</p>
</td>
<td class="report-table-cell">
<p>378918923.00</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
Does anyone see what I might be missing to download an XLS file?
Thanks for your time!
EDIT
After doing some more research, it seems that my original workflow for downloading -- using an AJAX call to trigger -- is part of the problem. For example Download a file from Servlet using Ajax talks about AJAX storing results in JavaScript memory, which would explain why I get content in my console and not a file.
Try to add code below before Excel::create():
ob_end_clean();
ob_start();
Example code:
ob_end_clean();
ob_start();
Excel::create($filename, function($excel) use($records, $sheetname, $data) {}
This works for me.
I use Htmlunit in java. I need to find an element by text(), and i need the second cousin of this element (i think).
I tried this:
HtmlElement element = page.getFirstByXPath("//*[text() = \"SOMETHING\"]/parent/following-sibling/child");
System.out.println(element.asText()); // it's null
Update:
The html source page:
<tr>
<script>
_l('its not important')
</script>
<td valign="top">
<font class="its not important">
</td>
<td valign="top">
<font class="its not important">
SOMETHING
<script>
_l('its not important')
</script>
</font>
<script>
_l('its not important')
</script>
</td>
</tr>
<tr>
<td></td>
<td valign="top">
THE INFORMATION I NEED
</td>
</tr>
The following XPath should work:
//tr[td/*[contains(text(), "SOMETHING")]]/following-sibling::tr/td[#valign ="top"]
It will select a <tr> element, which does have a grandchild with the required text. Then it will select all following siblings and select the next element. Please note that I selected the correct <td> element basec on the valign attribute value, you might not want to do that and instead use the position, i.e. td[2]
try
//*[text() = \"SOMETHING\"]/../following-sibling::*[1]/*[1]
I've got a snippet in my ModX Evo. The problem is that on my local this shippet is working ok,but when I upload it to the host it returns only blank space. The code is a mess, but I need to get figured that out. Any ideas?Thx.
<?php
$action=$_GET['action'];
switch ($action){
case('add'):_add();break;
case('view'):_view();break;
case('order'):_order();break;
case('del'):_del();break;
}
/////////////////////////////////////////////////////////////////
function _add()
{
global $modx;
session_start();
if(!session_is_registered('things')){session_register('things');}
$ar=$_SESSION['things'];
$ar_size=sizeof($ar)-1;
$break=false;
$i=0;
if($ar_size>=0)
{
while ($i<=$ar_size):
$buf=$ar[$i];
if($buf['id']==$_GET['thing']){$_SESSION['things'][$i]['count']=$buf['count']+1;$break=true;}
$i++;
endwhile;
}
if($break==false){
$_SESSION['things'][($i)]=array('title' => $_GET['title'],
'id'=>$_GET['thing'],
'price'=>$_GET['price'],
'count'=>1);}
$modx->sendRedirect("/index.php?id=".$_GET['return']);
}
function _view()
{
if (!isset($_GET['zakaz'])){
session_start();
if(!session_is_registered('things')){session_register('things');}
if (isset($_GET['del']))
{
$buf=array();
$ar=$_SESSION['things'];
$ar_size=sizeof($ar)-1;
if($ar_size>=0)
{
$i=0;
while ($i<=$ar_size):
if(($i+1)!=$_GET['del']){$buf[sizeof($buf)]=$ar[$i];}
$i++;
endwhile;
}
$_SESSION['things']=$buf;
}
if (isset($_GET['delall']))
{
$_SESSION['things']=array();
}
if (isset($_GET['cn']))
{
$c=$_GET['cn'];
$ar=$_SESSION['things'];
$ar_size=sizeof($ar)-1;
if($ar_size>=0)
{
$i=0;
while ($i<=$ar_size):
$b=(int)$c[$i];
if($b>0)
{
$ar[$i]['count']=$b;
}else{$ar[$i]['count']=1;}
$i++;
endwhile;
}
$_SESSION['things']=$ar;
}
if((isset($_GET['peresh']))or(isset($_GET['del']))or(isset($_GET['delall'])))
{
global $modx;
$modx->sendRedirect("/index.php?id=10&action=view");
}
?>
<form action='index.php' method='GET'>
<input type="hidden" value="10" name="id">
<input type="hidden" name="action" value="view">
<table border=0 cellpadding=4 cellspacing=2 width='100%'>
<tr align='center'>
<td align=center colspan=5 bgcolor='#c5dcf8' class='table_title'>Ваша корзина</td>
</tr>
<tr align='center'>
<td bgcolor='#c5dcf8'>№</td>
<td bgcolor='#c5dcf8' >наименование товара</td>
<td bgcolor='#c5dcf8'><nobr>цена, руб.</nobr></td>
<td bgcolor='#c5dcf8'>кол-во</td>
<td bgcolor='#c5dcf8'>удалить</td>
</tr>
<?php
$ar=$_SESSION['things'];
$ar_size=sizeof($ar)-1;
$break=false;
$i=0;
if($ar_size>=0)
{
$summ=0;
while ($i<=$ar_size):
$buf=$ar[$i];
$i1=$i;
$i++;
$name=$buf['title'];
$id=$buf['id'];
$price=$buf['price']*$buf['count'];
$summ=$summ+$price;
$count=$buf['count'];
echo"<tr><td bgcolor=\"white\" style=\"color:black;\" align=\"center\">$i</td><td bgcolor=\"white\"style=\"color:black;\" align=\"center\">
<a style=\"color:blue\" href=\"/index.php?id=$id\">$name</td><td bgcolor=\"white\"style=\"color:black;\" align=\"center\">$price</td>
<td bgcolor=\"white\" style=\"color:black;\" align=\"center\"><input type=\"edit\" name=\"cn[$i1]\" value=\"$count\"SIZE=\"4\"></td>
<td bgcolor=\"white\" style=\"color:black;\" align=\"center\"><font color=\"Maroon\" style=\"color:Maroon;font-weight:bold;font-size:16px;text-decoration:none;\">X</td></tr>";
endwhile;
?>
<tr><td colspan="2" align="right" bgcolor="white"><b style="color:navy">Итого к оплате:</td><td style="color:blue;"bgcolor="white" align="center"><?php echo $summ; ?></td><td align="center"><input name="peresh" style="font-size:10px" type="submit" value="Пересчитать"></td><td align="center"><input style="font-size:10px" name="delall" type="submit" onclick="return confirm('Вы согласны?')" value="Удалить все">
</table><br><center><input type="submit" name="zakaz" value="Оформить заказ"></center></form>
<?php
}
else
{
?>
<tr><td colspan="5" align="center" valign="middle" height="60" style="color:blue" bgcolor="white">Корзина пуста</td></tr>
</table></form>
<?php
}
}
else
{
//////////////////////для заказа////////////////////////
}
?>
<?php
}
You should put all your functions in:
If (!function_exists('yourfunction')) {
[....]
EDIT: does your snippet work in a local modx install? Or does it work as a normal php-script? I dont think you can stop/start php (?> and
You could check your error-log within Modx. If it displays blank errors might be turned off
session_register() and session_is_registered() are deprecated in PHP 5.3 and removed in PHP 5.4, according to the docs. I'd definitely take that out.
As OptimusCrime says, you can't use <?php and ?> in snippets; the ENTIRE snippet will be evaluated in parse time and doing that results in parse errors. May find some evidence of that in the error log.
Also all the references to session_start really shouldn't be there - MODX handles the sessions for you and you should not be re-starting them again. I'm not sure if that will cause issues, but if anything it can help to clear up your code even just a tiny bit ;)