How to make a userfeed scroll on a new mysql input? - php

I'm trying to make a userfeed for the homepage of my website that displays new information from users, for example: user x just did somthing.
This is what it looks like sofar: Image of page
this is the code used on the page:
if ($result->num_rows > 0) {
// output data of each row
while ($row = $result->fetch_assoc()) {
echo '
<div class="media testimonial-inner">
<div class="pull-left">
<img class="img-responsive img-square" src="images/bierportaal.jpg" height="66" width="66">
</div>
<div class="media-body">
<span><a href="' . $row["naam"] . '"target=main>' . $row["naam"] . '</a></span>
<span>' . $row["tekst_before"] . '</span><a href="' . $row["item"] . '"target=main>' . $row["item"] . '</a>
<span>' . $row["tekst_after"] . '</span>
</div>
</div>
';
}
} else {
}
$db_conx->close();
?>
My question is, How do I rotate trough the activities?
So that when someone does somthing (it will be inserted into the database)the records jump and the top one will display a new record and the bottom one wil move out of the screen/disapear.
An example of what i have in mind is on this website the activetyfeed:
ratebeer website
Kind regards,
Aerosteon

Related

How to load data from MYSQL server with PHP while when loading the website

I have a html file showing a quiz webside with questions and answers and a php file getting the questions from my local mysql server.
The html file and the php file are working fine, but now I want to get the data from the server when the side is loaded and put the data into the right buttons and labels (Loading a question and the answers and display it on my prefabricated html file).
This is my php code how i get the question from my database:
$round = $_POST['round'];
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}else{
$sql = "select * from questions where round = $round order by rand()
limit 1;";
while($row = mysql_fetch_assoc($sql)) {
echo $row['id'] . " " . $row['category'] . " " . $row['round'] .
" " . $row['question'] . " " . $row['rightanswer'] . " " .
$row['wronganser1'] . " " . $row['wronganser2'] . " " .
$row['wronganser3'];
}...
and this is my html file displaying the label and buttons with the question and answers:
<div id="question">
<h4 id="category">Kunst und Literatur</h4>
<p style="margin-bottom: 0px" class="question">Question=</p>
</div>
<ul id="answers">
<li id="answer1" class="button">Answer1</li>
<li id="answer2" class="button">Answer2</li>
<li id="answer3" class="button">Answer3</li>
<li id="answer4" class="button" style="margin-bottom: 0px">Answer4</li>
</ul>...
Instead of "Question" and "Answer1","Answer2"... i want the data loaded from my server.
I appreciate every idea and if anything is unclear don't hesitate to ask.
Thanks :)
If you need to put some content from the database into your webpage you can just replace the HTML code like that:
<div id="question">
<h4 id="category">Kunst und Literatur</h4>
<p style="margin-bottom: 0px" class="question"><?php echo $row['question']; ?></p>
</div>
<ul id="answers">
<li id="answer1" class="button"><?php echo $row['answer1']; ?></li>
<li id="answer2" class="button"><?php echo $row['answer2']; ?></li>
<li id="answer3" class="button"><?php echo $row['question']; ?></li>
<li id="answer4" class="button" style="margin-bottom: 0px">Answer4</li>
</ul>...
If you want to make a site with more questions just wrap your while loop over the HTML code.

show custom fields data in next and previous link in wordpress

I am trying to show a advanced custom fields data in previous post link in wordpress. But The data is not showing also it breaks the html as well.
<div class="prev-posts pull-left">
<?php
$prev_post = get_previous_post();
if($prev_post) {
$prev_title = strip_tags(str_replace('"', '', $prev_post->post_title));
echo "\t" . '<a rel="prev" href="' . get_permalink($prev_post->ID) . '" title="' . $prev_title. '" class=" ">
<strong>
<<< "'. $prev_title . '"
</strong>
<img src="'.the_field("girl_image").'" alt="'.the_title().'/>
</a>' . "\n";
}
?>
</div>
In this code the "girl_img" field contains the URL of an image. I want to show the image based on the URL. But it is showing the URL itself instead of showing the image.
Use get_field() instead of the_field().
get_field() = Returns the value of the specified field.
the_field() = Displays the value of the specified field. This function is the same as echo get_field($field_name);
Replace the_field("girl_image") with get_field("girl_image")

jQuery and CSS not working when generated from PHP

I'm trying to create a follow button (like twitter) and it's largely working, however when I generate the HTML from PHP script it's not.
Here's the fiddle to show it working: http://jsfiddle.net/MCam435/HpAWH/10/
Works wonderfully :)
However when I generate it from PHP:
PHP Script
function getTalent($row) {
return "<div class='talent_result_wrapper' data-experience='" . $row['divTagExp'] . "' data-salary='" . $row['divTagSal'] . "'>
<div class='talent_result_header'>
<span class='talent_result_head'>ID: </span>" . $row['CandidateID'] . "
</div>
<ul>
<li><strong>Resides: </strong>" . $row['Town'] . "</li>
<li><strong>Salary Required: </strong>£" . $row['SalaryMin'] . "</li>
<li><strong>Experience: </strong>" . $row['CandidateExperience'] . " Years </li>
<li><strong>Industy: </strong>" . $row['PrimarySector'] . "</li>
<li><strong>Specialism: </strong>" . $row['PrimarySector'] . "</li>
<br>
<div id='follow1'><a href='#' class='follow' id='1'><span class='follow_b'> + Tag </span></a></div>
<div id='remove1' style='display:none'><a href='' class='remove' id='1'><span class='remove_b'> - UnTag </span></a></div>
</div>";
}
Main Page
while($row = mysqli_fetch_array($result2)) {
echo getTalent($row);
}
The switching between div's doesn't work, even though the output is exactly the same?
You can't have multiple elements with the same ID on a page.
<div id='follow1'><a href='#' class='follow' id='1'><span class='follow_b'> + Tag </span></a></div>
<div id='remove1' style='display:none'><a href='' class='remove' id='1'><span class='remove_b'> - UnTag </span></a></div>
You need to give those elements all unique IDs. It will work if there is only 1 instance of this on the page, but as soon as you add more than 1 it will start to fail. That's why it works in your example, but not when you use PHP.

Show first 5 items in list, hide/toggle display of others (PHP)

I'd like to show the first 5 names in a list and toggle the display of any additional names as a single block.
I've currently got the names list as an array object though I'm happy to change it to an array if the solution would be simpler with that.
Here's what I have so far which is *in*complete because I don't know how to create the hidden div of names:
PHP
$names_count=0;
echo '<div id='nameList' class='toggler'>';
foreach($names as $name){
echo '<a id='name'.$name->acct_id.'>'.$name->full_name.'</a>';
if($names_count<=4){
echo '</div><!--toggler div-->';
}
else
<div class='namesList' style='display:none'>
//put additional names in hidden div?
</div>
}
$names_count++;
} //endforeach
JS:
UPDATE Sorry for the confusion. This isn't really a javascript question so I deleted that tag but I'm including the following jQuery code snippet for completeness with the PHP
$('.toggler').click(function(){
var id=this.id;
$('#'+id).toggle();
});
PHP
$names_count = 0;
echo '<div id="nameList" class="toggler">';
foreach($names as $name) {
echo '<a id="name' . $name->acct_id . '">' . $name->full_name . '</a>';
if ($names_count == 4) {
echo '</div><div class="hidden">';
}
$names_count++;
}
echo '</div>';
JS
$('.toggler').click(function(){
$(this).next().toggle();
});
CSS
.hidden {
display: none;
}
Here's an example with two while loops.
$names = array('Bob', 'Andy', 'Tim', 'Max', 'Roger', 'John', 'Test');
$nameCount = count($names);
$nameIndex = 0;
echo '<div id="nameList" class="toggler">';
// Show the first 5 names.
while ($nameIndex < min(5, $nameCount)) {
$name = $names[$nameIndex++];
echo '<a id="name' . $name . '">' . $name . '</a>';
}
// Show the remaining names in a hidden div.
if ($nameIndex < $nameCount)
{
echo '<div class="hiddenNames" style="display:none">';
while ($nameIndex < $nameCount) {
$name = $names[$nameIndex++];
echo '<a id="name' . $name . '">' . $name . '</a>';
}
echo '</div>';
}
echo "</div>";
That code produces the following output.
<div id="nameList" class="toggler">
<a id="nameBob">Bob</a>
<a id="nameAndy">Andy</a>
<a id="nameTim">Tim</a>
<a id="nameMax">Max</a>
<a id="nameRoger">Roger</a>
<div class="hiddenNames" style="display:none">
<a id="nameJohn">John</a>
<a id="nameTest">Test</a>
</div>
</div>
It also safe if you have less than 5 names; the script would produce :
<div id="nameList" class="toggler">
<a id="nameBob">Bob</a>
<a id="nameAndy">Andy</a>
<a id="nameTim">Tim</a>
</div>
For the JS, I would probably do something along the lines of :
$('.toggler').click(function(){
$('.hiddenNames').toggle();
});
Even if the code is a bigger, I find it easier to follow and probably easier to maintain in the long run. (Opinion)
Hope this helps!
To make a <div> hidden:
<div style="display: hidden"></div>
Then the jQuery should make it visible with the .toggle() command.

Steam Login script won´t work

I tried to use the steam-login script of github on my php file.
I used a custom button instead of the official steam button.
The situation is: I press the button and i get to the standard localhost/dashboard site, I'm simulating it over XAMPP.
Script to login to steam, adding a trade link of your steam account, showing your profile and logging out at the end.
<?php
if(!isset($_SESSION["steamid"])) {
steamlogin();
echo '<a class="ezpz-loginas" style="font-size: 12px;border: 2px solid #db073d;margin: 60px auto 0px;padding-top: 22px;" href="/?login">CONNECT TO STEAM</a>';
} else {
echo '<article class="jfrs clearfix">
<img src="' . $steamprofile['avatarfull'] . '" height="74" width="74" alt="">
<p>' . $steamprofile['personaname'] . ' Logout</p>
<ul class="clearfix">
<li>Where can I find my Trade-URL?</li>
</ul>
</article>
<form method="POST" action="./updatelink.php">
<input type="text" class="main-link" name="link" id="link" value="' . $mytrade . '" placeholder="Set Trade-URL">
<input type="submit" class="main-link-check" href="#" value="">
</form>';
mysql_query("UPDATE users SET name='" . $steamprofile['personaname'] . "', avatar='" . $steamprofile['avatarfull'] . "' WHERE steamid='" . $_SESSION["steamid"] . "'");
}
?>
I edited the steamauth files in the right way.
P.S.: Sorry for my english skills.

Categories