Jump to content

Problem with the code


ashrafzia
 Share

Recommended Posts

I have the following code for ajax/php :

 

$form = "<head><title>:::Subjects:::</title></head>
		<script src='ajax_files/prototype.js'></script>
		<script src='ajax_files/getSecond.js'></script>
			<body>
		<form action='subjects.php' method='get' enctype='multipart/form-data'>
		  <table width='394' border='1' align='center' cellpadding='5' cellspacing='5'>
		  	<tr>
		      <td>Programe Name:</td>";

$sql = "select programe_name from programmes";
$result = mysql_query($sql, $conn) or die (mysql_error());
while ($row = mysql_fetch_array($result)){
	$add .="<option value='$row[programe_name]'>$row[programe_name]</option>";
}

$form .= "<td>
			<select name='prog_name' id='prog_name' onchange='getSecond(this.value)'>
		  	<option value=''>--Select--</option>
			$add
		    </select>
		  </td>
		  </tr>
		 <tr>
		 <td>Semester:</td>
		 <td><span id=\"comboHint\">";

$include = include('ajax_files/sublist.php');   // i don't know wat to do here? How to include this file?
// include "ajax_files/sublist.php";

$form .= "$include</span>
		  </td></tr></table></form></body></html>";

 

I am actually getting the programe names from the table inside the select box.

Now i want whenever a programe name is selected, for e,g bba, a new list box should appear with the total no of semesters for it.

i dont know how to put the sublist.php file between <span> </span> tags and run it there.

In the sublist.php file i have my list box.

 

And another question is, how can i maintain the format/design of my form?

because when i echo the file sublist.php it is showing me the list box on the top left corner instead of inside the cell, which i have mentioned.

Link to comment
Share on other sites

What are th conents of your sublist?

 

If it's just html why don't you use the file_get_contents() function.

 

$form .= file_get_contents('ajax_files/sublist.php'); instead of $include = include('ajax_files/sublist.php');.

 

Here's my sublist.php file :

 

<?
include "connection.php";
$prog_name = $_GET['prog_name'];

echo "$prog_name";

$sql = "SELECT	programmes.no_of_semesters
	FROM programmes
	WHERE	programmes.programe_name = '$prog_name' ";

$result = mysql_query($sql, $conn) or die (mysql_error());

while ($row = mysql_fetch_array($result)){
	$semester .="<option value='$row[no_of_semesters]'>$row[no_of_semesters]</option>";
}

echo  "<select name='semester'>
	<option value=''>--Select--</option>
	$semester
	</select>";
?>

 

Its still not working.....

 

Link to comment
Share on other sites

Oh ok, rather than echoing:

echo  "<select name='semester'>
	<option value=''>--Select--</option>
	$semester
	</select>";

 

extend the variable $form:

$form .=  "<select name='semester'>
	<option value=''>--Select--</option>
	$semester
	</select>";

 

Now you can just use the include function on the other page:

 

include('ajax_files/sublist.php'); // include "ajax_files/sublist.php";

$form .= "</span>
		  </td></tr></table></form></body></html>";

 

Link to comment
Share on other sites

I'll write it for you, maybe i wasn't clear with what i meant.

 

$form = "<head><title>:::Subjects:::</title></head>
		<script src='ajax_files/prototype.js'></script>
		<script src='ajax_files/getSecond.js'></script>
			<body>
		<form action='subjects.php' method='get' enctype='multipart/form-data'>
		  <table width='394' border='1' align='center' cellpadding='5' cellspacing='5'>
		  	<tr>
		      <td>Programe Name:</td>";

$sql = "select programe_name from programmes";
$result = mysql_query($sql, $conn) or die (mysql_error());
while ($row = mysql_fetch_array($result)){
	$add .="<option value='$row[programe_name]'>$row[programe_name]</option>";
}

$form .= "<td>
			<select name='prog_name' id='prog_name' onchange='getSecond(this.value)'>
		  	<option value=''>--Select--</option>
			$add
		    </select>
		  </td>
		  </tr>
		 <tr>
		 <td>Semester:</td>
		 <td><span id=\"comboHint\">";
include('ajax_files/sublist.php');  // include "ajax_files/sublist.php";

$form .= "</span>
		  </td></tr></table></form></body></html>";

 

sublist.php:

<?php
include "connection.php";
$prog_name = $_GET['prog_name'];

$form .= "$prog_name";

$sql = "SELECT	`programmes.no_of_semesters` FROM `programmes` WHERE `programmes.programe_name` = '$prog_name'";
$result = mysql_query($sql, $conn) or die (mysql_error());

while ($row = mysql_fetch_array($result)){
	$semester .="<option value='$row[no_of_semesters]'>$row[no_of_semesters]</option>";
}

$form .=  "<select name='semester'>
	<option value=''>--Select--</option>
	$semester
	</select>";
?>

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.