I am trying to build a comment system below my articles where users can reply on the comment as well. Comment or its reply can be posted by only logged-in users.
There I have created 4 tables in MySQL.
User Table
<style type="text/css">
table.tableizer-table {
border: 1px solid #CCC; font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #ccc;
}
.tableizer-table th {
background-color: #104E8B;
color: #FFF;
font-weight: bold;
}
</style>
<table class="tableizer-table">
<tr class="tableizer-firstrow"><th>id</th><th>email</th></tr>
<tr><td>1</td><td>abc#gmail.com</td></tr>
<tr><td>2</td><td>xyz#gmail.com</td></tr>
<tr><td>3</td><td>pqr#gmail.com</td></tr>
<tr><td>4</td><td>abc#yahoo.com</td></tr>
<tr><td>5</td><td>xyx#yahoo.com</td></tr>
</table>
Profile Table
<style type="text/css">
table.tableizer-table {
border: 1px solid #CCC; font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #ccc;
}
.tableizer-table th {
background-color: #104E8B;
color: #FFF;
font-weight: bold;
}
</style>
<table class="tableizer-table">
<tr class="tableizer-firstrow"><th>id</th><th>user_id</th><th>fname</th><th>lname</th></tr>
<tr><td>1</td><td>3</td><td>PQR</td><td>Gmail</td></tr>
<tr><td>2</td><td>2</td><td>XYZ</td><td>Gmail</td></tr>
<tr><td>3</td><td>1</td><td>ABC</td><td>Gmail</td></tr>
<tr><td>4</td><td>5</td><td>XYZ</td><td>Yahoo</td></tr>
<tr><td>5</td><td>4</td><td>ABC</td><td>Yahoo</td></tr>
</table>
Article Table
<style type="text/css">
table.tableizer-table {
border: 1px solid #CCC; font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #ccc;
}
.tableizer-table th {
background-color: #104E8B;
color: #FFF;
font-weight: bold;
}
</style>
<table class="tableizer-table">
<tr class="tableizer-firstrow"><th>id</th><th>article_title</th><th>article_content</th></tr>
<tr><td>1</td><td>Helooooooo</td><td>Hi, How are you?</td></tr>
<tr><td>2</td><td>Hiiiiiiiiiiii</td><td>Hey, How are you?</td></tr>
<tr><td>3</td><td>Heeeeeey</td><td>Hello, How are you?</td></tr>
</table>
Comment Table
<style type="text/css">
table.tableizer-table {
border: 1px solid #CCC; font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #ccc;
}
.tableizer-table th {
background-color: #104E8B;
color: #FFF;
font-weight: bold;
}
</style>
<table class="tableizer-table">
<tr class="tableizer-firstrow"><th>id</th><th>article_id</th><th>user_id</th><th>parent_comment_id</th><th>Comment</th></tr>
<tr><td>1</td><td>2</td><td>5</td><td>0</td><td>Great Article</td></tr>
<tr><td>2</td><td>2</td><td>2</td><td>0</td><td>Nice Article</td></tr>
<tr><td>3</td><td>2</td><td>4</td><td>1</td><td>I agree Great Article</td></tr>
<tr><td>4</td><td>2</td><td>1</td><td>1</td><td>I also agree Great Article</td></tr>
<tr><td>5</td><td>2</td><td>3</td><td>0</td><td>Bad Article</td></tr>
<tr><td>6</td><td>2</td><td>4</td><td>2</td><td>OK Artilce</td></tr>
</table>
I want my output to display as:
Name: XYZ Yahoo (Comment)
Great Article
Name: ABC Yahoo (Reply on 1st Comment)
I agree Great Article
Name: ABC Gmail (Reply on 1st Comment)
I also agree Great Article
Name: XYZ Gmail (Comment)
Nice Article
Name: ABC Yahoo (Reply on 2nd Comment)
OK Artilce
Name: PQR Gmail (Comment)
Bad Article
In the above comment system i am using hierarchical table structure to store comment and its replys.
Hope i have been able to explain my problem.
Can someone help me with MySQL statement and php code
I would tweak the order by clause a little bit so you would get all posts in the right order on php side, so you can simply loop through the resultset.
$sql = 'SELECT c.id, parent_comment_id,`comment`, p.fname, p.lname FROM comment c INNER JOIN profile p on c.user_id=p.user_id INNER JOIN WHERE article_id='.$article_id . ' ORDER BY IF(parent_comment_id=0,id,parent_comment_id) ASC, id ASC;'
While looping through the resulset in php I would build an array to hold the ids of each record to determine their rank within the comments. Although, I should note, that on forums you can rarely see the reference that a comment is a response to the first comment, you can usually see that a comment is a response to a comment made by sy at such and such time. Anyway, the helper array can hold user names and timestamps of the records as well.
//outside the loop
//initialise rowcount variable to 0
$rowcount=0
...
//within the loop
//rowcount variable
$rowcount++;
$helper[$row['id']]=$rowcount;
...
//if a comment has a parent comment, get the parent's rownumber
echo 'Reply to ' . $helper[$row['parent_comment_id']] . '. comment';
Related
I'm using php to display an error message to the user. The code is sitting at the top of the page and once the error message displays, it affects the height of my textboxes. I coded the height in a style sheet. Also, my error message is sitting inside of a div. I tried using the span tag but that isn't working either since its still sitting at the top line of the page. This is the error message in php:
if($result != "")
{
echo "<div id='Error'>";
echo "<b>The following errors occured:</b><br>";
echo $result;
echo "</div>";
}
Registration div css:
#RegBody
{
background-color: white;
background-image: url(LilyPads.jpg);
height: 82.7vh;
}
#RegContents
{
position: absolute;
margin: 39px auto 0 402px;
border-radius: 20px;
background-color: white;
width: 500px;
height: 455px;
padding-left: 57px;
}
#RegisterUser
{
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 15px;
margin-top: 14px;
margin-left: 112px;
color: #1A3D5B;
width: 215px;
height: 30px;
color: white;
background-color: #1A3D5B;
border-color: #1A3D5B;
border-style: solid;
border-radius: 20px;
}
Error message css:
#Error
{
position: absolute;
background-color: white;
border: 2px solid red;
border-radius: 20px;
width: 200px;
padding: 15px;
margin: 147px 0 0 70px;
color: red;
}
Here's the css for the textboxes:
input[type='text']
{
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
text-indent: 10px;
width: 210px;
height: 25px;
border-color: #1A3D5B;
border-style: solid;
border-radius: 20px;
}
Before the error message:
I was thinking that maybe its the font size that's the issue but regardless...a white line also appears at the bottom of the page:
Please have patience with me. I'm a student and new to php. Thank you
i can tell you how to rectify the error (though i am still looking for the reason because of which it happens).
what i did is that i inserted the php code inside body tag and it work fine no change in Textbox dimensions.Below is the code i wrote to prove the same
<?php
$result=1;
echo "<div id='Error'>";
echo "<b>The following errors occured:</b><span>";
echo $result;
echo "</span></div>";
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
input[type='text']
{
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
text-indent: 10px;
width: 210px;
height:25px;
border-color: #1A3D5B;
border-style: solid;
border-radius: 20px;
}
</style>
</head>
<body>
<input type='text' name=''>
</body>
</html>
I have trouble with my CSS. I'm trying to correctly display this kind of array:
https://jsfiddle.net/ju8hmgp9/
I think the problem is maybe right there :
table {
display: table;
width:auto;
margin : auto;
border-spacing: 2px;
border-color: gray;
}
table td{
font-size: 8pt;
}
.empty{
background-color: #C7C7C7;
}
td, th {
display: table-cell;
vertical-align: inherit;
width: auto;
border: 1px solid gray;
border-collapse : collapse;
margin-left: 5px;
margin-right: 5px;
}
As I know, everything worked as well before, and I don't know how to fix this. How can I fix my problem ?
In your JSFiddle you have applied display: block; to the td element. If you remove this then the table displays as it should.
https://jsfiddle.net/4bx4n8fk/1/
I am trying to get unit and staff count using
SELECT
(SELECT
COUNT(unit_id)
FROM
tbl_units) AS uCount,
(SELECT
COUNT(staff_id)
FROM
tbl_staff) AS sCount
For example, the result might be
uCount | sCount
----------------
5 | 45
And the text comes
SELECT title, text FROM tbl_content WHERE alias = 'about'
Retrieved result
employees at units work in our company...
I want to put those value into a paragraph. I send both data to view
$this->load->view('about', array('text' => $text, 'sCount' => $sCount, 'uCount' => $uCount));
The result should be like:
45 employees at 5 units work in our company
My idea is putting variable names into text's itself and replace them. So text would be like:
$1 employees at $2 units work in our company
after getting text using str_replace() would be useful.
But I want to know if there is a better way?
You can directly pass the variable names inside double quotes and php will parse it.
eg:
echo "{$sCount} employees at {$uCount} units work in our company";
Code I have written in CodeIgnitor is as below :
controller
public function index()
{
$sCount = 45;
$uCount = 5;
$this->load->view('welcome_message', array('sCount' => $sCount, 'uCount' => $uCount));
}
view
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to CodeIgniter</title>
<style type="text/css">
::selection { background-color: #E13300; color: white; }
::-moz-selection { background-color: #E13300; color: white; }
body {
background-color: #fff;
margin: 40px;
font: 13px/20px normal Helvetica, Arial, sans-serif;
color: #4F5155;
}
a {
color: #003399;
background-color: transparent;
font-weight: normal;
}
h1 {
color: #444;
background-color: transparent;
border-bottom: 1px solid #D0D0D0;
font-size: 19px;
font-weight: normal;
margin: 0 0 14px 0;
padding: 14px 15px 10px 15px;
}
code {
font-family: Consolas, Monaco, Courier New, Courier, monospace;
font-size: 12px;
background-color: #f9f9f9;
border: 1px solid #D0D0D0;
color: #002166;
display: block;
margin: 14px 0 14px 0;
padding: 12px 10px 12px 10px;
}
#body {
margin: 0 15px 0 15px;
}
p.footer {
text-align: right;
font-size: 11px;
border-top: 1px solid #D0D0D0;
line-height: 32px;
padding: 0 10px 0 10px;
margin: 20px 0 0 0;
}
#container {
margin: 10px;
border: 1px solid #D0D0D0;
box-shadow: 0 0 8px #D0D0D0;
}
</style>
</head>
<body>
<div id="container">
<h1>Welcome to CodeIgniter!</h1>
<div id="body">
<p><?php echo "{$sCount} employees at {$uCount} units work in our company";?></p>
</div>
</div>
</body>
</html>
I hope it will resolve your problem
I have a PDF that is being generated by TCPDF in php. The whole thing looks great, but I cant increase the size of font in any section of the table that is generated. My CSS is not great, but any idea what I am doing wrong?
CSS:
<style>
}
table.first {
color: #003300;
font-family: helvetica ;
font-size: 8pt;
border-left: 1px solid black;
border-right: 1px solid black;
border-top: 1px solid black;
border-bottom: 1px solid black;
background-color: white;
}
td {
border: 1px solid black;
background-color: white;
}
</style>
HTML:
<table class="first" cellpadding="0" cellspacing="0">
<tr>
<td width="50%"><B>1a.</b> Name of Insurance Plan (<B>OFFICE USE ONLY</b>):
<BR>
<BR><BR>
<BR><B>1b.</b> Insurance I.D. Number (<B>UTAH ONLY</b> - Check with the patient and if they have Utah Medicaid and include the Medicaid I.D. Number.):
<BR><BR><B><span style='font-size: 24pt;'>$medicaidid,</span></b>
<BR><BR><B>1c.</b> Patient Name (Last Name, First Name) & DOB (Typed out, example: January 01, 1901):
<BR><BR><B>$name</b>
<BR><B>$dob</b><BR></td>
<td width="50%"><B>2a.</b><BR> <img src="lilogo.png" style="width:8500%;" height="75">
<BR><B>2b.</b> Appointment Number: <BR><BR> <B>$appid</b></td>
</tr>
</table>
remove the } under the style tag
This is your code:
<style>
}
table.first {
color: #003300;
font-family: helvetica;
Try this instead:
<style>
table.first {
color: #003300;
font-family: helvetica;
I dont know what are you trying to say, but on jsfiddle.net there is no issue regarding font size as for example when I tried,
*{
font-size:20px;
}
it worked good or if you have any other issue, please be clear !
This is most likely the culprit for this page:
http://www.mypicx.com/04192010/ff/
table
{
border-collapse:collapse;
}
table,th, td
{
border: 1px solid black;
font-family:Arial, Helvetica, sans-serif; letter-spacing: 1px; font-size:3;
font-size:10px;
}
th
{
background-color:#A7C942;
color:white;
}
I don't know why, but the page has some php scripts in it which shows a table from mysql database. As you can see in the url above.
Please help, why do I see those lines everytime I put those css scripts
Looks like your borders are being set to all of the tables in the page, and not just one.
Try something like:
.mytable
{
border-collapse:collapse;
}
.mytable th, .mytable td
{
border: 1px solid black;
font-family:Arial, Helvetica, sans-serif; letter-spacing: 1px; font-size:3;
font-size:10px;
}
.mytable th
{
background-color:#A7C942;
color:white;
}
And use a class in the HTML on the table you wish to have these borders on:
<table class="mytable">
<tr>
<th>Time</th>
</tr>
<tr>
<td><span class="A">8:00 AM</span></td>
</tr>
</table>