I was wondering how I could add a scroll to my table that is written in the php file. I do not want to write it in a style.css file, I want it directly in the php file. below is my code, but I am not able to make it to work. The table gets content from mySql database, which works. but the problem is that I get to much of content so it fills out the whole page. That is why I want to make it scrollable :
if(mysqli_num_rows($result) > 0){
echo '<table border="1">';
echo "<tr>";
echo "<th>Name</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "</tr>";
}
echo "</table>";
If im getting your question right you need to set a width and height then set the overflow-y. This will give you a table set to a certain size with a scroll bar. Note you need to set your own width and height.
echo "<table style=\"width:500px; height:500px; overflow-y:auto\">";
Related
echo "<table id='table_id' class='display table table-hover table-inverse'>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['last_update_time'] . "</td>";
When I add this row with a delete link, data table is not being applied to my table.
echo "<td>Delete</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
Without the particular line all works fine.
Please help.
TIA
can you please confirm that in your code, number of columns inside 'thead' are equal to number of columns inside 'tbody'. It should not mismatch the number of columns of both 'thead' and 'tbody'
This question may have been answered, but I have been Googling and searching this site for over a week now and have not come across anything that applies to this situation. Yes, this is a homework assignment, and I have exhausted my resources (the entire class is confused). Any help or links to relevant resources would be appreciated.
Problem: I have a program where the user can submit "bug reports". These bug reports are all written to the same text file and are each treated as an array. Each report is also displayed with a "Details" link. I need to write a hyperlink that will essentially assign the link to the index value of the array without hardcoding it (because the link will need to work for future updates) and then have that specific report displayed in a separate page. I'm submitting a photo of the display table with the link in it so that there's a visual of this allow with the specific code for the display table.
Image of display table
$count = count($ReportArray);
for($i = 0; $i < $count; ++$i) {
$CurReport = explode("~", $ReportArray[$i]);
//bug description line and details link
echo "<tr>";
echo "<td><p style='text-align: center;'><strong>Bug Description: </strong></td>";
echo "<td colspan='6' style='text-align: center;'>".htmlentities($CurReport[0])."<br/></td>\n";
//$CurArray = implode("~", $CurReport);
//assign details link an array - no idea how
$num = count($ReportArray); //total number of reports
echo '<td style="text-align: center;">';
echo '<p>Details</p>';
echo "</td></tr>\n";
//other bug report fields
echo "<tr>";
echo "<td></td>";
echo "<td style=\"text-align:center;\">".htmlentities($CurReport[1])."<br /></td>\n";
echo "<td style=\"text-align:center;\">".htmlentities($CurReport[2])."<br /></td>\n";
echo "<td style=\"text-align:center;\">".htmlentities($CurReport[3])."<br /></td>\n";
echo "<td style=\"text-align:center;\">".htmlentities($CurReport[4])."<br /></td>\n";
echo "<td style=\"text-align:center;\">".htmlentities($CurReport[5])."<br /></td>\n";
echo "<td style=\"text-align:center;\">".htmlentities($CurReport[6])."<br /></td>\n";
echo "<td></td>";
echo "</tr>\n";
//display updates
echo "<tr>";
$line_count = count($ReportArray);
if($line_count > 7) {
echo "<tr>";
echo '<td style="text-align:center; text-weght:bold;">Update</td><td>';
echo htmlentities($CurReport[$line_count - 1]).'<br/>\n';
echo "</td>";
echo "</tr>\n";
}
}
So here's how the program works:
bug_List.php: Has the form for bug reports and then a table to
display the submitted and validated reports. These reports all
written and read from the same text file. BugReportCreate.php:
This file validates the input and writes it the text file. BugReport.php: This file is used to display each individual report and allows the user to submit updates for the report currently displayed. BugReportUpdate.php: writes/appends the update to the specific report from BugReport and displays the updated report. bug_List.php will also display the updated report(s)
I'm coming here after some head banging. Still learning php/mysql and coming across an issue which is bothering me for a while.
Currently I print a table with all the data without any condition. The values below the lower values and above are printed in this table. The snippet of my code is below:
while ($result = mysql_fetch_assoc($records)){
echo "<tr>";
echo "<td>" .$result['id']. "</td>";
if ($result['time'] > $limit[lower]){
echo "<td bgcolor=#ff0000>" $result['time']. "</td>";
} else {
echo "<td>" .$result['time']. "</td>";
}
echo "<td>" .$result['name']. "</td>";
echo "</tr>";
}
I want to create a href link so that by dafault only values above the lower are printed and on clicking the link, say detailed_view will give the table as it does above i.e. all value including below and above the lower value. Shall I create two methods and use them in href separately. In that case there will be two while loops which I want to avoid. Any pointer on this?
The name of the script is display.php, so before the loop I tried using:
echo "<a href='display_jobid.php?view=$num'>Show All</a>";
It does create a hyperlink Show All but how to get the functionality working, am not sure.
Thanks
I have a MySQL database where I have a table ITEMS and column PICTUREPATH. The Picture path lists "localhost/firstimage.jpg" and so on. In my PHP script, I've added some code to what I thought would work, but it's not. I'm fetching the picturepath but it's literally giving me the text "localhost/firstimage.jpg" rather than the actual image. Here is what my code looks like...
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td align='center'>" . $row['picturepath'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
How can I add this into the code so the picture actually displays, not the text name of the image?
echo "<td align='center'><img src=\"" . $row['picturepath'] . "\" /></td>";
I have created a table using information from my database which all works fine. I have this all echo'd back in position how i want it.
My question is when i add a background to this, it adds a background to everything in every row. How can i add a background to each row with maybe 10px padding in between each background?
echo "\n<table id=\"messageboard\" cellpadding=\"0\" cellspacing=\"0\">\n";
echo "<tr><th width=\"150px\" style=\"text-align: center;\"></th>\n";
echo "<th width=\"330px\" style=\"background-color: #c01718;\"></th>\n";
echo "</tr>";;
while($row = mysql_fetch_array($result)){
echo "<tr><td>\n";
echo $row ['username']."<br />".$row ['date_time'];
echo "<td>\n";
echo $row ['message'];
echo "</td></tr>\n";
}
You need to add the css class to the tr in order to give a style for every row
The starting row line should read
echo "<tr class=\"styledRow\"><td>\n";
Check this out:
http://www.utexas.edu/learn/html/colors.html
your problem can be solved by to ways:
add style in tr tag ,and give padding to tr 10px or more
alternatively
$style = ['style1','style2']
$i = 0
while($row = mysql_fetch_array($result))
{
if {$i ==0{$i = 1}}
else {$i = 0}
echo "<tr";
echo "class=$style[$i]";
echo "><td>\n";
echo $row ['username']."<br />".$row ['date_time'];
echo "<td>\n";
echo $row ['message'];
echo "</td></tr>\n";
}
now in css define two style sheet style1 and style2, your table row will have alternating style as style1 and style2,
please ignore syntax error