I want to put a button in the table at php.
here is my code.
echo "<td>";?> <img src="<?php echo $row["image"]; ?>" height = "100" width = "100" border="1"> <?php echo "</td>"; //row에 값넣는 것
echo "<td>" . $row['bookName'] . "</td>";
echo "<td>" . $row['publisher'] . "</td>";
echo "<td>" . $row['writer'] . "</td>";
echo "<td>" . $row['libraryowned'] . "</td>";
echo "<td>" . $row['codenumber'] . "</td>";
// I want to button here
echo "<td>" . $row['loan'] . "</td>";
echo "<td>" . $row['publicationdate'] . "</td>";
echo "<td>" . $row['reservation'] . "</td>";
echo "<td>" . $row['borrowdate'] . "</td>";
echo "<td>" . $row['returndate'] . "</td>";
echo "<tr></tr>";
just put a button element inside a element like this:
<td><button></button></td>
if you like to refer to some script / page:
<td><button></button></td>
You can put in the href part whatever you want. You can also omit the button element and heir your button-CSSClass to the <a> element.
I hope I helped you.
Have Fun!
Related
I want to change the color of the entire cell according to a specific value. But what should I do when the grammar is wrong and it doesn't work?
in this my code
echo "<tr if( $row['treatment_fees_check_division'] == 'error') : style='yellow' >";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['chart_num'] . "</td>";
echo "<td>" . $row['chart_name'] . "</td>";
echo "<td>" . substr($row['visit'], 0,10) . "</td>";
echo "<td >" . number_format($row['total_medical_bills']) . "</td>";
echo "<td >" . number_format($row['total_amount']) . "</td>";
echo "<td>" . number_format($row['amount_asked']) . "</td>";
echo "<td>" . number_format($row['medical_bills_payment']) . "</td>";
echo "<td>" . number_format($row['personal_liability_amount']) . "</td>";
echo "<td >" . number_format($row['non_payment']) . "</td>";
echo "<td >" . number_format($row['non_payment_sales']) . "</td>";
echo "<td>" . $row['insurance_division'] . "</td>";
echo "<td>" . $row['division'] . "</td>";
echo "<td>" . number_format($row['cash_amount_received']) . "</td>";
echo "<td>" . number_format($row['cash_receipt']) . "</td>";
echo "<td>" . number_format($row['cash_receipt_non_payment']) . "</td>";
echo "<td>" . number_format($row['cash_receipt_payment']) . "</td>";
echo "<td>" . number_format($row['card_amount_received']) . "</td>";
echo "<td>" . number_format($row['card_non_payment']) . "</td>";
echo "<td>" . number_format($row['card_payment']) . "</td>";
echo "<td>" . number_format($row['treatment_fees_difference']) . "</td>";
echo "<td>" . $row['treatment_fees_check_division'] . "</td>";
echo "</tr>";
Try replacing your first line with something like this.
if ($row['treatment_fees_check_division'] == 'error') {
echo "<tr style='yellow' >";
} else {
echo "<tr >";
}
I seem to be having an issue with my HTML formatting. I am calling the database to display all information within the table on a webpage. I have got the information coming down into the table. Unfortunately the table is adding an additional row to the bottom of the table making 4 rows when in fact there is only 3 rows displaying in the database.
Any idea as to why?
<?php
//connect to the server
$link = mysql_connect('*****', '*****', '****');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('******');
$query = mysql_query("SELECT * FROM tablename");
echo "<table border='1'>
<tr>
<td>Date</td>
<td>Region</td>
<td>Cameraman</td>
<td>Livestream?</td>
<td>Event Title</td>
<td>Lecturer</td>
<td>Time</td>
<td>Speaker</td>
<td>ICE Contact</td>
<td>Venue Address</td>
<td>Venue Contact</td>
<td>Additional Comments</td>
<td>On App?</td>
</tr>";
WHILE($rows = mysql_fetch_array($query)):
echo "<tr>";
echo "<td>" . $rows['date'] . "</td>";
echo "<td>" . $rows['region'] . "</td>";
echo "<td>" . $rows['cameraman'] . "</td>";
echo "<td>" . $rows['livestream'] . "</td>";
echo "<td>" . $rows['eventitle'] . "</td>";
echo "<td>" . $rows['lecturer'] . "</td>";
echo "<td>" . $rows['time'] . "</td>";
echo "<td>" . $rows['speaker'] . "</td>";
echo "<td>" . $rows['icecontact'] . "</td>";
echo "<td>" . $rows['venueaddress'] . "</td>";
echo "<td>" . $rows['venuecontact'] . "</td>";
echo "<td>" . $rows['additioncomments'] . "</td>";
echo "<td>" . $rows['onapp'] . "</td>";
echo "</tr>";
endwhile;
echo "</table>";
?>
I have added the link to the page below.
http://cpdonline.tv/spreadsheet/spreadsheet.php
Update your while loop with the following:
WHILE($rows = mysql_fetch_array($query)):
$rows = array_filter($rows);
if (!empty($rows)) {
echo "<tr>";
echo "<td>" . $rows['date'] . "</td>";
echo "<td>" . $rows['region'] . "</td>";
echo "<td>" . $rows['cameraman'] . "</td>";
echo "<td>" . $rows['livestream'] . "</td>";
echo "<td>" . $rows['eventitle'] . "</td>";
echo "<td>" . $rows['lecturer'] . "</td>";
echo "<td>" . $rows['time'] . "</td>";
echo "<td>" . $rows['speaker'] . "</td>";
echo "<td>" . $rows['icecontact'] . "</td>";
echo "<td>" . $rows['venueaddress'] . "</td>";
echo "<td>" . $rows['venuecontact'] . "</td>";
echo "<td>" . $rows['additioncomments'] . "</td>";
echo "<td>" . $rows['onapp'] . "</td>";
echo "</tr>";
}
endwhile;
echo "</table>";
array_filter() function's default behavior will remove all values from array which are equal to null, 0, '' or false.
It seems that you have empty data in your database, as many lines are empty
Check your database for empty records or run the query
DELETE FROM table_name WHERE column='';
I have a form on my website that I use to send information to a MySQL table, then I have a PHP file called read.php that retrieves the information from the MySQL table and displays it on a page. This works completely fine and I have no issues with it. However I would now like to add a search function so the table can be searched by things such as first name, last name, email etc.
Here is my read.php file:
<html>
<head>
<title>messages</title>
</head>
<body>
<h1>Message Center</h1>
<?php
$con = mysqli_connect('localhost', 'removed', 'removed', 'removed');
$result = mysqli_query($con,"SELECT*FROM specialisttable");
echo"<table border='1'>
Specialist Table
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Phone</th>
<th>Email</th>
<th>Website</th>
<th>Speciality</th>
<th>Street Name</th>
<th>Suburb</th>
<th>City</th>
<th>Post Code</th>
<th>Comments</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
{
echo "<tr>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['phone'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['website'] . "</td>";
echo "<td>" . $row['speciality'] . "</td>";
echo "<td>" . $row['streetname'] . "</td>";
echo "<td>" . $row['suburb'] . "</td>";
echo "<td>" . $row['city'] . "</td>";
echo "<td>" . $row['postcode'] . "</td>";
echo "<td>" . $row['comments'] . "</td>";
echo "</tr>";
}
}
echo"</table>";
mysqli_close($con);
?>
<br>
<br>
Click to return to homepage
</body>
</html>
I would to like search by things such as first name, email and city so for example if I have an entry with the name John and I type J into the first name search bar John and his other information would show in the table as well as anyone else with J in their name.
Also the same thing for something such as city, if I type auck then all the entries with auck in the city section would show as well as the other information.
I'm unsure of how I would do this, I've managed to work out how to search for first name using $search = $_GET['search']; and then using:
while($row = mysqli_fetch_array($result))
{
if($search=="")
{
echo "<tr>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['phone'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['website'] . "</td>";
echo "<td>" . $row['speciality'] . "</td>";
echo "<td>" . $row['streetname'] . "</td>";
echo "<td>" . $row['suburb'] . "</td>";
echo "<td>" . $row['city'] . "</td>";
echo "<td>" . $row['postcode'] . "</td>";
echo "<td>" . $row['comments'] . "</td>";
echo "</tr>";
}
else if($row['firstname']==$search)
{
echo "<tr>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['phone'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['website'] . "</td>";
echo "<td>" . $row['speciality'] . "</td>";
echo "<td>" . $row['streetname'] . "</td>";
echo "<td>" . $row['suburb'] . "</td>";
echo "<td>" . $row['city'] . "</td>";
echo "<td>" . $row['postcode'] . "</td>";
echo "<td>" . $row['comments'] . "</td>";
echo "</tr>";
}
I can do the same thing for last name and any other field but it makes the code very messy and I don't think it's the most efficient way of doing things.
If someone could please point me in the right direction on how to efficiently make a search function I would greatly appreciate it.
Thank you very much.
I'm trying to pass some variables from a link but for some reason it only reads one of them. Below is the link and the code. roundNo shows up fine.
archery/viewround.php?gameNo=1&roundNo=7
echo $_GET['gameNo'];
echo $_GET['roundNo'];
echo "<table border><tr><th>Round ID</th><th>Match Name</th><th>Player Name</th><th>Shot 1</th><th>Shot 2</th><th>Shot 3</th><th>Shot 4</th><th>Shot 5</th><th>Shot 6</th><th>Shot 7</th><th>Shot 8</th><th>Shot 9</th><th>Shot 10</th></tr>";
while ($row = mysql_fetch_array($sql)) {
$tempPlayerName = getnamewithid($row["player_id"]);
$tempMatchName = getmatchnamewithid($_GET['gameNo']);
echo "<tr>";
echo '<td>' . $row["round_id"].'</td>';
echo "<td>" . $tempMatchName. "</td>";
echo "<td>" . $tempPlayerName. "</td>";
echo "<td>" . $row["shot_1"] . "</td>";
echo "<td>" . $row["shot_2"] . "</td>";
echo "<td>" . $row["shot_3"] . "</td>";
echo "<td>" . $row["shot_4"] . "</td>";
echo "<td>" . $row["shot_5"] . "</td>";
echo "<td>" . $row["shot_6"] . "</td>";
echo "<td>" . $row["shot_7"] . "</td>";
echo "<td>" . $row["shot_8"] . "</td>";
echo "<td>" . $row["shot_9"] . "</td>";
echo "<td>" . $row["shot_10"] . "</td>";
echo "</tr>";
$i++;
}
echo "</table>";
How can I assign a class id that is unique for all the <tr>
The id's need to stay stay even when I refresh as I will be using them to style the table.
Here is the code I am using:
while($row = mysql_fetch_array($result2))
{
echo "<tr id='centered' class='"; echo "'";
echo "<td>" . $row['Year_9'] . "</td>";
echo "<td>" . $row['Year_8'] . "</td>";
echo "<td>" . $row['Year_7'] . "</td>";
echo "<td>" . $row['Year_6'] . "</td>";
echo "<td>" . $row['Year_5'] . "</td>";
echo "<td>" . $row['Year_4'] . "</td>";
echo "<td>" . $row['Year_3'] . "</td>";
echo "<td>" . $row['Year_2'] . "</td>";
echo "<td>" . $row['Year_1'] . "</td>";
echo "<td>" . $row['Year_0'] . "</td>";
Perhaps use a counter with a multi-valued class?
$i = 1;
while($row = mysql_fetch_array($result2))
{
$secondClass = 'abc' + $i;
echo "<tr id='centered' class='firstClass $secondClass'>";
...
$i++;
}