Jump to content


Check out our Community Blogs

Bertan

Member Since 08 Sep 2010
Offline Last Active Jan 29 2012 06:54 AM
-----

Topics I've Started

Get count of different values in the same column

21 January 2012 - 10:50 AM

I been trying to put these two queries into one, anyone know how this can be accomplished?

$query = "SELECT COUNT(rate) AS Likes 
		  FROM ratings				
		  WHERE image_id = '{$image_id}' AND rate = 1";
$result = mysql_query($query);
$rate1 = mysql_fetch_assoc($result);

$query = "SELECT COUNT(rate) AS Dislikes 
		  FROM ratings				
		  WHERE image_id = '{$image_id}' AND rate = -1";
$result = mysql_query($query);
$rate2 = mysql_fetch_assoc($result);

echo $rate1['Likes'], $rate2['Dislikes'];

Thanks for any help

Yours,
Bertan

Show multiple count result from sql join

10 January 2012 - 09:03 AM

When executing this code the both counts is added together showing the result of $submissions + $comments. I want to show the result of $submissions and $comments seperated from each other.

For example if submissions is 2 and comments is 1 then submissions should show 2 and comments 1. Now both of them are showing 3.

What am I doing wrong?

$query = "SELECT u.user_prestige, u.user_name, COUNT(c.comment_id) AS NumberOfComments, COUNT(c.image_id) AS NumberOfsubmissions
		  FROM users u 
		  LEFT JOIN images i ON i.user_id = u.user_id
		  LEFT JOIN comments c on c.user_id = u.user_id
		  WHERE u.user_id = '$user_id'";
$result = mysql_query($query);
$user = mysql_fetch_array($result);
$submissions = $user['NumberOfsubmissions'];
$comments = $user['NumberOfComments'];

Session cookies

06 January 2012 - 01:59 PM

I want to make it possible for users to stay logged in on my page. I was going to store the session data in the database. From what I have seen from most session scripts online, data is saved to the database from all users guests and logged in users. Is there any value in saving information about guests if all I want to do is to give the user the ability to stay online. I was thinking about inserting the data when the users logs in and delete all rows with the matching user id everytime the user logs out to keep the session table slim. But I havn't seen anyone doing like this so I figure I might have got something wrong.

Any help on this would be appreciated.

Yours,
Bertan

Click event on DOM element inserted with AJAX

22 December 2011 - 09:08 AM

I tried to put the click event inside ajax.php and then it works, but if in test.php it doesn't work is it any way to get this to work from test.php?

Thanks for any help,
Bertan

test.php
<!DOCTYPE html>
<html>
	<head>
		<title>Image</title>
		<meta charset="UTF-8" />
		<script src="http://code.jquery.com/jquery.min.js"></script>
		<style>
		#content {
			padding: 20px 0;
			background: #f4f4f4;
			text-align: center;
		}
		ol, ul {
			list-style: none outside none;
		}		
		</style>
	</head>
	<body>

		<div id="content">
			<ul class="imgRow">
			</ul>
		</div>
		<script>
 		$(function() {
		
 			loadContent();
			
			function loadContent() {
				var index = true;
				
				$(function () {
					$.ajax({
						type: "GET",					
						url: "ajax.php",
						dataType: "html", 
						success: function(html) {                     
							$(".imgRow").html(html);							
						} 
					});
				});
				setTimeout(loadContent, 10000);
			}
			
 			$("#text").click(function(data) {
				alert("Hello");
			});	 	
		}); 		
		</script>		
	</body>
</html>

ajax.php
<?php
echo 
	'<li id="text">				
		Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
	</li>';
?>

How to show and hide divs using JavaScript?

19 October 2011 - 07:34 AM

I have some problem getting this script to work. I want to be able to show the content for the link I am clicking on. I have tried with a for loop and text.length but all I achieved was to get nothing it all to work. I guess it is somewhere in that direction I have to go, but I will paste the code from where something actually works so you get the idea of what I am trying to achieve.

In this example the top link is working as it should but I want to apply this to all links.

Thanks for any help!

Javascript:
onload=function(){

	showContent();
	
	function showContent(){
		var text = document.getElementsByClassName("text")[0];
		var showText = document.getElementsByClassName("showText")[0];
		var newHeight = 0;
		var y = 0;
		
		text.style.display = "block";
		var firstTextHeight = text.offsetHeight;
		text.style.display = "none";
		
		text.style.height = newHeight + "px";

		showText.onclick = function(){
			text.style.display = "block";
			var textHeight = text.offsetHeight;
			if (firstTextHeight < textHeight){
				slideUp();
			} else {
				slideDown();
			}
		}
		
		function slideDown(){
			y++;
			if(y <= firstTextHeight){
				text.style.height = y + "px";
				setTimeout(slideDown, 1);
			}
			showText.innerHTML = "Slide up";
		}
		
		function slideUp(){
			y--;
			if(y >= 0){
				text.style.height = y + "px";
				setTimeout(slideUp, 1);
			} else {
				showText.innerHTML = "Slide down";
				text.style.display = "none"; 
			}
		
		}
	}
}


HTML:

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="UTF-8" />
<link href="css/stylesheet.css" rel="stylesheet" type="text/css" />
<script src="javascript/script.js" type="text/javascript"></script>
</head>
<body>
<div id="wrapper">
<div id="content">

<a href="#" class="showText">Slide down</a>
<div class="text">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet
egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan
porttitor, facilisis luctus, metus</p>
</div>

<a href="#" class="showText">Slide down</a>
<div class="text">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet
egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan
porttitor, facilisis luctus, metus</p>
</div>

<a href="#" class="showText">Slide down</a>
<div class="text">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet
Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque
egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan
Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque
egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan
porttitor, facilisis luctus, metus</p>
</div>

</div>
</div>
</body>
</html>


CSS:
#wrapper {
	width: 960px;
	margin: 0 auto;
}
#content {
	background: #234343;
	height: 600px;
	width: 700px;
	float: left;
	padding: 20px;
}

.showText {
	display: block;
	color: #282828;
	border: 1px solid #282828;
	width: 400px;
	background: #bbb;
	padding: 5px;
}

.text {
	overflow: hidden;
	width: 400px;
	background: #fff;
	border: 1px solid #282828;
	padding: 5px;
	display: none;
}

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download