Resize Images in php - php

I am having problem in resizing pictures. to show the uploaded images i have saved their path in database table and code to show images is:
$result = mysql_query("SELECT * FROM photos");
while($row = mysql_fetch_array($result))
{
$name = 'name';
echo '<div id="imagelist">';
echo '<p ><img src="timthumb.php?src="' .$row['location']. '"&w=100&h=80"/></p>';
echo '</div>';
echo '<div id="imagelist">';
echo '<p>' .$row['id']. '</p>';
echo " ";
echo '<p><b>Location:</b>' .$row['location']. '</p>';
echo '<p><b>File Name:</b>' .$row['name']. '</p>';
echo '<p><b>ID:</b>' .$row['au_id']. '</p>';
echo '<p><b>Position:</b>' .$row['position']. '</p>';
echo '<p><b>Contace info:</b>' .$row['contact']. '</p>';
echo '</div>';
}
I am using timthumb and .$row['location']. has values like "photos/image.png". Page is unable to show the pictures, am I usning timthumb correctly?

echo '<p ><img src="timthumb.php?src="' .$row['location']. '"&w=100&h=80"/></p>';
Remove " " from URL:
echo '<p ><img src="timthumb.php?src=' .$row['location']. '&w=100&h=80"/></p>';

Related

how to make image as clickable to submit image id to a php file?

I have something like this
while($row = $result->fetch(PDO::FETCH_ASSOC)){
echo '<div class="container">';
$i=0;
while($i<3){
echo '<div class="row">';
echo '<div class="col-sm-4">';
echo '<div class="panel panel-primary">';
echo '<div class="panel-body"><img src="';
echo $row['imageurl'];
echo '"class="img-responsive" style="width:250px" style="height:250px" alt="Image"></div>';
echo '<div class="panel-footer">';
echo $row['name'];
echo '</div></div></div>';
$i++;
}
}
I want to click the image so that it calls a new PHP file with the image id.
To view the output http://csedu.cf/test.php
Try to put your image tag in a tag.
while($i<3)
{
echo '<div class="row">';
echo '<div class="col-sm-4">';
echo '<div class="panel panel-primary">';
echo '<div class="panel-body"><a href="test.php?id=image_id"><img src="';
echo $row['imageurl'];
echo '"class="img-responsive" style="width:250px" style="height:250px" alt="Image"></div>';
echo '</a><div class="panel-footer">';
echo $row['name'];
echo '</div></div></div>';
$i++;
}

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
}

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.

Deleting status post using Ajax POST request

how do i delete a single record in database? i tried with Ajax and it didn't work.here is my code,each row has a unique number ID,so i need that to delet it,but i don't know how to get it.
echo '<tr>';
echo '<td>';
echo '<a href="korisnik.php?id='.$session_poster_id.'">';
echo '<div class="profile_pic_div" style="margin-top:10px;">';
echo "<img src='$avatar' style='width:40px;height:40px;'>";
echo '</div>';
echo '</a>';
echo '<div class="timestamp" style="margin-left:50px;margin-top:-43px;font-size:15px;">';
echo $user['vrijeme'];
echo '</div>';
echo '<a href="delete.php?post_id='.$post_id.'">';
echo '<div class="icon-x" style="margin-left:550px;margin-top:-15px;">';
echo '</div>';
echo '</a>';
echo '<div class="post_div" style="margin-top:30px;">';
if (strlen($user['post']) > 500) {
$user['post'] = substr($user['post'], 0, 500);
$user['post'] = substr($user['post'], 0, strrpos($user['post'], ' ')).'... Read More';}
echo $user['post'];
echo '</div>';
echo '<br>';
echo 'Komentiraj';
echo '</td>';
echo '</tr>';
DELETE FROM Name_of_your_table
WHERE Columname = your_value;
see w3schools delete query
PS. What is in your delete.php ?

Compare MySQL result in PHP

I had retrieve some result from database and want to display the result separately.
If the pb_title is same as temp_title then put it togather in a red color div
else is pb_title is not same as temp_title then put it in grey color div
Here my tried code :
$select_brand = "SELECT * FROM tblProduct_Brand WHERE pb_display='display'";
$result = mysqli_query ($mydatabase, $select_brand);
if($result)
{
while($row = mysqli_fetch_array($result))
{
$pb_feature_image = substr(($row['pb_feature_image']),3);
$pb_logo = substr(($row['pb_logo']),3);
$temp_result;
if($temp_result == $row["pb_title"])
{
//if product brand title is same, put it in same area
echo '<div style="padding:20px; background-color:red;">';
echo '<div style="display:inline-block;width:340px;height:250px;vertical-align:top;">';
echo '<img src="'.$pb_feature_image.'" width="100%" height="100%"/>';
echo '</div>';
echo '<div style="display:inline-block;width:330px;height:250px;padding-left:10px;">';
echo '<div style="height:40px;width:80px;float:right">';
echo '<img src="'.$pb_logo.'" width="100%"/>';
echo '</div>';
echo '<div style="clear:both"></div>';
echo '<a class="product-content">'.$row["pb_content"].'</a>';
echo '</div>';
echo '</div>';
$temp_result = $row["pb_title"];
}
else
{
//if not same, put in another area
echo '<div style="padding:20px; background-color:grey;">';
echo '<div style="display:inline-block;width:340px;height:250px;vertical-align:top;">';
echo '<img src="'.$pb_feature_image.'" width="100%" height="100%"/>';
echo '</div>';
echo '<div style="display:inline-block;width:330px;height:250px;padding-left:10px;">';
echo '<div style="height:40px;width:80px;float:right">';
echo '<img src="'.$pb_logo.'" width="100%"/>';
echo '</div>';
echo '<div style="clear:both"></div>';
echo '<a class="product-content">'.$row["pb_content"].'</a>';
echo '</div>';
echo '</div>';
}
}
Any mistake about the code please correct me.
Thanks.
The following code assumes that you did something like this with the data you fetched from the sql query:
$data = array();
while($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
Which returns an array like this:
Array (
[0] => Array(
'pb_title' => '',
'pb_content' => '',
//...etc
),
//.....etc
)
Now assuming that I understand your question correctly, you'd want to do something like this:
$i = array();
$key = 'A';
foreach ($data as $item) {
if ($item['pb_title'] == $key) {
$i['red'][] = $item;
} else {
$i['grey'][] = $item;
}
}
Which gives you an array of red (Matching) and grey (Not Matching).
Which you can loop through and generate your div's appropriately.
Something like this (pseudo code)
echo '<div style="padding:20px; background-color:red;">';
foreach($i['red'] as $row) {
echo '<div style="display:inline-block;width:340px;height:250px;vertical-align:top;">';
echo '<img src="'.$pb_feature_image.'" width="100%" height="100%"/>';
echo '</div>';
echo '<div style="display:inline-block;width:330px;height:250px;padding-left:10px;">';
echo '<div style="height:40px;width:80px;float:right">';
echo '<img src="'.$logo.'" width="100%"/>';
echo '</div>';
echo '<div style="clear:both"></div>';
echo '<a class="product-content">'.$row["pb_content"].'</a>';
echo '</div>';
}
echo '</div>';
Example
$temp_result;
if($temp_result == $row["pb_title"])
Before checking the condition you should have assigned some value to $temp_result , but you haven't and you are comparing it anyway.
EDIT :
What I understand is that initially you have not set any value of $temp_result and it is always coming in your Else Block where you do'not assign $temp_result = $row["pb_title"]; , So that it shoudl store the previous value , you only did it in the If Block , you need to place the same code in your else block too..
Simple Edit this section in your code
else
{
//if not same, put in another area
echo '<div style="padding:20px; background-color:grey;">';
echo '<div style="display:inline-block;width:340px;height:250px;vertical-align:top;">';
echo '<img src="'.$pb_feature_image.'" width="100%" height="100%"/>';
echo '</div>';
echo '<div style="display:inline-block;width:330px;height:250px;padding-left:10px;">';
echo '<div style="height:40px;width:80px;float:right">';
echo '<img src="'.$pb_logo.'" width="100%"/>';
echo '</div>';
echo '<div style="clear:both"></div>';
echo '<a class="product-content">'.$row["pb_content"].'</a>';
echo '</div>';
echo '</div>';
$temp_result = $row["pb_title"]; // added this to save previous result
}
Make sure that programing should be effective for that you need to have following ideas:
1) Here you no need to use if($result) because when the sql results are true then only it will allow inside the condition
2) While programing try to avoid more if else condition for making efficient.
<?php
$select_brand = "SELECT * FROM tblProduct_Brand WHERE pb_display='display'";
$result = mysqli_query ($mydatabase, $select_brand);
while($row = mysqli_fetch_array($result))
{
$pb_feature_image = substr(($row['pb_feature_image']),3);
$pb_logo = substr(($row['pb_logo']),3);
$temp_result;
if($temp_result == $row["pb_title"]) { $style = 'style="padding:20px; background-color:red;"'; }
else { $style = ' style="padding:20px; background-color:grey;"'; }
echo '<div '.$style.' >';
echo '<div style="display:inline-block;width:340px;height:250px;vertical-align:top;">';
echo '<img src="'.$pb_feature_image.'" width="100%" height="100%"/>';
echo '</div>';
echo '<div style="display:inline-block;width:330px;height:250px;padding-left:10px;">';
echo '<div style="height:40px;width:80px;float:right">';
echo '<img src="'.$pb_logo.'" width="100%"/>';
echo '</div>';
echo '<div style="clear:both"></div>';
echo '<a class="product-content">'.$row["pb_content"].'</a>';
echo '</div>';
echo '</div>';
$temp_result = $row["pb_title"];
}
?>

Categories