/    Sign up×
Community /Pin to ProfileBookmark

Ajax, mysql, php form

Hi everyone

I figured this forum would be the forum that would be able to help me with my issue.

I am trying to figure out a ajax form in php. Its very simple issue and probably solution.

Question #1:
This is what i am trying to do. there is a price colum of a table that price is received from a mysql database, the customer will type in the ammount of plants they need and then to right of that, Ajax will display the subtotal of each plant. if the number changes in the amount they want then the ajax total will change.

Letter sort:

at the top of my table i have letters A-Z if a user only wants to see plants with name starting with T they press the t and it will display only plants with T. I also will have a “Display All” and it will do as it states.

Question #2:
I know how to display only records with say latter T but i dont know how to get that row of letters A-Z to be links that will assign variable to that letter

Availability.php

[CODE]<script language=”javascript” type=”text/javascript”>
<!–
//Browser Support Code
function ajaxFunction(str){
var ajaxRequest; // The variable that makes Ajax possible!

try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject(“Msxml2.XMLHTTP”);
} catch (e) {
try{
ajaxRequest = new ActiveXObject(“Microsoft.XMLHTTP”);
} catch (e){
// Something went wrong
alert(“Your browser broke!”);
return false;
}
}
}

ajaxRequest.onreadystatechange = function(str){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById(‘ajaxDiv’);
ajaxDisplay.innerHTML = ajaxRequest.responseText;

}
}
ajaxRequest.open(“POST”, ‘Total.php’, true);
ajaxRequest.send(null);
}

//–>
</script>

<?php

echo “<link rel=’stylesheet’ href=’av.css’>”;
echo “<link rel=’stylesheet’ href=’style.css’>”;

// Open connection to DB
include ‘config.php’;
include ‘opendb.php’;

//Varables
$num=1;
$input_order = $_POST[“input_order”];

//Query
$query = “SELECT * FROM `Availability` ORDER BY name ASC”;

$Letter=e;
$queryl = “SELECT * FROM `Availability` Where name LIKE ‘$Letter%’ ORDER BY name ASC “;
$result = mysql_query($query);

//Wrapper and button
echo”
<div id=’center250a’>
<div id=’fixedtop2′>
<center>
<input type=’submit’ />
</Center>
</div>
</div>
</form>
<div id=’wrapper’>”;
echo ‘<form method=”post” action=”Total.php”>
Company Name:<input type=”text” size=”12″ maxlength=”40″ name=”cname”> <br/> Email:<input type=”text” size=”12″ maxlength=”18″ name=”email”><br /><br />
‘;

// Display DB
echo
“<div id=’letter’>A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
</div>
<table id=’rounded-corner’>
<thead>
<tr>
<th scope=’col’ class=’rounded-first’>Plant Name</th>
<th scope=’col’ class=’rounded-si’>Size</th>
<th scope=’col’ class=’rounded-de’>Description</th>
<th scope=’col’ class=’rounded-av’>Available</th>
<th scope=’col’ align=’right’ class=’rounded-pr’>Price</th>
<th scope=’col’ class=’rounded-or’>Order Unit</th>
<th scope=’col’ class=’rounded-end’>Total</th>
</tr>
</thead>
<tfoot>
<td colspan=’4′ class=’rounded-foot-left’>&nbsp;</td>
<td colspan=’4′ class=’rounded-foot-right’>&nbsp;</td>
</tr>
</tfoot>
<tbody>”;

while(list($id,$name,$size,$description,$available,$price)= mysql_fetch_row($result))
{

$input_order= $_POST[‘input_order’];
echo”
<tr>
<td align=’left’>$name</td>”;
if ($size==’B&B’)
{
echo”<td>$size</td>”;
}
else
{
if($size==4)
{
echo”<td>$size”; echo ‘”‘; echo”</td>”;
}
else{
echo”<td>#$size</td>”;
}
}
echo”
<td>$description</td>
<td>$available</td>
<td align=’right’>$$price </td>
<td>

<form method=’post’ action=’Total.php’>
<input id=’input_order’ onchange=’ajaxFunction();’ type=’number’ size=’4′ maxlength=’4′ name=’input_order’ ></td>
</form>
“;

echo “Price: $price “;
echo “input: $input_order “;
echo “Total: $total<br/>”;
echo”
<td>
<div id=’ajaxDiv’>-
</div>
</td>
</tr>”;
$num++;

}
echo “</tbody></table>
</div>”;

// Close connection to DB
mysql_close($conn);

?>[/CODE]

Total.php

[CODE]<?php
$input_order= $_POST[‘input_order’];
$total=$price*$input_order;
echo ‘$input_order’;

echo $price;
if($total==’0′){
$total=’-‘;
echo $total;
}
else{
echo $total;}
?>[/CODE]

My code is really messy and has a lot of unnecessary stuff in it. i will clean it all up later.

could some one help me with my questions that would be greatly appreciated.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@GerritvkauthorOct 30.2008 — How do i output a variable from a input using ajax.
×

Success!

Help @Gerritvk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...