Jump to content

hitman47

Members
  • Posts

    14
  • Joined

  • Last visited

hitman47's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. prosthiki_akinitou_form_ajax.php = ajax.php this is not the problem
  2. I want to create a real esatte website. This is part of my code. The user selects a category.Then ajaxhelp is called and sends the cariable category to ajax.php. There it gets the type of estate wuering the database. however i want to enable the selected="selected" option, in order in category php in id=category in the bottom to print the option the user has already selected. i don't know how to it. The selected option doesnt work <script> function ajaxhelp(str) { if (str=="") { document.getElementById("category").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("category").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","prosthiki_akinitou_form_ajax.php?category="+str,true); xmlhttp.send(); } </sqript> //category.php <tr > <td><h4>Category:<small class="red">*</small></h4></td> <td ><select name="category" onChange="ajaxhelp(this.value);"> <?php $category_array = get_categories(); //estate_fns echo '<option value=""><h4>- Choose Estate Category -</h4></option>'; foreach ($category_array as $row) { if($estate_array['catid'] === $row['catid']) { echo '<option selected="selected" value="'. $row['catid'].'"><h4>' . $row['catname'].'</h4></option>'; } else { echo '<option value="'. $row['catid'].'"><h4>' . $row['catname'].'</h4></option>';} } ?> </select> </td></tr> <?php echo '<tr >'; echo '<td><h4>Estate type:</h4></td> <td ><select name="eidos" id="category" >'; echo '</select> </td></tr>'; ?> //ajax.php include ('estate_sc_fns.php'); $katigoria = $_GET['category']; //get the value from ajax.php $estate_array = get_estate_details($_SESSION['estate_code']); //get the estate type the user already has entered from mysql $eidos_array = get_estate_type($category); //get all possible estate types from mysql foreach ($eidos_array as $row) { if($estate_array['estate_type'] === $row['estate_type'] ) { echo '<option selected="selected" value="'. $row['estate_type'].'"><h4>' . $row['estate_name'].'</h4></option>'; } else { echo '<option value="'. $row['estate_type'].'"><h4>' . $row['estate_name'].'</h4></option>';} } But the selected="selected" doesn't work! Please help how to do it?
  3. Thank you bro. One question only. In the first link for example ajax sends the variable 'id' with post to a different page than the original-mother select is. The mother select is in sections_demo.php and ajax sends the variable to ajax_city.php From there it queries the dtabase and the extra option field is echoed. Why? Could this be done within the same page sections_demo.php? This is something i don't understand
  4. Its easy. I have a form with many select options. Like this website: http://www.tospitimou.gr/en/index.jsp Check it at the top where it says YOU ARE AT. IF you choose an area then in the select box that follows some options are shown. If you choose something differnet in teh first select different choises come up in the second. Same thing in this site: http://www.realestatecorner.gr/ I foy choose something in the "Περιοχή:" that means location in greek, then a new select option emerges, that was not shown in the beggining. If you choose another location, other options come up. How shall i do iti? I dont have a clue about ajax. With the code i gave you
  5. I want to mention that all my code is in one file. In insert_data.php. Shall i use more? Shall i split the data? I dont know ajax. Please help
  6. Hallo. I have a form <form id="form2" method="post" action="insert_data.php>"> <select name="catid" id="catid" onChange="showkatigoria(this.value);"> <option value="'. $row['catid'].'"><h4>' . $row['catname'].'</option> // something i need with php, i dont' think it matters <option value="'. $row['catid'].'"><h4>' . $row['catname'].'</option> <option value="'. $row['catid'].'"><h4>' . $row['catname'].'</option> //option value bla bla bla bla i have 4-5 options value. </select> My javascript: <script type="type/javascript"> function showkatigoria(str) { if (str=="") { document.getElementById("catid").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("catid").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","insert_data.php?category="+str,true); xmlhttp.send(); } </script> It doesn't work what ever i do. Please help! I don't know javascript, let alone ajax. It's urgent. Please help!
  7. No i still have problem. how to use Post/Redirect/Get http://en.wikipedia.org/wiki/Post/Redirect/Get#cite_note-1 ? Does anyone knows. I want fully detailed instractcions
  8. You haven't understand. I don't want them to reenter forms. After submit, If the user accidentaly presses mouse or browser back button, the forms are aempty. Then if he presses forward then there is a message that THE PAGE HAS EXPIRED! I can't see the page. It's a huge bug and very annoying!!!
  9. HALLO, i have one major problem. I have a page that submits data to another with post for example this: <form id="form2" method="post" action="articles.php" > <table id="table1" class="adminformat" > <tr><td> <br></br><td></tr> <tr > <td><strong>Category:</strong></td> <td class="spaceUnder"><select name="catid" > <?php $cat_array = get_categories(); foreach ($cat_array as $row) { echo '<option value="'. $row['catid'].'">' . $row['catname'].'</option>'; } ?> </select> </td></tr> <tr> <td colspan="2"><strong>Title :</strong> </td></tr> <tr> <td colspan="2" class="spaceUnder"><input maxlength="300" class="inputglow" type="text" name="title"/></td></tr> <tr> <td colspan="2"><strong>Message :</strong> </td></tr> <tr> <td colspan="2"><textarea name="message"> </textarea></td></tr> <td align="right" colspan="2"> <input type="reset" class="button" value="Clear"/> <input type="submit" class="button" value="OK"/></td></tr> </table> </form> The data is send to articles.php. If user presses refresh or back button, an ERROR PAGE in the browser is shown or forms are empty. I know i have to store somehow my variables. I have many forms, so i am looking for the best an easyest way, because i have to fill in a lot of code in many pages. Furthermore when i press back and forawrd again, the articles page cannot be shown. Instead teh browser shows a message that the page HAS EXPIRED! I am so freaked out. Please help i am so stuch.URGENT!!!!!!!!!
  10. I have a table with some data. The user chooses how he wants the data in the table to be sorted in the user.php page. The table data are stored in my mysql database. Easy. However because the table is paginated i have a huge problem. Everytime i change the page, the sortment is lost. I used cookies. <form method="post" action="news_list.php" onchange="form.submit()"> <select name="sortid" > <?php $sort_array = array(' ','date desc','date asc','title desc','title asc') ; for($i=1; $i<5; $i++) { if($i ==$shortchoice ){ echo '<option selected="selected" value="'.$i.'">'.$sort_array[$i].'</option>'; } else { echo '<option value="'.$i.'">'.$sort_array[$i].'</option>'; } } echo '</select></form>'; ?> In the beggining of news_list.php, before the header i place this: <?php session_start(); setcookie('sortid', $_POST['sortid']); ?> Now i have a paginated sorted table that keeps in $_cookie['sortid'] the users sorting choise When i change the first page IN the table, the sortment is maintained, because the cookie keeps its value. After i browse more pages, more than two IN the sorted table, the cookie looses its value and the table loses it's sortment, it returns to the default sorting value Should i place <?php session_start(); setcookie('sortid', $_POST['sortid']); ?> in my user.php page or in news_list.php? I have tried both but the problem insists. How to maintain the cookie value? Please i have racked my brains to find a solution, and nothing seems to work. Any suggestions? HELP!!!
  11. The user chooses his year of birth. This is stored in my mysql database. Easy. <select name="year" > for ($year = 1960; $year <= 2030; $year++) { echo '<option value="'.$year.'"><h4>' .$year.'<h4></option>'; } </select> However when i hit submit the form resets to the first option of the list, in this example 1960. If the user chooses 2000 for example and hits submit, the valuse will be passed with post to the next php page, but when i return to this, his choise, 2000, is lost, and it will return to 1960. How can i maintain his option in the select field? Furthermore i want if the user wants to change his option and the select field shows all the options from 1960 to 2030 in a row, not mixed. I am stuck. It is very frustrating. Help!!!
  12. Please somebody help me. Do you want more data on this?
  13. Here is my pagination code: class Paginator{ var $items_per_page; var $items_total; var $current_page; var $num_pages; var $mid_range; var $low; var $high; var $limit; var $return; var $default_ipp =11; //items_per_page function Paginator() { $this->current_page = 1; $this->mid_range = 7; $this->items_per_page = (!empty($_GET['ipp'])) ? $_GET['ipp']:$this->default_ipp; } function paginate() { if($_GET['ipp'] == 'All') { $this->num_pages = ceil($this->items_total/$this->default_ipp); $this->items_per_page = $this->default_ipp; } else { if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $this->default_ipp; $this->num_pages = ceil($this->items_total/$this->items_per_page); } $this->current_page = (int) $_GET['page']; // must be numeric > 0 if($this->current_page < 1 Or !is_numeric($this->current_page)) $this->current_page = 1; if($this->current_page > $this->num_pages) $this->current_page = $this->num_pages; $prev_page = $this->current_page-1; $next_page = $this->current_page+1; if($this->num_pages > 3) { $this->return = ($this->current_page != 1 And $this->items_total >= 10) ? "<a class=\"paginate\" href=\"$_SERVER[php_SELF]?page=$prev_page&ipp=$this->items_per_page\">« Previous</a> ":"<span class=\"inactive\" href=\"#\">« Previous</span> "; $this->start_range = $this->current_page - floor($this->mid_range/2); $this->end_range = $this->current_page + floor($this->mid_range/2); if($this->start_range <= 0) { $this->end_range += abs($this->start_range)+1; $this->start_range = 1; } if($this->end_range > $this->num_pages) { $this->start_range -= $this->end_range-$this->num_pages; $this->end_range = $this->num_pages; } $this->range = range($this->start_range,$this->end_range); for($i=1;$i<=$this->num_pages;$i++) { if($this->range[0] > 2 And $i == $this->range[0]) $this->return .= " ... "; // loop through all pages. if first, last, or in range, display if($i==1 Or $i==$this->num_pages Or in_array($i,$this->range)) { $this->return .= ($i == $this->current_page And $_GET['page'] != 'All') ? "<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" href=\"$_SERVER[php_SELF]?page=$i&ipp=$this->items_per_page\">$i</a> "; } if($this->range[$this->mid_range-1] < $this->num_pages-1 And $i == $this->range[$this->mid_range-1]) $this->return .= " ... "; } $this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 10) And ($_GET['page'] != 'All')) ? "<a class=\"paginate\" href=\"$_SERVER[php_SELF]?page=$next_page&ipp=$this->items_per_page\">Next »</a>\n":"<span class=\"inactive\" href=\"#\">» Next</span>\n"; $this->return .= ($_GET['page'] == 'All') ? "<a class=\"current\" style=\"margin-left:10px\" href=\"#\">All</a> \n":"<a class=\"paginate\" style=\"margin-left:10px\" href=\"$_SERVER[php_SELF]?page=1&ipp=All\">All</a> \n"; } else { for($i=1;$i<=$this->num_pages;$i++) { $this->return .= ($i == $this->current_page) ? "<a class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" href=\"$_SERVER[php_SELF]?page=$i&ipp=$this->items_per_page\">$i</a> "; } $this->return .= "<a class=\"paginate\" href=\"$_SERVER[php_SELF]?page=1&ipp=All\">All</a> \n"; } $this->low = ($this->current_page-1) * $this->items_per_page; $this->high = ($_GET['ipp'] == 'All') ? $this->items_total:($this->current_page * $this->items_per_page)-1; $this->limit = ($_GET['ipp'] == 'All') ? "":" LIMIT $this->low,$this->items_per_page"; } function display_items_per_page() { $items = ''; $ipp_array = array(10,25,50,100,'All'); foreach($ipp_array as $ipp_opt) $items .= ($ipp_opt == $this->items_per_page) ? "<option selected value=\"$ipp_opt\">$ipp_opt</option>\n":"<option value=\"$ipp_opt\">$ipp_opt</option>\n"; return "<span class=\"paginate\">Items per page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[php_SELF]?page=1&ipp='+this[this.selectedIndex].value;return false\">$items</select>\n"; } function display_jump_menu() { for($i=1;$i<=$this->num_pages;$i++) { $option .= ($i==$this->current_page) ? "<option value=\"$i\" selected>$i</option>\n":"<option value=\"$i\">$i</option>\n"; } return "<span class=\"paginate\">Page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[php_SELF]?page='+this[this.selectedIndex].value+'&ipp=$this->items_per_page';return false\">$option</select>\n"; } function display_pages() { return $this->return; } } And this is where my sorted table is: $displayed_articles = count_articles(NULL);//get number of articles in my table $pages = new Paginator; $pages->items_total = $displayed_articles; $pages->mid_range = 9;//The third line tells the paginator the number of page links to display $pages->paginate(); show_article_list($articles, $pages->display_pages(),$pages->display_jump_menu(),$pages-> display_items_per_page()); //my function where my table is and where my data would be shown If i want to sort my table and keep my pagination what should i add? Please help i am stuck and it is urgent
×
×
  • 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.