Now i dont know if this is simple or hard. If its just css or php code i need
But basically i have posting system and users can comment on posts. In the comments page it shows orginal post and one users have left (the comments)
I had one in there and this was fine but i added another and it looked like this...
[1]: http://i.stack.imgur.com/2fIXd.jpg
As you can see its completly different! Heres my code for it...
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("test");
echo "<a href='Untitled9.php'>Go Back...</a>";
?>
<br/><br/>
<div class="message">
<?php
$sql = mysql_query("SELECT * FROM threads WHERE id = '".
mysql_real_escape_string($_GET['id']) . "'") or die(mysql_error());
while($r = mysql_fetch_array($sql)) {
$posted = date("jS M Y h:i",$r['posted']); echo "".$r['author']." $posted"; ?>
<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-text="<?php echo "".$r['message'].""; ?>">
Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
<div class="message2"><?php echo " ".$r['message'].""; ?></div>
<?php echo "Likes: ".$r['votes_up']." "; echo "Dislike: ".$r['votes_down']."";>
</div>
<br/>
<hr width="725px">
<?php
echo "<h3>Replies...</h3>"; ?>
<div class="message"><?php
$sql = mysql_query("SELECT * FROM replies WHERE thread = '".
mysql_real_escape_string($_GET['id']) . "'") or die(mysql_error());
while($r = mysql_fetch_array($sql)) {
$posted = date("jS M Y h:i",$r['posted']); echo "".$r['author']." $posted"; ?>
<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-text="<?php echo "".$r['message'].""; ?>">
Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
<div class="message2">
<?php echo " ".$r['message']."" ; } ?> </div>
</div>
<hr width="725px">
<form action="newreply.php" method="POST">
Your Name: <input type="text" name="author">
<input type="hidden" value="<?php echo $_GET['id']; ?>" name="thread"><br>
Message:<br><textarea cols="60" rows="5" name="message"></textarea><br>
<input type="submit" value="Post Reply">
</form>
The code looks really messy on here. I tried editing but couldnt get much better.
So bascially what i want to know is how do i prevent this (the overlapping) from happening?
Edit * CSS
.message {
width: 500px;
color: black;
background: white;
padding:8px;
border:1px solid white;
margin:5px auto;
-moz-border-radius:8px;
}
.message2 {
background-color: grey;
}
It looks to me as though everything is posting inside the second php function but i have some code pretty much the same for just the individual post and this displays normally i.e. as many as i want. Im just wondering is there something i need to add/change
Wrong (Your code):
<?php echo " ".$r['message']."" ; } ?> </div>
</div>
Correct:
<?php echo " ".$r['message']."" ; ?> </div>
</div>
<?php } ?>
You were opening multiple DIVs in your while loop but only closing two.
Similarly to Cobra_Fast's reply, it seems that the positioning of your divs seemed to be causing the problem, and also the position of your while loop.
Try replacing the replies section with the following and let me know if it is any better.
<?php
echo "<h3>Replies...</h3>";
$sql = mysql_query("SELECT * FROM replies WHERE thread = '".mysql_real_escape_string($_GET['id']) . "'") or die(mysql_error());
while($r = mysql_fetch_array($sql)) {
?>
<div class="message">
$posted = date("jS M Y h:i",$r['posted']);
echo $r['author']." ".$posted;
?>
<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-text="<?php echo $r['message']; ?>">
Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
</div>
<div class="message2">
<?php
echo " ".$r['message'];
?>
</div>
<?php
}
?>
Related
Morning/Afternoon/Evening,
I'm terrible with PHP. I finally got it to connect/pull the information that I wanted.
I used css to setup a grid of 3 cards.
I'm pulling Image/URL, Name, Age, State.
Right now when I load the page the every, with all three cards, hold the exact same information.
Example:
Page:
Ben Ben Ben
Janna Janna Janna
Steven Steven Steven
What I want:
Page:
Ben Janna Steven
Here is my PHP, and below the css.
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Covid-Deaths</title>
<link rel="stylesheet" type="text/css" href="main.css">
<script src="https://kit.fontawesome.com/1f285a5a86.js" crossorigin="anonymous"></script>
<script src="http://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<h1>You're terrible at this</h1>
<p>Get each picture to be unique</p>
<?php
//database Connection
include 'dbconfig.php';
// retrieving data from table accounts
$query = "SELECT * FROM test_info";
$result = mysqli_query($conn, $query);
?>
<?php
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
?>
<div class="grid-container">
<div class ="card">
<img src="uploaded-images/<?php echo $row['picture'];?>" width="80%"/>
<h4><?php echo $row['names']; echo ", "; echo $row['age'];?></h4>
<p><?php echo " "; echo "State: "; echo $row['state']; ?></p>
</div>
<div class ="card">
<img src="uploaded-images/<?php echo $row['picture'];?>" width="80%"/>
<h4><?php echo $row['names']; echo ", "; echo $row['age'];?></h4>
<p><?php echo " "; echo "State: "; echo $row['state']; ?></p>
</div>
<div class ="card">
<img src="uploaded-images/<?php echo $row['picture'];?>" width="80%"/>
<h4><?php echo $row['names']; echo ", "; echo $row['age'];?></h4>
<p><?php echo " "; echo "State: "; echo $row['state']; ?></p>
</div>
</div>
</div>
<?php
}
}
?>
</body>
</html>
And the CSS
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
grid-gap: 20px;
}
Again, I'm super new at this and can't quite figure out how to google the exact words. Would appreciate any help.
Inside the while loop change your code as below:
<?php
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
?>
<div class="grid-container">
<div class ="card">
<img src="uploaded-images/<?php echo $row['picture'];?>" width="80%"/>
<h4><?php echo $row['names']; echo ", "; echo $row['age'];?></h4>
<p><?php echo " "; echo "State: "; echo $row['state']; ?></p>
</div>
<?php
}
}
?>
Since you are having all state, name, age, image all information in one card and you are having that code in a while loop so you don't need the other cards.
$query = "SELECT * FROM test_info";
So if the above query result returns more than 1 row, then automatically multiple cards will be generated and information would be loaded in that.
remove the extra 2 card container since your are using a loop. Try this tutorials for a better understanding on how to fetch data using php and mysql
https://www.tutorialrepublic.com/php-tutorial/php-mysql-crud-application.php
I have an employee database which includes images as well as their work location (specialty). I have created a page where I fill out a form and upload the image to a directory and the path to the database. I then load the main page where I pull in all the images from the database (into the "photos" DIV. Everything works fine.
What I would like to do is reload the images in the DIV based on a MySQL query from a button. For example, instead of showing all employees, I only want to see those who have a specific job function i.e. Management. I currently have this accomplished by redirecting to a new page, where I run a specific query and that works fine as well. However, I'd like to learn how this is done without creating a new page for each query. I've spent many days looking at AJAX and PHP tutorials, which I how I was able to accomplish what I have, but I can't find a method to do what I want. This is the relevant part of my code:
Main.php
<div class="container-fluid">
<div class="row">
<div class ="col-lg-12" style="width: 18%; height: 100%; border:3px solid red;">
MANAGEMENT
HIGH
</div>
<?php
include ('db_connect.php');
//include_once ('functions.php');
$result = $db->query("SELECT * from monctonfir order by initials ASC");
if($result->num_rows > 0){
while ($row = $result->fetch_assoc()){
$imageURL = 'image/'.$row["file"];
$initial = $row["initials"];
$name = $row["name"];
?>
<div id="photos" class = "col-lg-1 no-gutters" style="margin-top:1rem;">
<div class="card text-center" style="width: 5rem;">
<a href = "#">
<img class="img card-img-top" src = "<?php echo $imageURL ?>">
</a>
<div class = "card-body">
<h5 class = "card-title round-button" style="text-align: center;"><?php echo $initial ?></h5>
</div>
</div>
</div>
<?php }
} ?>
</div>
Can someone point me in the right direction?
Thanks!
You don't need jQuery for what you are doing. You can use query/GET parameters to build your sql so you don't have to create a different page. Like:
<div class="container-fluid">
<div class="row">
<div class ="col-lg-12" style="width: 18%; height: 100%; border:3px solid red;">
MANAGEMENT
HIGH
ALL
</div>
<?php
include ('db_connect.php');
//include_once ('functions.php');
$sql = "SELECT * from monctonfir WHERE 1 ";
if(isset($_GET['job'])) $sql .= " AND job = '".$_GET['job']."' ";
$sql .= " order by initials ASC";
$result = $db->query($sql);
if($result->num_rows > 0){
while ($row = $result->fetch_assoc()){
$imageURL = 'image/'.$row["file"];
$initial = $row["initials"];
$name = $row["name"];
?>
<div id="photos" class = "col-lg-1 no-gutters" style="margin-top:1rem;">
<div class="card text-center" style="width: 5rem;">
<a href = "#">
<img class="img card-img-top" src = "<?php echo $imageURL ?>">
</a>
<div class = "card-body">
<h5 class = "card-title round-button" style="text-align: center;"><?php echo $initial ?></h5>
</div>
</div>
</div>
<?php }
} ?>
</div>
The simplest way is to use the load function of Jquery
Jquery
For example:
$( "#divID" ).load( "loadEmploye.php", { parameters1: 25, parameters2:3 });
I have problem with my (made with tutorial) PHP comment box.
The problem is this number 1. I think that problem is in last code, but as I am beginner I don't know where is problem.
I'm posting all 3 php files without header and footer file.
PrtSc of problem on page
Source code in chrome of page
This is full code in php....
First php file
<?php
$title = "FilmoviRecenzije";
$content = '
<img src="Slike_filmovi/novo_Mockingjay2.jpg" class="imgLeft"/>
<h2>The Hunger Games: Mockingjay - Part 2 (2015)</h2>
<p><i>"Žanr: Avantura, Znanstvena fantastika"</i></p>
<p>Režija: Francis Lawrence<p>
<h4>
U grand finalu spektakularne kino-hit franšize Igre gladi Katniss Everdeen (Jennifer Lawrence),
nakon što je postala vođa masovne pobune potlačenih, zajedno sa Distriktom 13 pokreće
sveopću revoluciju protiv autokratskog Kapitola. Katniss nastavlja svoju ulogu heroja
koji se u nevjerojatnoj bitci za preživljavanje bori za svoj narod!
</h4>
<dev class="videoCenter">
<iframe width="720" height="405" src="https://www.youtube.com/embed/n-7K_OjsDCQ" frameborder="0" allowfullscreen></iframe>
</dev>
';
include ('Template_Mockingjay2.php');
?>
Next file which is connected through "include" is:
<?php include('Header.php'); ?>
<div id="wrapper">
<div id="banner">
</div>
<nav id="navigation">
<ul id="nav">
<li>Početna </li>
<li>Novi Filmovi</li>
<li>Kontakt</li>
</ul>
</nav>
<div id="content_area">
<?php echo $content; ?>
</div>
<div id="sidebar">
<?php echo include('novo_Mockingjay2_komentar.php'); ?>
</div>
<?php include ("Footer.php"); ?>
And last file for Mysql, same included is:
<?php
mysql_connect("localhost","root","");
mysql_select_db("db_komentari");
if (isset($_POST['Ime']) && isset($_POST['Komentar'])){
// $Ime = isset($_POST['Ime']) ? $_POST['Ime'] :
$Ime = $_POST['Ime'];
$Komentar = $_POST['Komentar'];
$submit = $_POST['submit'];
$dbLink = mysql_connect("localhost","root","");
if($submit)
{
if($Ime&&$Komentar)
{
$insert=mysql_query("INSERT INTO novo_mockingjay2 (Ime,Komentar) VALUES ('$Ime','$Komentar') ");
echo "<meta HTTP-EQUIV='REFRESH' content='0; url=novo_Mockingjay2.php'>";
}
else
{
echo "Molim Vas ispunite oba polja";
}
}
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Komentari</title>
<center>
<form action="novo_Mockingjay2.php" method="POST">
<table>
<tr><td>Ime: <br><input type="text" name="Ime"/></td></tr>
<tr><td colspan="2">Komentar: </td></tr>
<tr><td colspan="5"><textarea name="Komentar" rows="1" cols="18"></textarea></td></tr>
<tr><td colspan="2"><input type="submit" name="submit" value="Objavi"></td></tr>
</table>
</form>
<?php
$dbLink = mysql_connect("localhost","root","");
$getquery=mysql_query("SELECT * FROM novo_mockingjay2 ORDER BY ID DESC");
while($rows=mysql_fetch_assoc($getquery))
{
$ID=$rows['ID'];
$Ime=$rows['Ime'];
$Komentar=$rows['Komentar'];
echo $Ime . ':<br/>' . $Komentar . '<br/>' . '<br/>' . '<hr size="4"/>';}
?>
Thank You in Advance!
As include language construct returns 1 on successful file including - this value is passed to your echo, so line:
echo include('novo_Mockingjay2_komentar.php');
means - include file, execute it and echo the result of inclusion. As result is 1 - it's echo'ed.
Change it to:
include('novo_Mockingjay2_komentar.php'); // without echo
<?php
session_start();
if (!isset($_SESSION['username'])) {
header('Location: LoginForm.php');
}
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Secured Page</title>
<style>
.db-table {position:absolute;top:95px;left:300px;}
</style>
</head>
<body>
<p align="left" style="margin-left:0px; margin-top:135px;">
<form action="Secured_Page_Search.php" method="post">
Select_Table_To_Display:<br><select name="Table">
<option value="members">Members</option>
<option value="online">Online</option>
<input type="submit" name="submit_name" />
</form>
<title>Secured Page</title>
<style type="text/css">
body{font-family:Impact;}
#container{width:10000px;margin:auto;font-size:15pt;}
#menu{position:absolute;margin-top:10px;}
#menu ul .item{display:none;}
#menu ul:hover .item{display:block;background:#white;padding:1px;margin:1px;}
#menu ul:hover .item a{color:#abc;text-decoration:none;}
#menu ul:hover .item a:hover{color:grey;}
#menu ul{width:110px;float:left;margin:0px;padding:2px;background:white;list-
Style:none;}
.clear{clear:both;height:10px;}
</style>
<div id="container">
<h1></h1>
<div id="menu">
<p align="left" style="margin-left:0px; margin-top: 0px;">
<br><FONT FACE="arial">Logged In #: (<?php echo $_SESSION['username']; ?>)</FONT></p>
</p>
<ul id="item1">
<li class="top">Profile</li>
<li class="item">Profile User</li>
<li class="item"><a href="#">Profile I.M.</li>
<li class="item">Profile O.P.</li>
</ul>
<ul id="item1">
<li class="top">Edit</li>
<li class="item">Edit User</li>
<li class="item"><a href="#">Edit I.M.</li>
<li class="item">Edit O.P.</li>
</ul>
</div>
<div class="clear"></div>
</body>
<br><FONT FACE="arial">
<?php
$Table = 'members';
$mysqli = new mysqli("XXXXXXXX", "XXXXXXXX", "XXXXXXXX", "XXXXXXXXXX");
$result = $mysqli->query("SHOW TABLES");
while ( $row = $result->fetch_row() ){
$table = $row[0];
$result1 = $mysqli->query("SELECT * FROM $Table ORDER BY dt DESC LIMIT 0,12");
if($result1) {
echo '<table cellpadding="15" cellspacing="20" class="db-table">';
$column = $mysqli->query("SHOW COLUMNS FROM $Table");echo '<tr>';
while($row3 = $column->fetch_row() ) {
echo '<th>'.$row3[0].'</th>';
}
echo '</tr>';
while($row2 = $result1->fetch_row() ) {
echo '<tr>';
foreach($row2 as $key=>$value) {
LINE 110 ----> echo '<td style="padding-top:0px;padding-bottom:0px;">',$value,'
'Edit'</td>;'<------Line 110
}
echo '</tr>';
}
echo '</table><br />';
}
}
$mysqli->close();
?>
<FONT FACE="impact">
<p align="left" style="margin-left:100px; margin-top:100PX;">
<form action="Secured_Page_Search_Email.php" method="post">
Search, Email:<br> <input type="text" name="email"><br>
<input type="submit" name="submit_name" />
</form>
<p align="left" style="margin-left:100px; margin-top:10px;">
<form action="Secured_Page_Search_User.php" method="post">
Search, User:<br> <input type="text" name="usr"><br>
<input type="submit" name="submit_name" />
</form>
</FONT></p>
</body>
</html>
Basically i need the mysql table to print with a edit link... Seems so easy, but have been battling with this issue the last few hours. Line that has an issue:
Basically i need the mysql table to print with a edit link... Seems so easy, but have been battling with this issue the last few hours. Line that has an issue:
LINE 110 ----> echo '<td style="padding-top:0px;padding-bottom:0px;">',$value,'
'Edit'</td>;'<------Line 110
UPDATED CODE UPDATED CODE
echo '<td>'Edit'</td>;'
Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in Secured_Page_Edit.php on line 113
echo '<td style="padding-top:0px;padding-bottom:0px;">'.$value.'
Edit</td>';
The way you concatenate text and variables is wrong. See http://php.net/manual/en/language.operators.string.php
You should write something like this:
LINE 110 ----> echo '<td style="padding-top:0px;padding-bottom:0px;">' . $value . '
Edit</td>;'<------Line 110
More precisely, mixing dots and comma is fine, but if you use single quotes with echo, you should make sure to put either a dot or a comma right after them (if you want to continue your string [1]) or a semicolon if you're done [2].
echo 'Text and '.$variable; // [1]
echo $variable.' and text'; // [2]
See also http://us.php.net/manual/en/function.echo.php.
Your php open/close tags are part of what is being echoed. As well as using commas rather then dots (.) to append the $value. However there is no reason to echo into the html string when already building the string in php.
echo '<td style="padding-top:0px;padding-bottom:0px;">',$value,''Edit'</td>;'
I think you want:
echo '<td style="padding-top:0px;padding-bottom:0px;">'.$value.'Edit</td>;'
// Changes are: ^ ^ ^ ^
UPDATE (Thanks Fred) You can in fact use commas to append a string in an echo call. So this would also be valid:
echo '<td style="padding-top:0px;padding-bottom:0px;">', $value, 'Edit</td>;'
I want to display post details ( title, description, username ) on my home page within a div tag in a proper format like all websites have. The problem I'm facing is that all the data from database are getting displayed as a plain text, one below the other. I am new to php, so please guide me to achieve the result.
Here is my code.
I want to display in this tag:
<div id='display'>
<h3 class='name'></h3>
<h1 class='title'></h1>
<p class='desc'></p>
<p class='cat'></p>
<p class='sub_cat'></p>
</div>
And my php code is:
<?php
$row="";
$link = mysql_connect("localhost","username","password");
mysql_select_db("database");
$query = "SELECT * from posts ORDER by post_id DESC limit 0,5";
$result = mysql_query($query);
$result = mysql_query($query) or die("Query to get blah failed with error:".mysql_error());
while($row = mysql_fetch_array($result)) {
echo "<div id='display'>";
echo "<h3 class='name'>".$row['username']."</h3>";
echo "<h1 class='title' >".$row['post_title']."</h1>";
echo "<p class='cat'>".$row['cat']."</p>";
echo "<p class='sub_cat'>".$row['sub_cat']."</p>";
echo "<p class='desc'>".$row['post_desc']."</p>";
echo "</div>";
}
mysql_close($link);
?>
I think what you are missing is some CSS. In HTML, DIV-Containers are displayed as block elements. So without any configuration, they are displayed one below the other. To get them next to each other, just add some CSS to your page:
<div id='display'>
<h3 class='name'></h3>
<h1 class='title' ></h1>
<p class='desc'></p>
<p class='cat'></p>
<p class='sub_cat'></p>
</div>
<div class="clear"></div>
<style type="text/css">
.name, .title, .desc, .cat, .sub_cat {
float:left;
}
.clear {
clear:both;
}
</style>