Why do I need div table in my layout? - yii - php

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>

Related

How to display data from selected table in the same database in the form of table, in php?

I am working on a website where I am getting input of semester number from the user and I want to display the subjects in the semester they entered accordingly.
For this, I planned to create tables for each semester which would have the subjects in it.
For now, I am successful to retrieve data from one table. But I am required to get subjects as per the entered semester by the student.
Following is the code,which works perfectly for semester 5. Please suggest alterations as per the requirements asked above.
<!DOCTYPE html>
<html>
<head>
<title></title>
<!-- very important -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="subject.css">
</head>
<body>
<h1 class="text-center text-capitalize font-weight-bold">Subject Information</h1>
<div class="container">
<div>
<br>
<div>
<form class="form-inline">
<!-- <div class="mx-auto" style="width: 200px;"> -->
<div class="form-group">
<label for="Sem"> Semester: </label>
<div>
<input type="text" name="sem_no" placeholder="Enter current semester" id=sem class="form-control">
</div>
<br>
</div>
</form>
</div>
</div>
</div>
<div>
<!-- TABLE DISPLAYED WITH DATA FROM RESPECTIVE DATABASE -->
<div class= "container">
<div class="col-lg-12 ">
<br><br>
<h2 class="text-center">Subjects</h2>
<table class="table table-striped table-hover table-bordered">
<tr>
<th>Subject code</th>
<th>Subject Name</th>
<th>Faculty name</th>
</tr>
<?php
$con = mysqli_connect('localhost','root');
mysqli_select_db($con,'subjects');
$q= "select * from sem5";
$query = mysqli_query($con,$q);
while($res = mysqli_fetch_array($query))
{
?>
<tr>
<td><?php echo $res['subject_no']; ?></td>
<td><?php echo $res['subject_name']; ?></td>
<td><?php echo $res['faculty_name']; ?></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</body>
</html>
Please suggest alterations. Will be highly obliged.
You need to do a HTTP GET request and use PHP to get the value. Then use PHP to make the SQL query. Here it is in its simplest form.
I've added a submit button which submits the form and executes the HTTP GET with the parameters attached to the URL. You will see ?sem_no=x after it is submitted. That's the Query String.
...
...
<div class="form-group">
<label for="Sem"> Semester: </label>
<div>
<input type="text" name="sem_no" placeholder="Enter current semester" id=sem class="form-control">
</div>
<div>
<input type="submit"/>
</div>
<br>
...
...
...
...
//check the value was submitted and it is not blank
<?php if(isset($_GET['sem_no']) && !empty($_GET['sem_no'])) { ?>
<!-- TABLE DISPLAYED WITH DATA FROM RESPECTIVE DATABASE -->
<div class= "container">
<div class="col-lg-12 ">
<br><br>
<h2 class="text-center">Subjects</h2>
<table class="table table-striped table-hover table-bordered">
<tr>
<th>Subject code</th>
<th>Subject Name</th>
<th>Faculty name</th>
</tr>
<?php
$con = mysqli_connect('localhost','root');
mysqli_select_db($con,'subjects');
$q= 'select * from sem'.$_GET['sem_no'];
$query = mysqli_query($con,$q);
while($res = mysqli_fetch_array($query))
{
?>
<tr>
<td><?php echo $res['subject_no']; ?></td>
<td><?php echo $res['subject_name']; ?></td>
<td><?php echo $res['faculty_name']; ?></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
<?php
//closing if
} ?>
...
...
As mentioned in the comments earlier, this database design is quite poor. I know you are learning though. Have you considered having a subjects table that has a Semester column? Then you could do a query like:
SELECT * FROM subjects where semester_number = x
There are even better ways to do it beyond that but this would be a good starting point for you.

How can i save data on a database from a html pasted in a texarea or similar?

first of all I want to clarify that I have read the suggestions but I did not find an exact answer.
I want to make a database locally by saving in this parts of a html page code, and I'm going to use it locally only, i use Wampsever 3.
I want to make a page in a local in which I can paste HTML code and parts of this code are saved in a database, the code is dynamically generated so I think it has no error, and always i will paste a DIV element with a TABLE with ROWS.
The code is something like this:
<div>
<table>
<tbody>
<tr class="month">
<td colspan="5">Jan</td>
</tr>
<tr class="day-info">
<p>xxx</p>
</tr>
<tr class="dataofday">
<div class="info1">
<p>yyy</p>
</div>
<div class="info2">
<p>zzz</p>
</div>
</tr>
<tr class="day-info">
<p>xxx</p>
</tr>
<tr class="dataofday">
<div class="info1">
<p>yyy</p>
</div>
<div class="info2">
<p>zzz</p>
</div>
</tr>
<tr class="month">
<td colspan="5">Feb</td>
</tr>
<tr class="day-info">
<p>xxx</p>
</tr>
<tr class="dataofday">
<div class="info1">
<p>yyy</p>
</div>
<div class="info2">
<p>zzz</p>
</div>
</tr>
<tr class="day-info">
<p>xxx</p>
</tr>
<tr class="dataofday">
<div class="info1">
<p>yyy</p>
</div>
<div class="info2">
<p>zzz</p>
</div>
</tr>
</tbody>
</table>
</div>
And i need to save in a database the rows with classes "day-info" and class="dataofday", both in the same row of a table in a a database but in different cells.
I can create the database, i can get the elements with Jquery or Javascript but i do know how can i save the data in a database from a page in local where i can paste the DIV with the data.
So i need some help for create it and save the data to a DB.
Am i rigth if my first step is to create a .html or .php file into a virtual host in Wampserver with a code like this:
<html>
<head>
</head>
<body>
<textarea rows="40" cols="100">
...Here paste the data.
</textarea>
</body>
</html>
and maybe with new DOMDocument i can get the data, parse it and save it to th database.

How to give table white background color - Bootstrap, Yii

I've modified the general Yii Crud generated index.php to not display the side menu and instead display a table. I've done this by overriding the default layout and by creating a column3.php This view file looks like this
<?php $this->beginContent('//layouts/main'); ?>
<div class="row-fluid">
<div class="span3">
<table class="table 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>
</form>
</table>
</div><!-- sidebar span3 -->
<div class="span9">
<div class="main">
<?php echo $content; ?>
</div><!-- content -->
</div>
</div>
<?php $this->endContent(); ?>
Unfortunately the side of my screen is a grey color and I've realized that the table itself is simply composed of a couple of lines and text (meaning it is see-through). I'd like to change the background color of the table to be white - any suggestions would be greatly appreciated!
CSS
.table,
.table tr,
.table td {
background-color: white !important;
}

html link tr broken not on place

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.

while() - not looping - PHP

I have a little problem with my PHP while loop. I am looping out all the available membership packages (and it's details) from my database.
My code is like this:
<?php
while($mp = mysql_fetch_assoc($s)):
?>
<tr class="hover">
<td class="name" width="30%"><?php echo $mp['membershipname']; ?></td>
<td class="price" width="30%">$<span><?php echo $mp['ap_price']; ?></span>/<span><?php echo $mp['duration']; ?></span> days.</td>
<?php if($userdata['membership']>$mp['membershipid']): ?>
<td width="40%" class="purchase"></td>
<?php else: ?>
<td width="40%" class="purchase" >
Pricing
</tr>
<?php endif; ?>
<div style='display:none'>
<div id='inline_content' style='padding:10px; background:#fff;'>
<div style="text-align:center;font-weight:bold">Please select your payment method:</div>
<div style="text-align:center">
<br />
<?php
if($sdata['allow_paypal'] == 1 && $mp['pp_price']>0 && $userdata['paypal']!=""): ?>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="float:left;" >
<input type="submit" name="submit" class="click cblue" value="PayPal - $<?php echo $mp['pp_price']; ?>">
</form>
<?php endif;
if($sdata['allow_alertpay'] == 1 && $mp['ap_price']>0 && $userdata['alertpay']!=""):
//Do not change any input fields, OTHER than return URL (if needed)
?>
<form method="post" name="ap" action="https://www.alertpay.com/PayProcess.aspx" style="float:right;" >
<input type="submit" name="submit" class="click cgreen" value="AlertPay - $<?php echo $mp['ap_price']; ?>" />
</form>
<?php
endif; ?>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$("#upg<?php echo $mp['id']; ?>").colorbox({inline:true, width:"30%",href:"#inline_content"});
});
</script>
<?php endwhile; ?>
As you can see in the above code, I am doing a while loop.
My problem is that the $mp['pp/ap_price'] inside the #inline_content is not looping. It only take the price from the first row. Although, it is looping in the table.
What's the issue here? I tried to do another loop inside the #inline_content, but it didn't work.
HTML IDs should be unique to one DOM element.
You have a DOM element #inline_content for every record in your database query result. Then, when you try to use Javascript to display them all, only one is displayed because they all have the same ID.
HTML and Javascript are not aware of your PHP loop.
Consider using a class attribute instead of an id attribute.

Categories