www.webdeveloper.com
Results 1 to 2 of 2

Thread: Ajax, mysql, php form

Hybrid View

  1. #1
    Join Date
    Oct 2008
    Posts
    18

    Question 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);
    
    ?>
    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;}
    ?>
    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.

  2. #2
    Join Date
    Oct 2008
    Posts
    18

    One question at a time I guess

    How do i output a variable from a input using ajax.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles