Hey guys, I'm new to this forum and new to programing. Hopefully this is the start to a grand adventure in the computer realm. I'd like to thank you in advance for the help and support.
I'm trying to build a price list (a simple one or so I thought)
What I'm trying to accomplish with a table is the following;
///////////////////////////////////////////////////////////////////////////////////////////
|
echo Rug_cat | echo's the different sizes according to their rug_cat
|
///////////////////////////////////////////////////////////////////////////////////////////
When you click on a size I want it to pop a ajax box that will display or at very minimal (which I'm trying to accomplish now is it will display it on the bottom of the table)
////////////////////////////////////////////////////////////////
rug_cat : size |
////////////////////////////////////////////////////////////////
[price 1] [price 2] [price 3] [price 4] and [price 5] |
////////////////////////////////////////////////////////////////
My index.php code;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script src="price.js" type="text/javascript"></script>
</head>
<body>
<?php
require('includes/configuration.php');
require('includes/open_conn.php');
$query = "SELECT * FROM rugs";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
if($row['rug_cat'] == 'Standard Size')
{
echo "<a class=\"price\" href=\"javascript:void(0)\" onclick=\"showUser(". $row['id'] .")\">" . $row['size'] . "</a>";
echo "<br>";
}
}
include('includes/close_conn.php');
?>
<div id="txtHint"></div>
</body>
</html>
My Javascript / Ajax Code (which i got from w3cshools.com)
var xmlHttp
function showUser(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getprice.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
My getprice.php which i also got from w3schools.com
<?php
$q=$_GET['q'];
require('includes/configuration.php');
require('includes/open_conn.php');
$sql="SELECT * FROM rugs WHERE id = '".$q."'";
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['size'] . "</td>";
echo "<td>" . $row['rug_cat'] . "</td>";
echo "<td>" . $row['Age'] . "</td>";
echo "<td>" . $row['Hometown'] . "</td>";
echo "<td>" . $row['Job'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo $q;
include('includes/close_conn.php');
?>
What do you guys think?