PHP how to add a style to HTML in a table [closed] - php

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to be able to style this table:
With a dark background, the text returned is unreadable:
<?php
echo "
<table border = '1'>
<tr>
<th>Client ID</th>
</tr>";
echo "<tr>";
echo "<td>" .$clientID. "</td>";
echo "</tr>";
echo "</table>";
}
?>
The PHP is working. But how do I change the color of the text in the table?
Found a solution
I found a simple solution to what was needed. Use the bgcolor = '#fff', this fixed the issue.
<?php
echo "
<table border = '1'>
*bgcolor='#fff'*
<tr>
<th>Client ID</th>
</tr>";
echo "<tr>";
echo "<td>" .$clientID. "</td>";
echo "</tr>";
echo "</table>";
}
?>

Here's a basic rundown of how to implement styles onto your page:
HTML HEAD
<head>
<!-- example css -->
<style type="text/css">
table.mytable {
border: 1px solid #FF0000;
}
table.mytable > thead > tr > th {
font-size: 2em;
}
table.mytable > tbody > tr > td {
color: #999;
}
</style>
<!-- or below: include a css file -->
<link rel="stylesheet" type="text/css" href="/path/to/my/css/file.css">
</head>
Your Table (see my changes to the DOM)
<table class="mytable">
<thead>
<tr>
<th>Client ID</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<!-- notice how I include php without echoing the whole table -->
<?php echo $clientID; ?>
</td>
</tr>
</tbody>
</table>
Learn CSS
Check out this website for a good tutorial and reference to follow for adding css properties to your page.

try using Bootstrap, just download it and put the files in the correct folders, put ths css files in your css folder, the js files in your javascript folder and the same thing with images, finally in your code just add classes like this:
<?php
echo "
<table class='table table-striped' >
<tr>
<th>Client ID</th>
</tr>";
echo "<tr>";
echo "<td>" .$clientID. "</td>";
echo "</tr>";
echo "</table>";
}
?>
take a look here for more information: http://twitter.github.com/bootstrap/base-css.html#tables

Related

How to use an HTML button to trigger a function?

I am populating an HTML table with information from a database and want to trigger it with a button.
Can someone help me with this, and perhaps add some links to relevant website with examples?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div method="GET">
<table>
<thead>
<tr>
<th>ID</th>
<th>Nombre</th>
<th>Usuario</th>
</tr>
<?php
include "php/populate.php";
?>
</thead>
</table>
<input type="button" value="button" id="button">
</div>
</body>
</html>
<?php
$result = mysqli_query($enlace,"SELECT * FROM tb_personas");
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['txt_nombre'] . "</td>";
echo "<td>" . $row['txt_usuario'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($enlace);
?>
You need to use jQuery (the easiest way to use ajax)
take a look at this question on stackoverflow how to call a php script on a html button click
additionally you are including your data at table's header, instead they should be included in table's body.
<table>
<thead>
<tr>
<th>ID</th>
<th>Nombre</th>
<th>Usuario</th>
</tr>
</thead>
<tbody>
<?php include "php/populate.php"; ?>
</tbody>
</table>

Going to someones profile

I have this userlist page and i want for users to be able to click the users username and it will send them to there profile page how would i go on doing this ?
This line is where the user clicks the username of a user
echo "<td class='info'><a href=''>". $people_list['username']."</a></td>";
Also in my .htaccess i have a code that makes it so i go to users profile all i do is http://www.example.com/username
<?php
include 'core/int.php';
include 'includes/head.php';
include 'head.php';
include 'includes/body.php';
include 'body.php';
$people_list="SELECT * FROM users";
$people=mysql_query($people_list);
?>
<html>
<head>
<style>
.owner {
color: orange;
}
</style>
</head>
<body>
<pre>
<table class="table table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Username</th>
<th>Email</th>
</tr>
<?php
while($people_list=mysql_fetch_assoc($people)){
echo "<tr>";
if ($people_list['username'] == KillerDucky1){
echo "<td>". $people_list['user_id']."</td>";
echo "<td class='warning'><a class='owner' href=''>". $people_list['username']."</a></td>";
echo "<td>". $people_list['email']."</td>";
} else {
echo "<td>". $people_list['user_id']."</td>";
echo "<td class='info'><a href=''>". $people_list['username']."</a></td>";
echo "<td>". $people_list['email']."</td>";
echo "</tr>";
}
}
?>
</thead>
</pre>
</body>
</html>
You simply need to put the username in the <a> link tag :)
<a href='/".$people_list['username']."'>...</a>
You could try just adding the username to the href of the anchor.
echo '<td class="info">'. $people_list['username'].'</td>';
should give you something like:
<td class="info">username</td>

how to style php echo table

I have the following code and I would like to style it. Are there any ways to do this?
Specifically I want to center the Columns headings and the text within each cell.
echo "Variable Profile";
echo "<table>";
echo "<th>"."STATE"."</th>";
echo "<th>"."$column_name"."</th>";
foreach($lotsofasians as $lotsofasian){
echo "<tr>";
echo "<td>".$lotsofasian->state."</td>";
echo "<td>".$lotsofasian->$column_selected."</td>";
echo "</tr>";
}
echo "</table>";
I have tried putting something like align= 'center' in the tag but I cant get it to work.
With regard to styling HTML, there's nothing special about the fact that PHP is outputting it. You can still give your elements classes, IDs, inline styling or whatever - it's just that if PHP is involved you'll have to reference these in the echo output statements.
Just change the echo statement to include classes as required, e.g.
echo "<table class='some_class'>";
Try using css rather than using inline styles
css
table th,table td{
text-align:center;
}
See demo here
Your php is going to output something like this:
<table>
<th>state value</th>
<th>column value</th>
<tr>
<td>value</td>
<td>value</td>
</tr>
</table>
I would sneak a <tr> in there for your <th> elements as well:
<table>
<tr>
<th></th>
</tr>
Then, create some css rules:
table th, table td { padding: 5px; text-align: center; }
Use css-classes or inline styles.
Why you quote Variables? Your HTML is not valid.
simplest way:
echo 'Variable Profile';
printf('<table>
<thead>
<tr>
<th>%s</th>
<th>%s</th>
</tr>
</thead>
<tbody>', 'State', $column_name);
foreach($lotsofasians AS $index => $lotsofasian) {
$style = array();
/* Example 1: center text */
$style[] = 'text-align: center;';
/* Example 2: Set Background each second output */
if($index % 2 == 0) {
$style[] = 'background: #DDDDDD;';
}
printf('<tr style="%">
<td>%s</td>
<td>%s</td>
</tr>', implode('', $style), $lotsofasian->state, $lotsofasian->{$column_selected});
}
echo '</tbody>
</table>';

how to load mysql data faster into jquery datatable

hi i am using jquery datatable plugin to load mysql data into it so far its goin good but when the records are more the data table gets relatively slow to load so now i am stuck here and have no idea of what has to be done so can anyone help me in this
here is my code
<?php
$result = mysql_query("SELECT * FROM `mdb` ORDER BY grno");
?>
$(document).ready(function(){
$('#datatables').dataTable({
"sPaginationType":"full_numbers",
"aaSorting":[[2, "desc"]],
"bJQueryUI":true
});
})
<table id="datatables" class="display">
<thead>
<tr>
<th>Srno.</th>
<th>Brno.</th>
<th>Name</th>
<th>Address</th>
<th>City</th>
<th>Pin</th>
<th>Mobile</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td align='center'>$row[grno]</td>";
echo "<td align='center'>$row[brno]</td>";
echo "<td align='center'>$row[name]</td>";
echo "<td align='center'>$row[address]</td>";
echo "<td align='center'>$row[city]</td>";
echo "<td align='center'>$row[pin]</td>";
echo "<td align='center'>$row[mobile]</td>";
echo "<td><img src='images/edit.png'> <img src='images/delete.png'></td>";
echo "</tr>";
}
?>
</tbody>
</table>
Please have a look at here.
If you want to have server-side processing click here.

Display content without reloading page in php [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am using 2 div elements as tabber
1) search candidate
2) my list.In search candidate when i select some candidate ,than that candidate is added to selected_candidate table and displayed in my list div ,but to display it in my list i have to reload whole page ,how can i display it without reloading whole page
<div class="tabber" style="width: auto;">
<div <?php if(isset($_POST['submita'])){ echo "class=\"tabbertab tabbertabhide\"";}else{echo "class=\"tabbertab\"";} ?>>
<h3>SEARCH CANDIDATE</h3>
//.....select candidate code.....//
</div>
<div <?php if(isset($_POST['searchsel_list'])){ echo "class=\"tabbertab tabbertabdefault\"";}else{echo "class=\"tabbertab\"";} ?>>
<h3>MY LIST</h3>
<div id="tabr">
<script>
$("td").removeAttr("style");​
</script>
<form method="post" action="csearch.php?epage=csearch" name="mylist">
<div class="CSSTableGenerator">
<table id="mylist_remark">
<caption>SELECTED CANDIDATE LIST</caption>
<!-- headings -->
<tr>
<th>REMARK</th>
<th> <input name="delete_sel" id="delete_sel" value="DELETE" type="submit" class="button"/></th>
<th>NAME</th>
<th>CELL NO</th>
<th>STATUS</th>
<th>EMAIL ID</th>
<th>LOCATION</th>
<th>QAULIFICATION INFORMATION</th>
<th>KIND OF WORK</th>
<th>DETAILED CV</th>
</tr>
<!-- /headings -->
<?php
if($mresult_set)
{
if (mysql_num_rows($mresult_set) == 0)
{
echo "<tr>";
echo "<td colspan=\"9\" ><p align=\"center\" class=\"message\"> <blink><span style=\"color:red;\" > NO CANDIDATE SELECTED</span></blink></p></td>";
echo "</tr>";
}
$j=0;
while($data_set1 = mysql_fetch_array($mresult_set))
{
// $i=0;
if($data_set1['ca']=='')
{
$qua="";
}
else
{
$qua=$data_set1['ca'];
}
if($data_set1['cs']=='')
{
$qua="";
}
else
{
$qua.=",".$data_set1['cs'];
}
if($data_set1['cwa']=='')
{
$qua.="";
}
else
{
$qua.=",".$data_set1['cwa'];
}
if($data_set1['completed']=='')
{
$qua.="";
}
else
{
$qua.=", Completed(".$data_set1['completed'].")";
}
if($data_set1['persuing']=='')
{
$qua.="";
}
else
{
$qua.=", Persuing(".$data_set1['persuing'].")";
}
echo "<tr >";
echo "<td><input id={remark{$j}} type=\"text\" class=\"fancyText\" onkeyup=\"writeremark(this.id,{$data_set1['eid']},{$emprid});\" value=\"{$data_set1['remark']}\" maxlength=\"15\" placeholder=\"Write Remark\" /></td>";
echo "<td style=\"text-align:center;\"><input id=\"listrow_sel{$j}\" type=\"checkbox\" name=\"list_sel[]\" value=\"{$data_set1['eid']}|{$emprid}\" /></td>";
echo "<td>{$data_set1['ename']} {$data_set1['lname']}</td>";
echo "<td>{$data_set1['ecell']}</td>";
echo "<td>{$data_set1['eposition']}</td>";
echo "<td>{$data_set1['eemail']}</td>";
if($data_set1['ecity']=='')
{
echo "<td>{$data_set1['ecountry']}</td>";
}
else
{
echo "<td class=\"showmsg\" title=\"Country ={$data_set1['ecountry']}, State = {$data_set1['estate']} \" >{$data_set1['ecity']}</td>";
}
// echo "<td>{$data_set['ecountry']},{$data_set['estate']},{$data_set['ecity']}</td>";
echo "<td>{$qua}</td>";
echo "<td>{$data_set1['other_work1']} {$data_set1['other_work2']}{$data_set1['other_work3']}{$data_set1['other_work4']} {$data_set1['other_work5']} {$data_set1['other_work6']} {$data_set1['other_work7']} {$data_set1['other_work8']} {$data_set1['other_work9']} {$data_set1['other_work10']}{$data_set1['other_work1e']} {$data_set1['other_work2e']} {$data_set1['other_work3e']} {$data_set1['other_work4e']} {$data_set1['other_work5e']} {$data_set1['other_work6e']} {$data_set1['other_work7e']} {$data_set1['other_work8e']} {$data_set1['other_work9e']} {$data_set1['other_work10e']}</td>";
echo "<td><a style=\"cursor:hand;\" href=\"detailcv.php?id={$data_set1['eid']}&flag=0\" target=\"_blank\" ><input style=\"cursor:auto;width:40px;\" class=\"button\" name=\"cv\" type=\"button\" value=\"C V\" /></a></td>";
//echo "<td class=\"edit\" contenteditable=\"true\">Write Remark</td>";
echo "</tr>";
$j++;
}
}
?>
<tr><td colspan="10">
<img src="images/pdfdown.jpg" alt="Adobe Doc" width="42" height="42" title="Download List In PDF"/>&nbsp&nbsp&nbsp
<a id="showcand" href="<?php echo $listurl1;?>"><img src="images/excel.gif" alt="Excel Doc" width="42" height="42" title="Download List In Excel "/></a>
<?php ?>
</td></tr>
</table></div>
</form>
</div>
In this Image i am showing tabber,when i click on MY list ,hoe can i load its form without loading whole page so that selected candidate will be visible,i came to know that it can be done using Ajax ,but i dont know how i can do it in my code
you can do with the help of ajax. for that you have to call ajax function on select candidate whom you want to add to your list.
ajax function demo are as follows:
function getList(){
$.ajax({
type: "POST",
url: "List.php", // file where you process the list.
data: {name:name1,sda:name2}, // post data you want to pass to the file for processing
success:function(data){
//change the content of your mylist div here
}
});
}
you can try it.

Categories