PHP Private Message Reply Function - php

What I have is a reply script, and I need the page to only use the username echo'd in for a variable, like if Meap sends me a PM and I want to reply to it, when I hit the reply link I need it to use his name, and not another name from the page. Currently it is using the first name on the page instead of the one that the reply link is for
Here's the code;
while ($row = mysqli_fetch_array($data)) {
session_start();
$reply = $row['from'];
echo '<div class="viewpost">';
echo '<div class="vpside">';
if(!empty($row['picture'])) {
echo '<img class="pictest" src="' . MM_UPLOADPATH . $row['picture'] . '" alt="' . MM_UPLOADPATH . 'nopic.png' . '" />';
}
if(!empty($row['from'])) {
echo '<p>From:<br />' . $row['from'] . '</p>';
$_SESSION['reply'] = $row['from'];
echo 'Reply';
}
if(!empty($row['rank'])) {
echo '<p>Rank:<br />' . $row['rank'] . '</p>';
}
if(!empty($row['gender'])){
echo '<p>Gender:<br /> ' . $row['gender'] . '</p>';
}
echo '</div>';
if(!empty($row['title'])) {
echo'<h4><u>' .$row['title']. '</u></h4>';
}
if(!empty($row['msg'])) {
echo '<p class="">' . $row['msg'] . '</p>';
}
echo '<div class="sig">';
if(!empty($row['bio'])) {
echo '<p>' . $row['bio'] . '</p>';
}
echo '</div>';
echo '</div><br />';
}
Here's a picture of what it looks like when you get a Private Message;
Evidently you have to be specific down to the last detail on here, the question - or rather the problem - is that it is not using the correct recipient for the reply. Say I click reply under Meaps name, it will use Lilpunish instead. Basically it will use the first one loaded, and I need it to use the correct username. How would I do this.?

Here's your problem:
$_SESSION['reply'] = $row['from'];
echo 'Reply';
Consider what is happening when this code is run multiple times. The first time, it sets the session variable reply to Meap. The next time, when the second message is printed, it sets it to another value.
What you actually want is to pass who to reply as a part of the link, e.g.
echo 'Reply';
And then not retrieve the reply-to from $_SESSION. Session variables are not really supposed to be used like this.

Related

PHP -displaying 12 items of an associative array with specific key and value

<?php
foreach($catalog as $id=> $item) {
echo get_item_html($id,$item);
}
// here is the functions page code :
function get_item_html($id,$item){
$output = "<li><a href='#'><img src='"
. $item["img"] . "' alt='"
. $item["title"] . "' />"
. "<p>View Details</p>"
. "</a></li>";
return $output;
}
?>
I have used it for displaying product categories i checked several time but I did find any error but it display undefined variable
please help me to find out this solution

PHP concatenation issues

So I am really bad at concatenation Ive been working on it for an hour the best i can get this to do is no errors butit doesnt echo the username for some reason I am pretty sure it has to do with concatenation anyway.
Code:
echo '<span style="color: #"' . $row['color'] . ';"';
echo $row['user'] . ': ' . '</span>' . $row['message'] . '';
echo '</br>';
Basically I am trying to make the username show the color of the the hex in database. But when I do this it doesnt even show the username just the message.
echo '<span style="color: #' . $row['color'] . ';">'
. $row['user'] . ': </span>' . $row['message']
. '</br>';
You didn't close the <span> tag.
You can also just output the entire string and interpolate the values:
echo "<span style=\"color:#{$row['color']}\">{$row['user']}:</span> {$row['message']}<br>";

Why is this 1 image showing an infinite number of times?

$pgroup = $Sys->db->query("SELECT dj_photo_group.photo_group, dj_photo.name FROM dj_photo_group, dj_photo WHERE dj_photo_group.photo_group = dj_photo.img_group ORDER BY dj_photo.img_group DESC");
while($photo = $pgroup->fetch_object()) {
echo '<div class="photo_head">' . ucfirst($photo->photo_group) . '</div>';
echo '<div class="photo_sub">';
while($photo->name) {
echo '<img src="photogallery/' . $photo->photo_group . '/' . $photo->name . '" />';
}
echo '</div>';
}
This is showing the same 1 image over and over again. I have 3 groups: Wedding, 5points and Misc that have 2 images each. It only shows Weddings with 1 image infinite number of times.
What am I doing wrong and how can I fix it?
$photo->name is always true. So if you use it in a while loop, you're essentially saying:
while(true){
// do this
}
Remember, while loops will keep going as long as the condition specified is true.
You should really be using an if statement instead.
if($photo->name){
// do this
}
while($photo->name) will repeat until $photo->name is false. Because in the loop there is nothing that will change it, it will always be true, and so the loop continues forever.
Like Nishant said, you want to replace it with an if statement.
while($photo->name) is entering into infinite loop as the condition is always true. You should put an end condition to this while loop or otherwise you can go for if condition also
if($photo->name)
Try this.. this solution will provide you your desired layout....
$pgroup1 = $Sys->db->query("SELECT dj_photo_group FROM photo_group GROUP BY dj_photo_group");
while ($photo1 = $pgroup1->fetch_object())
{
echo '<div class="photo_head">' . ucfirst($photo1->dj_photo_group) . '</div>';
echo '<div class="photo_sub">';
$pgroup2 = $Sys->db->query("SELECT name FROM dj_photo WHERE img_group = '$photo1->dj_photo_group'");
while ($photo2 = $pgroup2->fetch_object())
{
echo '<img src="photogallery/' . $photo1->dj_photo_group . '/' . $photo2->name . '" />';
}
echo '</div>';
}

PHP Conditional Field Display Joomla

Basically I need to call a field (wrapped in a div) if the field has a value. I do not want the field or div to display if the field has no value. My PHP knowledge is dire but here is what I have to work with.
Here are instructions provided to me on how to call a custom field by ID:
$cust_1 = $this->fields->getFieldByCaption('Custom Text'); // getFieldByCaption() allow you to get the field by the Caption. This is not the best way to get a field since changing the caption in the back-end will break the reference.
echo '<br />Field ID: ' . $cust_1->getId();
$cust_2 = $this->fields->getFieldById(29); // getFieldById() is the ideal way of getting a field. The ID can be found at 'Custom Fields' section in Mosets Tree's back-end.
echo '<br />Name: ' . $cust_2->getName();
echo '<br />Has Caption? ' . (($cust_2->hasCaption()) ? 'Yes' : 'No');
echo '<br />Caption: ' . $cust_1->getCaption();
echo '<br />Value: ' . $cust_2->getValue();
echo '<br />Output: ' . $cust_2->getOutput(1);
echo '<hr />';
$this->fields->resetPointer();
while( $this->fields->hasNext() ) {
$field = $this->fields->getField();
echo '<br /><strong>' . $field->getCaption() . '</strong>';
echo ': ';
echo $field->getOutput(1); // getOutput() returns the formatted value of the field. ie: For a youtube video, the youtube player will be loaded
// echo $field->getValue(); // getValue() returns the raw value without additional formatting. ie: When getting value from a Online Video field type, it will return the URL.
$this->fields->next();
}
Here is the code I am working with and need help to try and do what I need it to as detailed above:
<?php
if( !is_null($this->fields->getFieldById(35)) ) {
$value = $field->getValue();
$hasValue = $field->hasValue();
$field = $this->fields->getField();
if( $hasValue )
{
echo '<div class="lin" id="lphn">'; {
echo $cust_2 = $this->fields->getFieldById(35);
echo $cust_2->getOutput(1);
echo '</div>';
}
else {
// Print nothing.
}
}
}
?>

Attributes running together or a URL query string in an unquoted attribute value

When running validator I am receiving this error. Alos, Internet Explorer 8 fails to load my sidebar in position. What I made wrong here ? TNX
global $layout;
echo '<div id=\"main\" role=\"main\" class=\"layout_" . $layout . "\">';
echo '<section id="content" class="grid_8 background_1">';
echo '<a id="main_btn" href="#"></a>';
echo '<div class="clearfix">';
echo '</div></div></div></div>';
The OUTPUT of line 2 is:
<div id=\"main\" role=\"main\" class=\"layout_" . $layout . "\">
Somehow, I doubt that's what you actually want. Try this instead:
echo "<div id=\"main\" role=\"main\" class=\"layout_" . $layout . "\">";

Categories