Put contents of PHP while loop code within a DIV - php

So I want to apply this DIV class to these PHP items.
This is what I have, I know it does not work, but what would be correct for what I am trying to achieve.
I cant add the class to each individually, as I want the entire contents to be within the one div.
Hope that makes sense, thanks!
<?php
while($campaigns= mysqli_fetch_assoc($result)){
<div class="feeditem">;
echo "<div class='field'>".$test['part0']."</div>";
echo "<div class='field'>".$test['part1']."</div>";
echo "<div class='field'>".$test['part2']."</div>";
echo "<div class='field'>".$test['part3']."</div>";
echo "<div class='field'>".$test['part4']."</div>";
echo "<div class='field'>".$test['part5']."</div>";
echo "<div class='field'>".$test['part6']."</div>";
</div>;
}
?>

You should use an IDE that gives you errors for syntax problems... You do not have all the html code wrapped in echo ""; statements.
while ($campaigns = mysqli_fetch_assoc($result)) {
echo '<div class="feeditem">';
echo "<div class='field'>" . $test['part0'] . "</div>";
echo "<div class='field'>" . $test['part1'] . "</div>";
echo "<div class='field'>" . $test['part2'] . "</div>";
echo "<div class='field'>" . $test['part3'] . "</div>";
echo "<div class='field'>" . $test['part4'] . "</div>";
echo "<div class='field'>" . $test['part5'] . "</div>";
echo "<div class='field'>" . $test['part6'] . "</div>";
echo '</div>';
}

I believe this is what you're trying to accomplish:
<?php
echo '<div class="feeditem">';
while($campaigns = mysqli_fetch_assoc($result)){
echo"<div class='field'>".$test['part0']."</div>";
echo"<div class='field'>".$test['part1']."</div>";
echo"<div class='field'>".$test['part2']."</div>";
echo"<div class='field'>".$test['part3']."</div>";
echo"<div class='field'>".$test['part4']."</div>";
echo"<div class='field'>".$test['part5']."</div>";
echo"<div class='field'>".$test['part6']."</div>";
}
echo '</div>';

Related

File existence check not working with is_uploaded_file and file_exists() function

I am trying to create a post system, where, if the user writes only text and doesn't upload an image, a blank image error should not appear (only plain text should appear after submitting).
So I have to check whether an image is uploaded or not.
The below code does the work of posting only Text.
while ($row = mysqli_fetch_array($result)) {
if (($_FILES['image1']['tmp_name'])==1){
echo "<br>";
echo "<div class='postuser'>";
echo "<div id='img_div1' class='caption'>";
echo "<p>".$row['image_text1']."</p>";
echo "<img src='images/".$row['image1']."' width='288px'>";
echo "</div>";
echo "</div>";
}
else
{
echo "<br>";
echo "<div class='postuser'>";
echo "<div id='img_div1' class='caption'>";
echo "<p>".$row['image_text1']."</p>";
echo "</div>";
echo "</div>";
}
}
PS: I have used file_exists() function and is_uploaded_file() function with both $_FILES['image1']['tmp_name'] and $_FILES['image1']['name'], tried many other ways, but to no help.
Hope nobody closes the question this time, please.
This code solved my query
while ($row = mysqli_fetch_array($result)) {
echo "<br>";
echo "<div class='postuser'>";
echo "<div id='img_div1' class='caption'>";
echo "<p>".$row['image_text1']."</p>";
if(!empty($row['image1']))
{
echo "<img src='images/".$row['image1']."' width='288px' height='250px' class='postedimg' >";
}
else
{
echo "";
}
echo "</div>";
echo "<p>".$row['sr']."</p>";
echo "</div>";
}
?>

SQL query not returning array

Working on getting a page to build off of an array that is returned from a DB to post a story, not sure what it is not working. The page URL looks like this: https://ohcrap.ninja/games/ps4/article.php?id=1
Here is the code that should be generating the content:
<?php
$id = $_GET['id'];
$query = mysqli_query($con,'SELECT * FROM `PS4` WHERE `id` =' .$id) or die(mysqli_error($con));
while ($row = mysqli_fetch_array($query));
// Echo page content
echo "<div class='col s12 m12 l12'>";
echo "<div class='card small grey darken-3'>";
echo "<div class='card-stacked'>";
echo "<div class='card-content'>";
echo "$id";
echo "<span class='card-title'>" . $row['title'] . "</span>";
echo "<hr color='black'>";
echo "<P>By:<i> " . $row['author'] . "</i></P>";
echo "<P>Published: " . $row['published'] . "</P>";
echo "<br>";
echo "<P class='truncate'>" . $row['story'] . "</P>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
?>
Your while loop is not doing anything useful, because you're immediately ending it with that ;.
while ($row = mysqli_fetch_array($query)) {
// all those echoes
}

Thumbnails not aligning in a single row

I'm trying to create a row with 3 thumbnails on it, the problem is it is not aligning in a single row, but instead every thumbnail goes in different row.
echo "<table>";
echo "<tr>";
echo "</tr>";
while($row=mysqli_fetch_array($result)){
echo "<div class=\"container\">";
echo "<div class=\"row-fluid\">";
echo "<div class=\"col-md-4\">";
echo "<div class=\"thumbnail\">";
echo "<img alt=\"News\" src=\"images/{$row["image"]}\">";
echo "<div class=\"caption\">";
echo "<h3>{$row["title"]}</h3>";
echo "<p>{$row["caption"]}</p>";
echo "<p align=\"right\">";
echo "<a class=\"btn btn-primary\" href=\"{$row["newsupdate"]}\">Read More</a>";
echo "</p>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
try this it might work
echo "<table>";
echo "<tr>";
while($row=mysqli_fetch_array($result)){
echo "<img alt=\"News\" src=\"images/{$row["image"]}\">";
echo "<div class=\"caption\">";
echo " <td> <h3>{$row["title"]}</h3> </td> ";
echo "<td><p>{$row["caption"]}</p></td>";
echo "<td> <a class=\"btn btn-primary\" href=\{$row["newsupdate"]}\">Read More</a>";
echo "</td>";
}
echo "</tr>";
echo "</table>";

Selecting data from sql to create a thumbnail

I'm creating a thumbnail with a title, image and caption on it. I'm trying to select data from my table to show it into my homepage. Can someone help me to create a normal thumbnail in my php that contains the detail from my sql. I tried to search and can't find how to create a thumbnail using php and not html.
$sql = "SELECT * FROM news";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr>";
echo "<th>id</th>";
echo "<th>first_name</th>";
echo "<th>last_name</th>";
echo "<th>email</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['title'] . "</td>";
echo "<td>" . $row['image'] . "</td>";
echo "<td>" . $row['caption'] . "</td>";
echo "</tr>";
}
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
In short, is there a way to create a php file from this?
<div class="col-md-4">
<div class="thumbnail">
<img alt="Memory" img src="../../images/a2.jpg">
<div class="caption">
<h3><b>
Title
</b></h3>
<p>
Caption Caption Caption Caption Caption
</p>
<p align="right">
<a class="btn btn-primary" href="news2.html">Read More</a>
</p>
</div>
</div>
</div>
Do you want to replace your table structure with that template structure? You'll need to adjust some of the data to fill the hyperlink (I don't know how you want to build that).
while($row=mysqli_fetch_array($result)){
echo "<div class=\"col-md-4\">";
echo "<div class=\"thumbnail\">";
echo "<img alt=\"Memory\" src=\"../../images/{$row["image"]}\">";
echo "<div class=\"caption\">";
echo "<h3>{$row["title"]}</h3>";
echo "<p>{$row["caption"]}</p>";
echo "<p align=\"right\">";
echo "<a class=\"btn btn-primary\" href=\"news2.html\">Read More</a>";
echo "</p>";
echo "</div>";
echo "</div>";
echo "</div>";
}

Lightbox not showing php

I'm working for a system by the use of php. We have an admin.php page where all the list of applicants were listed. And we want that when we click on a specific applicant's name, a lightbox would appear that will show more information about the applicant. But, these codes below seems to be not working and I don't know why. I am a newbie in php btw.
<?php
include('config.php');
$result = mysql_query("SELECT * FROM employee as t1")
or die(mysql_error());
echo "<table border='0' cellpadding='15' text-align = 'center' >";
echo "<tr>";
echo " <caption><b><font size = '5'> <h2>List of Applicants </h2> </b> </font><hr></caption>";
echo "<th>Applicant ID</th>";
echo "<th>Application Date</th>";
echo "<th>Name</th>";
echo "<th>Job</th>";
echo "</tr>";
while($row = mysql_fetch_array( $result ))
{
echo "<tr class='gradeC'>";
echo '<td><b><font color="#663300">' . $row['employee_id'] . '</font></b></td>';
echo '<td><b><font color="#663300">' . $row['date'] . '</font></b></td>';
echo '<td><b><font color="#663300">' . $row['fname'] . '</font></b></td>';
echo '<td><td>';
echo "</tr>";
}
echo "</table>";
function runMyFunction() {
echo "<div onclick =\"document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'\"></div>";
echo "<div id=\"light\" class=\"white_content\">This is the lightbox content. Close</div>";
echo "<div id=\"fade\" class=\"black_overlay\"></div>";
}
if (isset($_GET['hello'])) {
runMyFunction();
}
?>
I'm not sure but I think the problem is in the function, or the way I'm using the codes for lightbox to appear.
Can you rewrite this line
function runMyFunction() {
echo "<div onclick =\"document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'\"></div>";
echo "<div id=\"light\" class=\"white_content\">This is the lightbox content. Close</div>";
echo "<div id=\"fade\" class=\"black_overlay\"></div>";
}
to
function runMyFunction() {
?>
<div onclick ="document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'"></div>
<div id="light" class="white_content">This is the lightbox content.
Close</div>
<div id="fade" class="black_overlay"></div>
<?php }
By eliminating the slashes could help make the code easier to process.
I hope this help.

Categories