Jump to content


Check out our Community Blogs

doheja07

Member Since 08 May 2009
Offline Last Active Sep 02 2009 12:26 PM
-----

Topics I've Started

Could anybody recommend a good source to learn object oriented programming?

11 August 2009 - 09:40 AM

Hi. I've recently spent some time learning php. I then tried to create my own website but after a while the code was getting very disorganized and confusing and I was getting overwhelmed. Because of this, I took a month break from it and followed some tutorials to learn how to create flash games. Anyway, I figure it's time I should be getting back to the website, but before I do, I thought I would learn object oriented programming to help me organize my code better. I already watched the oop tutorial on lynda.com, but that still left me confused. I was able to learn the basic oop syntax from the tutorial, but I still need to figure out how to take my current code and divide it into classes and organize more effectively in general. Could anybody recommend a good source?

What do I need to change in order to get this to work using ajax?

18 June 2009 - 09:38 PM

I created a code. When I run the code using php, it is very inneficient. I figured I could significantly improve my UI if I could use ajax. The problem is, I am new to javascript and ajax. I have been following a tutorial to get a idea as to how I should write the code, but for some reason it doesn't work. It does work, however, when it is just php. Could somebody give me an idea as to what I need to change so that the code will work with ajax?

This is upload.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php
require_once("connection.php");
require_once("functions.php");
?>
<script type="text/javascript" src="getcategories.js"></script>

<body>
<form action="upload2.php" method="post">
<select name="categories" onchange="getSubcategories(this.value)">

<?php
get_selectable_categories();
?>
</select>
<select name="subcategories" onchange="getSubsubcategories(this.value)">
</select>
<select name="subsubcategories">
</select>
<input type="submit" name="submit" value="Submit" />
</form>
<?php
mysql_close($connection);
?>

</body>
</html>

This is getCategories.js:
window.onload = getCategories;

var xhr;

function getCategories() {
	xhr=GetXmlHttpObject();
if (xhr==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url = "categories.php";
url = url+"sid="+Math.random();
xhr.onreadystatechange=stateChanged;
xhr.open("GET",url,true);
xhr.send(null);
}

function getSubcategories(id) {
	xhr=GetXmlHttpObject();
if (xhr==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url = "subcategories.php";
var url = url+"?id="+id;
url = url+"sid="+Math.random();
xhr.onreadystatechange=stateChanged;
xhr.open("GET",url,true);
xhr.send(null);
}

function getSubsubcategories(id) {
	xhr=GetXmlHttpObject();
if (xhr==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url = "subsubcategories.php";
var url = url+"?id="+id;
url = url+"sid="+Math.random();
xhr.onreadystatechange=stateChanged;
xhr.open("GET",url,true);
xhr.send(null);
}

function stateChanged()
{
if (xhr.readyState==4)
{
document.getElementById("categories").innerHTML=xhr.responseText;
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

This is categories.php:
<?php require_once("connection.php"); ?>
<?php require_once("functions.php"); ?>
<?php get_selectable_categories(); ?>
<?php mysql_close($connection); ?>

This is subcategories.php:
<?php require_once("connection.php"); ?>
<?php require_once("functions.php"); ?>
<?php $id = $_GET['id']; ?>
<?php get_selectable_subcategories($id); ?>
<?php mysql_close($connection); ?>

This is subsubcategories.php:
<?php require_once("connection.php"); ?>
<?php require_once("functions.php"); ?>
<?php $id = $_GET['id']; ?>
<?php get_selectable_subsubcategories($id); ?>
<?php mysql_close($connection); ?>

This is functions.php:
<?php

function confirm_query($result_set) {
		if (!$result_set) {
			die("Database query failed: " . mysql_error());
		}
	}

function get_all_categories() {
		global $connection;
		$query = "SELECT *
				  FROM categories
				  WHERE visible = 1
				  ORDER BY cat_name ASC";
		$category_set = mysql_query($query, $connection);
		confirm_query($category_set);
		return $category_set;
	}
	
function get_selectable_categories() {	
	$categories = get_all_categories();
	while($category = mysql_fetch_assoc($categories)) {
		echo "<option value=" . $category['id'] . "";
		echo ">" . $category['cat_name']. "</option>";
	}
}

function get_subcategories_for_category($id) {
	global $connection;
	$query = "SELECT *
			  FROM subcategories
			  WHERE cat_id = $id
			  AND visible = 1
			  ORDER BY subcat_name ASC";
	$subcategory_set = mysql_query($query, $connection);
	confirm_query($subcategory_set);
	return $subcategory_set;
}

function get_selectable_subcategories($id) {	
	$subcategories = get_subcategories_for_category($id);
	while($subcategory = mysql_fetch_assoc($subcategories)) {
		echo "<option value=" . $subcategory['id'] . "";
		echo ">" . $subcategory['subcat_name']. "</option>";
	}
}

function get_subsubcategories_for_subcategory($id) {
	global $connection;
	$query = "SELECT *
			  FROM subsubcategories
			  WHERE subcat_id = $id
			  AND visible = 1
			  ORDER BY subsubcat_name ASC";
	$subsubcategory_set = mysql_query($query, $connection);
	confirm_query($subsubcategory_set);
	return $subsubcategory_set;
}

function get_selectable_subsubcategories($id) {	
	$subsubcategories = get_subsubcategories_for_subcategory($id);
	while($subsubcategory = mysql_fetch_assoc($subsubcategories)) {
		echo "<option value=" . $subsubcategory['id'] . "";
		echo ">" . $subsubcategory['subsubcat_name']. "</option>";
	}
}
	
?>


I would really appreciate it if somebody could tell me how to get the ajax version of this working.

How do I do this?

07 June 2009 - 01:35 PM

This may be a dumb question, but I am still in the beginning stages of learning programming. I found a script that seems to be pretty elaborate and figure if I can follow the logic of the script, I should be able to understand the PHP language better. But I am having a problem at the moment. How exactly to I add directories to my xampp server? They need to be put in the public_html directory, but I don't see that for xampp server. What is xampp server's equivalent of public_html?

Recommendations

06 June 2009 - 03:28 PM

Hi. I am trying to learn simpleXML. When learning any new programming skills, I like to use lynda.com, because they have projects to help you learn the skills. I also like the fact that the tutorials are videos. The problem is, they don't offer any tutorials for simpleXML. Does anybody know of someplace I can find a tutorial that has a project to go along with it? It doesn't have to be a video, but I would prefer it.

XML technologies.

05 June 2009 - 10:27 PM

Are there any technologies available that will let me work with XML in a similar way to the way I am able to work with PHP? I am working on building a store. The company I am working with is providing me with an XML datafeed of all their products. This way, if a product is out of stock, if they add a new product, if there is a new category, etc. my website can be updated more quickly. If this was data in a MySQL database, I would have no problem creating this site. In PHP I can create relational databases so that I can create one function that can look up the category id and find all the products that are related to that category. This function would be completely dynamic so adding a new catagory wouldn't require any additional programming. Are there any technologies for XML that would allow me to do something similar to this?

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