This is my table.
<?php
while(($result = mysqli_fetch_assoc($query))){
echo '<tr>';
echo '<td>';
echo $result['serial'];
echo '</td>';
echo '<td>';
echo $result['address'];
echo '</td>';
echo '<td>';
echo ''.$result['name'].'' ;
echo '</td>';
echo '<td>';
echo $result['postal'];
echo '</td>';
echo '<td>';
echo $result['website'];
echo '</td>';
echo '</tr>';
}
?>
Now I want that if a user moves his mouse over one row, the color should change.
If you don't need to support IE 6, add this to your CSS:
table tr:hover {
background:orange;
}
Make your <tr> tags <tr onMouseOver="this.bgColor='#EABF4E';">, or use table tr:hover in CSS.
I am a bit of a noob, but I think you need to give the table row a class, then give that class a hover property in your css file.
Add a class to your table row like so:
echo '<tr class="highlighter">';
You can name it anything, just make sure you use the same name in your css file.
Now, style the class so that it's color changes when a user's mouse hovers over it:
.highlighter:hover {
background: #ffff99;
}
Related
So I have a table with a value $i for a column that simply counts/labels each row (goes from 1 to 12).
I have an array that I would like to add, into another table column. What I am trying to do, is have the array change the value it is outputting each time the $i value changes.
This is sort of what it looks like as for coding:
<?php
$i=1;
$myarray= array('one', 'two', 'three', 'etc...')
?>
<center>
<?php
echo'<table width="100%">';
echo '<tr>';
echo '<th></th>';
echo '<th>Country</th>';
echo '<th>Greeting</th>';
echo '<th>Translation</th>';
echo '<th>Language</th>';
echo '</tr>';
$number_of_rows = 11;
for ($row = 0; $row <= $number_of_rows; $row++) {
echo '<tr>';
echo '<td >'. $i++ . '</td>';
echo '<td >'. “Blue” . '</td>';
echo '<td >'. “Red” . '</td>';
echo '<td >'. “Green” . '</td>';
echo '<td >'. “Black” . '</td>';
echo '</tr>';
}
?>
</center>
I'm quite new to php, so it's a bit confusing to me. Sorry for any mistakes.
This is where I'm a bit stuck. I want the row that says "Green" to be the row that I am going to implement my array. Each row it will say something different, as the $i value is different for each row. However, I'm not quite sure how to implement this with the current set up that I have going? Is there a way I can do it? Or do I have to take a different route?
Thanks.
I am currently developing a system where I would like individual cells which are being pulled from a database to change color when either a check box is clicked.
I am assuming perhaps referencing to the current table and then adding a field where when the check box is click, the value turns to 1 and therefore it will change the color?
I've got as far as thinking an IF statement is needed, but i'm not sure what else. If there is a simple way, which will fit in the with the following code, that's even better.
$query = mysql_query("Select * from list Where id='$id'"); // SQL Query
$count = mysql_num_rows($query);
if($count > 0)
{
while($row = mysql_fetch_array($query))
{
Print "<tr>";
Print '<td align="center">'. $row['entry'] . "</td>";
Print '<td align="center">'. $row['title'] . "</td>";
Print '<td align="center">'. $row['full_name'] . "</td>";
Print '<td align="center">'. $row['location'] . "</td>";
Print '<td align="center">'. $row['startdate']. "</td>";
Print '<td align="center">'. $row['ipad']. "</td>";
Print '<td align="center">'. $row['laptop']. "</td>";
Print '<td align="center">'. $row['login']. "</td>";
Print '<td align="center">'. $row['frog']. "</td>";
Print '<td align="center">'. $row['sims']. "</td>";
Print '<td align="center">'. $row['email']. "</td>";
Print '<td align="center">'. $row['status']. "</td>";
Print "</tr>";
}
}
else
{
$id_exists = false;
}
If you need any further information I'll be more than happy to help.
look at my edit.
if you want to change only the color on clicking a checkbox you need javascript.
for updating data you need php code.
you have different options to update data of your database but all of them needs php code.
If you like to update the data witout reloading your page you need ajax.
The easier method is to update the data with a html form.
therefore you have to submit it, and on the destination page (which is definied in this format: <form action="index.php" ... >)
you can retrieve you value for the updating field.
Then store it with php in the database, and after it, you can show the html table.
then you can write you if statement to check which color you use in your cell.
which field do you change in your database?
you can use javascript to change the color of your cell when you click on a checkbox.
to change the value in your database you need ajax (no reload of your page)
or pure php.
One solution is to create a form and on click of your checkbox you can submit the form via javascript.
in action="index.php" (per example) you can write php code to change the value in your database based on the checkbox values are submitted.
EDIT:
To change color of a cell based on a database entry you can try this per example:
<td class="<?php echo($value == 1 ? 'green' : 'red'); ?>"></td>
in css you can define you css classes.
.green{
background-color: #f0f;
}
.red{
background-color: #f00;
}
This is my current code (and image showing output). I want the table to be aligned and the Names of the values keep repeating. How can I achieve this?
<?php
$country['ph'] = array('Philippines', 'Manila', '+8');
$country['ru'] = array('Russia', 'Moscow', '-4');
$ctr = 1;
foreach ($country as $key => $value) {
echo '<table border = "1" >';
echo '<td>No';
echo '<td>Flag';
echo '<td>Code';
echo '<td>Name';
echo '<td>Capital';
echo '<td>Time Zone';
echo '<tr>';
echo '<td>', $ctr++, '</td>';
echo "<td><img src = \"/csnclass/img/flags/$key.png\"/></td>";
echo "<td>$key</td>";
echo '<td>',$value[0], '</td>';
echo '<td>',$value[1], '</td>';
echo '<td>',$value[2], '</td>';
echo '</tr>';
echo '</table>';
}
?>
Presently, your foreach is outputting a <table> for each item it iterates through - so the table cells in these tables won't be lined up, as cells in different tables have no relation to each other. Similarly, you're outputting the header of each table column for every single item as well.
A quick way to fix this is to take some of the echo calls outside of the foreach loop (mainly relating to the table and headers):
// Start table and print out headers
echo '<table border = "1" >';
echo '<tr>';
echo '<td>No';
echo '<td>Flag';
echo '<td>Code';
echo '<td>Name';
echo '<td>Capital';
echo '<td>Time Zone';
echo '</tr>';
// Print data for each country
foreach ($country as $key => $value) {
echo '<tr>';
echo '<td>', $ctr++, '</td>';
echo "<td><img src = \"/csnclass/img/flags/$key.png\"/></td>";
echo "<td>$key</td>";
echo '<td>',$value[0], '</td>';
echo '<td>',$value[1], '</td>';
echo '<td>',$value[2], '</td>';
echo '</tr>';
}
// End table
echo '</table>';
Hope this helps! Let me know if you have any questions.
I am working with a php document that has tables as well as an image, the way its set up is I have a table with 3 columns, two with text and one with a picture. The problem that I am running into is that the images are all different sizes which cause my text lines to cause spacing in between them, is there a way to format the text to retain its original formatting? Here is an example of what I am talking about http://www.cnghl.biz/cnghldb/test.php?PlayerID=2818
Here is the CSS
<style>
a {text-decoration:none;}
}
td {
vertical-align: top;
}
td img {
vertical-align: top;
}
.space {
line-height: .3 em;
}
.wrap {
float:right;
}
</style>
And here is the PHP
Echo "<td width='659'><div align='center'>";
Echo "<table width='602' border='0'>";
Echo "<tr>";
Echo "<td colspan='3'><h1>".$row['FirstName']." ".$row['LastName']."</h1> </td>";
Echo "</tr>";
Echo "<tr>";
Echo "<td width='164'><strong>Birthdate:</strong>".$row['DOB']."</td>";
$DOB = $row[DOB]; //dd.mm.yyyy
$user_date = new DateTime($DOB);
$curr_date = new DateTime();
$age_cal = $curr_date->diff($user_date);
Echo "<td width='219'><strong>Age:</strong>".$age_cal->y;"</td>";
Echo "<td width='205' rowspan='6'><div align='center'><img src=\"http://www.cnghl.biz/cnghldb/images/".$iPlayerID.".jpg\">";
Echo "</tr>";
Echo "<tr>";
Echo "<td><strong>Nation:</strong>".$row['Nation']."</td>";
Echo "<td><strong>CNGHL Team:</strong>".$row['CNGHLRights']. "</td>";
Echo "</tr>";
Echo "<tr>";
Echo "<td><strong>Position:</strong>".$row['Position']. "</td>";
Echo "<td><strong>Weight:</strong>".$row['Weight']. "</td>";
Echo "</tr>";
Echo "<tr>";
Echo "<td><strong>Height:</strong>".$row['Height']. "</td>";
Echo "<td><strong>NHL Team:</strong>".$row['Team']. "</td>";
Echo "</tr>";
Echo "<tr>";
Echo "<td><strong>Draft Year:</strong>".$row['CNDraftYR']."</td>";
Echo "<td><strong>Draft Position:</strong>".$row['CNDraftPOS']."</td>";
Echo "</tr>";
Echo "<tr>";
Echo "<td height='25'><strong>Drafted By:</strong>".$row['DrTeam']."</td>";
Echo "<td><strong>Current Salary:</strong></td>";
Echo "</tr>";
Echo "</table>";
Echo "</div></td>";
Echo "<td width='141'> </td>";
Echo "</tr>";
Echo "</table>";
Echo "</div>";
I have tried to adjust the size of the image but that does not solve the problem, any help would be greatly appreciated.
Definitely do not use tables for layout purposes. By the way, this is the expected behavior of HTML tables, stretching their size to the content.
You can achieve this using divs, both solving your problem and having a more semantic markup, and having a cleaner markup.
I would also suggest you wrap your player's data into a Definition list (dl element) for a more semantic approach.
Example implementation
If the problem is the images being different sizes, you could give each image a specific width. Or if you don't want to adjust the images themselves, give the div/td that the image is in a specific width and height that is equal to the largest image and doesn't change.
Your rowspan is set to 6 but you have 7 <tr> in your table. The td { vertical-align: top; } is what you need for your CSS.
I want to retrieve XML data from soundcloud using a simple search engine, that retrieves results in a simple results table array
$tracks = "https://api.soundcloud.com/tracks?q=".$var."&client_id=bbba84be29098bdaad6a5de1c048e3e9&limit=10";
$mysongs = simplexml_load_file($tracks);
echo "<table>";
echo '<table cellpadding="0" cellspacing="0">';
echo '<tbody>';
echo '<tr>';
echo '<th>State</th> <th>Name</th><th>Song</th><th>artist</th><th>user</th> <th>user</th>';
echo '</tr>';
echo '</tbody>';
foreach ($mysongs->track->user as $track) {
echo '<tbody>';
echo '<tr>';
echo '<td>';
echo $user->kind;
echo '</td>';
echo " ";
echo '<td>';
echo $user->kind;
echo " ";
echo '</td>';
echo '<td>';
echo $user->kind;
echo " ";
echo '</td>';
echo '<td>';
echo $user->kind;
echo " ";
echo '</td>';
echo '<td>';
echo $user->kind;
echo '</td>';
echo '<td>';
echo $user->kind;
echo '</td>';
echo '</tr>';
echo '</tbody>';
}
this is my code but nothing seems to display as a result, i have tested the same format of code on another api (yelp) and it does work in xml, so what am i missing here? i dont want to use json, i need it to be xml ( the user -> kind ) is just for testing the code right now.
the variable $user doesn't exist. the variable you want is $track. so where you have
echo $user->kind
replace that with
echo $track->kind
you can see the format of the returned object (and it's hierarchy by running the code in the cli and
print_r($mysongs)