I want to make custom code website function into wordpress.
its continuation from My URL question here: https://stackoverflow.com/questions/65456090/change-default-user-profile-url-bbpress-plugin
I have code that insert value into database phpmyadmin
function topic_count($reply_id = 0){
global $connection;
$user_id= bbp_get_reply_author_id( $reply_id );
$username= get_userdata($user_id);
$topic_count = bbp_get_user_topic_count_raw( $user_id);
$reply_count = bbp_get_user_reply_count_raw( $user_id);
$post_count = (int) $topic_count + $reply_count;
if(isset($user_id, $username->user_login, $topic_count, $reply_count, $post_count)){
$query = "INSERT INTO example (id, username, topic_count, reply_count, post_count )
VALUES (
'$user_id',
'$username->user_login',
'$topic_count',
'$reply_count',
'$post_count')";
mysqli_query($connection , $query);
}
}
add_action('bbp_theme_after_reply_author_details', 'topic_count');
The code working well, and the data stored into phpmyadmin. See this image below:
Now, i want to make function to get the user data. Not listing all the data, only retrieve specific user data. The key to define what data to take only through URL. Because the url have username defined, from this code:
function user_profile_link(){
$author_id = bbp_get_reply_author_id();
$user_info = get_userdata($author_id);
$url = site_url()."/profile/".$user_info->user_login;
return $url;
}
add_filter('bbp_get_user_profile_url', 'user_profile_link');
This is the image result:
Im trying to get the data with this code:
$id_query = mysqli_query($connection, "SELECT * FROM example" ) ;
$test = mysqli_fetch_assoc($id_query);
echo $test["username"];
And yes, the data can be fetched. But the problem is, only fetch first data. 'achan'. User andre and also chandra, also get 'achan' username.
In the nutshell, how to make code like, this url 'http://localhost/example/profile/chandra/' for 'chandra' data. this url 'http://localhost/example/profile/andre/' for 'andre' data.
All help is appreciated. Thank you web developer.
use while when you fetch data and set it to array; then use foreach.
$test_array = [];
while($test = mysqli_fetch_assoc($id_query)){
$test_array[] = $test;
}
foreach(test_array as $item){
echo $item["username"];
}
I found the solution in my own way. I'm using $_SERVER['REQUEST_URI']
the code is like this:
$uriSegments = explode("/", parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$id_query = mysqli_query($connection, "SELECT * FROM example" ) ;
foreach($id_query as $row);
if($uriSegments[3] == $row["username"]){
//your code, but in my case something like this
?>
<table style="border-collapse: collapse; width: 100%;">
<tbody>
<tr>
<td style="width: 20%; border-style: solid; border-color: #000000;">User ID</td>
<td style="width: 20%; border-style: solid; border-color: #000000;">Username</td>
<td style="width: 20%; border-style: solid; border-color: #000000;">Jumlah Topik</td>
<td style="width: 20%; border-style: solid; border-color: #000000;">Jumlah
Balasan</td>
<td style="width: 20%; border-style: solid; border-color: #000000;">Total</td>
</tr>
<tr>
<td style="width: 20%; border-style: solid; border-color: #000000;"><?= $row["id"] ?>
</td>
<td style="width: 20%; border-style: solid; border-color: #000000;"><?=
$row["username"] ?></td>
<td style="width: 20%; border-style: solid; border-color: #000000;"><?=
$row["topic_count"] ?></td>
<td style="width: 20%; border-style: solid; border-color: #000000;"><?=
$row["reply_count"] ?></td>
<td style="width: 20%; border-style: solid; border-color: #000000;"><?=
$row["post_count"] ?></td>
</tr>
</tbody>
</table>
<br /><br />
<?php
}
This code solve my problem. I hope this answer will be useful.
Related
I have a table row within an HTML email that won't fit everything in unless I make the width 110%.
The only problem is now the table extends to the right. The whole table is set to a width of 600px.
I have found that increasing the width to 110% is the only way I can make the text not wrap on a phone.
Can someone please tell me how to center this row even though the width is extended?
The code is -
<div style="margin-bottom: 30px; margin-top: 30px;">
<table class="td" cellspacing="0" cellpadding="6" style="width: 110%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; border-left: none; border-right: none; border-top: 1px solid #000; border-bottom: 1px solid #000;" border="0"; align="center">
<tbody>
<?php $items = $order->get_items();
foreach ($items as $item) {
$product = new WC_Product($item['product_id']);?> <tr>
<td><?php echo $product->get_image($size = 'shop_thumbnail'); ?></td>
<td><?php echo $product->get_title(); ?> </td>
<td>REVIEW NOW</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
Thanks!!
A pic is attached where you can see 'review now' section extending past the sections above. I just want to center this.
Try to use the "nowrap" keyword
<td nowrap><?php echo $product->get_image($size = 'shop_thumbnail'); ?></td>
You have to check the table-properties:
Tablepropertie
this is my first post and im already totally confused about my project right now :x
im able to make a successful connection to the sql db and also receive my data which displays on the top left, BUT its supposed to display in a html table, not somewhere on the screen :O
Here is the website to see the code in action, though there is none yet!
http://blackskill.square7.ch/
Here is the code which is running fine, but maybe im just too stupid and new for coding yet xd
<!DOCTYPE html>
<?php
$connection=mysqli_connect("localhost","username","password","db_name");
if ($connection) {
echo "database online <br>";
} else {
die("Connection failed. Reason: ".mysqli_connection_error());
}
$sql="SELECT * FROM blackskill_playerdb";
$results=mysqli_query($connection,$sql);
if (mysqli_num_rows($results)>0) {
while($row=mysqli_fetch_array($results)) {
echo '<tr>
<td>'.$row[0].'</td>
<td>'.$row[1].'</td>
<td>'.$row[2].'</td>
<td>'.$row[3].'</td>
</tr>';
echo "<br>";
}
}
mysqli_close($connection);
?>
<html>
<head>
<style>
* {
box-sizing: border-box;
}
#myInput {
background-image: url('/searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
width: 20%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}
#myTable {
border-collapse: collapse;
width: 100%;
border: 1px solid #ddd;
font-size: 18px;
}
#myTable th, #myTable td {
text-align: left;
padding: 12px;
}
#myTable tr {
border-bottom: 1px solid #ddd;
}
#myTable tr.header, #myTable tr:hover {
background-color: #f1f1f1;
}
</style>
</head>
<body>
<h2><center>Inofficial S.K.I.L.L. - Special Force 2 - Dishonor List</center></h2>
<input type="text" id="myInput" onkeyup="aa" placeholder="Search for player..." title="Type in a name">
<table id="myTable">
<tr class="header">
<th style="width:40%;">Player</th>
<th style="width:20%;">Clan</th>
<th style="width:20%;">Evidence</th>
<th style="width:20%;">Added to list</th>
<?php while($row=mysqli_fetch_array($results)) : ?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['clan']; ?></td>
<td><?php echo $row['rulebreak']; ?></td>
<td><?php echo $row['addlist']; ?></td>
</tr>
<?php endwhile ?>
</tr>
</table>
<tbody>
</body>
</html>
i hope we can find an answer together with friendship, emotions and friendship!
regards
I am having a php table which contains information about billing of certain numbers. After generating this table I export it in pdf using mpdf.
If the table has a certain number of rows it breaks the page in a weird way, leading the headers repeat on the next page with no rows.
Here is the format of the table:
The table contains up to 3 headers inside <thead> tags, like this:
<table class="items" width="100%" style="font-size: 9pt; border-collapse: collapse;" cellpadding="8">
<thead>
<tr>
<td width="30.3%">Forbrug</td>
<td width="23.1%">Periode</td>
<td width="10.76%">Tid/MB</td>
<td width="9.28%">Enheder</td>
<td width="12.9%" align="right">I alt</td>
<td width="13.3%" align="right">I alt+<b>moms</b></td>
</tr>
</thead>
rows are added in a while from the database in this way.. nothing special
<tr>
<td>'.$produktNameFromDatabase.'</td>
<td>'.$periodeFromDatabase.'</td>
<td>'.$tidMbFromDatabase.'</td>
<td>'.$enhederFromDatabase.'</td>
<td align="right">'.number_format((float)$produktpris, 2, ',', '.').' kr.</td>
<td align="right"><b>'.number_format((float)$produktpris*(1 + (0.25 * $moms)) - $momsDiscount, 2, ',', '.').' kr.</b></td>
</tr>
with the total lines at the end
<tr>
<td class="blanktotal" colspan="1" rowspan="6"></td>
<td class="blanktotal" colspan="1" rowspan="6"></td>
<td class="totals" colspan="2">Subtotal:</td>
<td class="totals" colspan="2">'.number_format((float)$pris1, 2, ',', '.').' kr.</td>
</tr>
<tr>
<td class="totals1" colspan="2">Moms:</td>
<td class="totals1" colspan="2">'.number_format((float)$pris1*(0.25 * $moms) - $momsTotal, 2, ',', '.').' kr.</td>
</tr>
<tr>
<td class="totals1" colspan="2"><b>TOTAL:</b></td>
<td class="totals1" colspan="2"><b>'.number_format((float)$pris1*(1 + (0.25 * $moms)) - $momsTotal, 2, ',', '.').' kr.</b></td>
</tr>
</tbody>
</table>
!!! EVERYTHING that you have seen by now, including the totals are a part of the table!
Here is the mpdf settings that I have:
In PhP:
$mpdf=new mPDF('win-1252','A4','','',20,15,48,25,10,10);
$mpdf->useOnlyCoreFonts = true; // false is default
$mpdf->SetProtection(array('print'));
$mpdf->SetTitle("Suggestive Title");
$mpdf->SetAuthor("Author");
$mpdf->SetWatermarkText("Faktura");
$mpdf->showWatermarkText = true;
$mpdf->watermark_font = 'DejaVuSansCondensed';
$mpdf->watermarkTextAlpha = 0.1;
$mpdf->SetDisplayMode('fullpage');
In HTML:
$html .= '<!--mpdf
<htmlpageheader name="myheader">
<table width="100%"><tr>
<td width="50%" style="color:#000000;">
<span style="font-weight: bold; font-size: 14pt;">
Company Name
</span>
Company Information
</td>
<td width="50%" style="text-align: right;">
<img src="image.jpg" />
Invoice Information <br />Side: {PAGENO} af {nb}
</td>
</tr></table>
</htmlpageheader>
<htmlpagefooter name="myfooter">
<div style="border-top: 1px solid #000000; font-size: 9pt; text-align: center; padding-top: 3mm; ">
Footer Stuff
</div>
<div style="font-size: 9pt; text-align: center;">
Other Footer Stuff
</div>
</htmlpagefooter>
<sethtmlpageheader name="myheader" value="on" show-this-page="1" />
<sethtmlpagefooter name="myfooter" value="on" />
mpdf-->';
Some styling that I use
body {font-family: sans-serif;
font-size: 10pt;
}
p { margin: 0pt;
}
td { vertical-align: top; }
.items td {
border-left: 0.1mm solid #000000;
border-right: 0.1mm solid #000000;
}
table thead td { background-color: #d4ffaa;
border: 0.1mm solid #000000;
}
.items td.blanktotal {
background-color: #FFFFFF;
border: 0mm none #000000;
border-top: 0.1mm solid #000000;
border-right: 0.0mm solid #000000;
}
.items td.totals {
text-align: right;
border-top: 0.1mm solid #000000;
border-right: 0.0mm solid #000000;
border-left: 0.0mm solid #000000;
}
.items td.totals1 {
text-align: right;
border-top: 0.0mm solid #000000;
border-right: 0.0mm solid #000000;
border-left: 0.0mm solid #000000;
}
The result looks something like this:
This issue occurs only when the number of rows fills the page. If it overflows it is no major issue, because the table headers are still there on the next page (all of them unfortunately, not only the last one) and the rest of the rows are added further.
How can I get rid of those empty rows, in this special case?
Thank you!
!!EDIT: Added more information, code and a better image of the case. Sorry for not doing it at the first time!
!!EDIT #2: I just observed on other examples that had more than 1 page of rows that the <thead>s keep their position on next pages. It happens all the time. Is there a way to disable that so that other <thead>s will just continue on the next page from the top of the page without remembering the position from the previous page?
You need to set headers (and footers) in individual strings, like this:
require_once __DIR__ . '/../vendor/autoload.php';
$stylesheet = '
.table-header{
border: none;
background-color: yellow;
width: 100%;
}
.table-header td{
border-right: 1px solid;
}
.table-body{
border: none;
background-color: transparent;
width: 100%;
}
.table-body td{
border-right: 1px solid;
border-bottom: 1px solid;
}
.table-footer{
border: none;
background-color: transparent;
width: 100%;
}
.table-footer .td-number{
text-align: right;
}
';
/* Sample data */
$html = '<table class="table-body">';
for ($i = 1; $i <= 100; $i++) {
$html.='<tr>
<td width="30.3%">Forbrug '.$i.'</td>
<td width="23.1%">Periode '.$i.'</td>
<td width="10.76%">'.$i.' MB</td>
<td width="9.28%">Val '.$i.'</td>
<td width="12.9%" align="right">I alt '.$i.'</td>
<td width="13.3%" align="right"><b>moms</b> '.$i.'</td>
</tr>';
}
$html.= '</table>';
$header = '<table class="table-header"><tr>
<td width="30.3%">Forbrug</td>
<td width="23.1%">Periode</td>
<td width="10.76%">Tid/MB</td>
<td width="9.28%">Enheder</td>
<td width="12.9%" align="right">I alt</td>
<td width="13.3%" align="right">I alt+<b>moms</b></td>
</tr></table>';
$footer = '<table class="table-footer"><tr>
<td>Footer here</td>
<td class="td-number"><b>Page N. {PAGENO}</b></td>
</tr></table>';
$mpdf = new mPDF('c','A4','','',15,15,18,15,10,5);
$mpdf->mirrorMargins = 1;
/* Declare headers */
$mpdf->SetHTMLHeader($header);
$mpdf->SetHTMLHeader($header,'E');
/* Declare footers */
$mpdf->SetHTMLFooter($footer);
$mpdf->SetHTMLFooter($footer,'E');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html);
$mpdf->Output();
I eventually found a solution. Best way to get rid of these things is to replace <thead> tags with <th>. <thead> has a predefined style which makes the table header repeat itself on every page. <th> will make the header stop repeating itself on the next pages (fortunate or unfortunate), but it will eliminate the space caused by the <thead>'s style
Need some help.
I'm creating a table view with grid/borders.
However,some borders can't be seen although I'm including in tags the style=''.
Much better if I will tell that I only see the table border which is included in table tag.
Please see attached file for the format.
By the way I'm getting the records in database via PHP script.
Here is my code:
$result.="<br/><br/><br/>
<table style='border:solid 1px;'>";
$result.="<thead style='border-bottom:thin solid'><th style='text- align:center;border-style:solid 1px'>YC ".$store_name."</th></thead>
<tr><td></td>
<td colspan='3'>Service Time </td>
<td colspan='3'>Production Time</td>
<!--<td colspan='3'>Customer Feedback</td>
<td colspan='3'>Customer Feedback</td>
<td colspan='3'>Customer Feedback</td>-->
</tr>
<tr></tr>
<tr>
<td></td>
<td>TC Within<br>30 mins.</td>
<td>Total<br>TC</td>
<td><br/>%</td>
<td>Within 15 <br/>mins.</td>
<td>Total <br/>TC</td>
<td><br/>%</td>
</tr>
<tr></tr>";
//get PartView
$query = "SELECT * FROM Part_view WHERE StoreID = ".$store_id." AND datepart(month,TransDate) = '".$month."' AND datepart(year,TransDate) = '".$year."' ORDER BY TransDate ASC ";
$que = mssql_query($query);
while($row=mssql_fetch_array($que)){
$transdate =date('d',strtotime($row['TransDate']));
$tc30 = $row['TC30'];
$totaltc30 = $row['Total_TRX1'];
$hitrate = round($row['Hitrate']);
$pd15 = $row['PDT15'];
$totalpd15 = $row['Total_TRX2'];
$production = round($row['ProdTime']);
$excellence = $row['Excellence'];
$totalexcellence = $row['Total_TRX4'];
$excellencepercent = round($row['ExcelPercent']);
$good = $row['Good'];
$totalgood = $row['Total_TRX5'];
$goodpercent = round($row['GoodPercent']);
$poor = $row['Poor'];
$totalpoor = $row['Total_TRX6'];
$poorpercent = round($row['PoorPercent']);
if($hitrate==""){
$hitrates = "";
}else{
$hitrates = $hitrate;
}
$result.="<tr>
<td>".$transdate."</td>
<td>".$tc30."</td>
<td>".$totaltc30."</td>
<td>".$hitrate."% </td>
<td>".$pd15."</td>
<td>".$totalpd15."</td>
<td>".$production."% </td>
</tr>";
}
$result.="</table>";
echo $result;
Can someone help me?
OK, I think what you are actually asking is why the entire grid isn't being 'bordered'. You can use CSS to accomplish this far cleaner than inline styles. You need to set styles for TD.
Code:
table {
border-width: 1px;
border-spacing: 0px;
border-style: solid;
border-color: black;
border-collapse: separate;
background-color: white;
}
table th {
border-width: 1px;
padding: 3px;
border-style: solid;
border-color: black;
background-color: white;
}
table td {
border-width: 1px;
padding: 3px;
border-style: solid;
border-color: black;
background-color: white;
}
If you use this in your CSS you can remove all the inline styling you have already, this code will fix it all.
You can use this tool to create the table. But I recommend you to do that by yourself. And you should include your code and we can help you to fix that.
Tool: http://divtable.com/generator/
So I made this div that is populated by php calls to my server to populate it with a table per entry in the Server table. Aka, a php script connects to my server, checks how many entries there are, and creates a table for each one to populate the div. So in the end there are several table entries displayed corresponding to each entry in the database.
I don't know of a jsfiddle/codepin type place that allows php since it's server-side so I took a picture to show what it looks like. The arrows are pointing to the two entries where the box they are in is wider than the others. This happens any time I do not include a link (an optional entry in the database). I assume this is because it is trying to fill the space left by having no link in the last table row, but the last part of my php script should have removed that last row if it was empty (assuming I wrote it correctly) and it shouldn't need to stretch to fill something no longer there.
So, what I'm asking here is how do I make each of the orange rows the same size?
Picture of the box: http://i67.tinypic.com/5k3nzs.png
HTML (Relevant portion)
<div id="announcements_box">
<h2>Announcements</h2>
<?php include "scripts/php/getAnnouncement.php";?>
<div class="bottom_color"></div>
</div> <!--end announcement_box-->
CSS (Relevant portion)
#announcements_box{
table-layout: fixed;
display: inline-block;
background-color: #FFFFFF;
width: 47%;
color: black;
margin-left: 1rem;
border-top-left-radius: 30px;
border-top-right-radius: 30px;
border-bottom-left-radius: 30px;
border-bottom-right-radius: 30px;
}
#announcements_box h2{
font-weight: normal;
font-size: 2rem;
background-color: navy;
color: white;
border-top-left-radius: 25px;
border-top-right-radius: 25px;
}
.announcement_blocks{
width: 100%;
margin-bottom: .5rem; /* space after each block */
background-color: #C0C0C0;
}
.announcement_blocks img{
/* height: 75px; */
width: 75px;
margin: .5rem;
padding-top: 1rem;
}
.announcement_blocks td{
/* word-wrap: break-word;
word-break: break-all;
*/
}
.announcement_blocks td.title{
text-align: center;
background-color: #E18A07;
font-weight: bold;
}
.announcement_blocks td.descr{
padding-left: 1rem;
padding-right: 1rem;
}
.announcement_blocks td.link{
text-align: center;
/*
padding-left: 1rem;
padding-right: 1rem;
*/
}
.announcement_blocks td.img_s{
width: 1rem;
background-color: #330000;
}
.bottom_color{
height: 2.5rem;
background-color: navy;
border-bottom-left-radius: 25px;
border-bottom-right-radius: 25px;
margin-top: -.5rem;
}
PHP (Relevant portion)
<?php require "scripts/php/database_connect.php"?>
<?php
$query = mysqli_query($con, "SELECT * FROM Announcements") or die("Error in query. Details: ".mysqli_error());
while($row = mysqli_fetch_assoc($query))
{
?>
<table class="announcement_blocks">
<tr>
<td class="img_s" rowspan="3"><?php echo "<img src='/img/announcement_icon/announcement_imp.png" . "' alt='announcement'>";?></td>
<td class="title"><?php echo $row['title']; ?></td>
</tr>
<tr>
<td class="descr"><?php echo $row['description']; ?></td>
</tr>
<?php if($row['link'] != "")
{
?>
<td class="link"><?php echo $row['link']; ?></td>
<?php
}
?>
</table>
<?php
}
?>
I know this is long and probably a bit confusing since I can't just hand you a fiddle or codepin to toy with but any ideas?
Thanks
In bottom if links are there its working, if not there its height increased.
to avoid this you can give
<?php if($row['link'] != ""){?>
<?php echo $row['link']; ?>
<?}else { echo "<br>";}?>
Try to use this php code:
<?php
$query = mysqli_query($con, "SELECT * FROM Announcements") or die("Error in query. Details: ".mysqli_error());
while($row = mysqli_fetch_assoc($query)){?>
<table class="announcement_blocks">
<tr>
<td class="img_s" rowspan="3"><?php echo "<img src='/img/announcement_icon/announcement_imp.png" . "' alt='announcement'>";?></td>
<td class="title"><?php echo $row['title']; ?></td>
</tr>
<tr>
<td class="descr"><?php echo $row['description']; ?></td>
</tr>
<tr>
<td class="link">
<?php if($row['link'] != ""){?>
<?php echo $row['link']; ?>
<?}?>
</td>
</tr>
</table>
<?}?>