ashrafzia Posted October 24, 2007 Share Posted October 24, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/74624-problem-with-the-code/ Share on other sites More sharing options...
only one Posted October 24, 2007 Share Posted October 24, 2007 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');. Quote Link to comment https://forums.phpfreaks.com/topic/74624-problem-with-the-code/#findComment-377200 Share on other sites More sharing options...
ashrafzia Posted October 24, 2007 Author Share Posted October 24, 2007 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..... Quote Link to comment https://forums.phpfreaks.com/topic/74624-problem-with-the-code/#findComment-377204 Share on other sites More sharing options...
only one Posted October 24, 2007 Share Posted October 24, 2007 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/74624-problem-with-the-code/#findComment-377212 Share on other sites More sharing options...
ashrafzia Posted October 24, 2007 Author Share Posted October 24, 2007 I am sorry. I couldn' get you are trying to say? why should i use include function on the other page? by other page do you mean sublist.php ? Quote Link to comment https://forums.phpfreaks.com/topic/74624-problem-with-the-code/#findComment-377233 Share on other sites More sharing options...
only one Posted October 24, 2007 Share Posted October 24, 2007 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/74624-problem-with-the-code/#findComment-377241 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.