Jump to content

digi duck

Members
  • Posts

    41
  • Joined

  • Last visited

    Never

Contact Methods

  • Website URL
    http://gamesigs.co.uk

Profile Information

  • Gender
    Not Telling

digi duck's Achievements

Member

Member (2/5)

0

Reputation

  1. Ok for anyone interested i've managed to solve it. I changed the text boxes to have the same function which activated onkeyup this function then saves each value as a variable and adds them on to the url as shown below: function change() { var name=document.forms.filter.name.value var city=document.forms.filter.city.value if (name=="" & city=="") { document.getElementById("results").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("results").innerHTML=xmlhttp.responseText; } } var url="results.php" url=url+"?name="+name; url=url+"&city="+city; xmlhttp.open("GET",url,true); xmlhttp.send(); }
  2. Hi there. I am trying to create a filtering system for results in a database (i.e. user types in inputs and it only show the results with that text). I have it half working in that they can filter by name and city individually, however i would like it so they can filter by both together. For example if i have the following data: NAME CITY john new york james london bob tokyo At the moment if they typed in the name filtering box "j" it would show results row john and james, however if they then went and typed in "y" in the city filtering box it would ignore the previous filter and show the john and bob (as y in new york and tokyo). What I want it do is for it to filter both and therefore only show the john row. So far I have the following: For the user submission page <script type="text/javascript" src="js/filter.js"></script> <form> Search by Name:<input type="text" name="name" onkeyup="showName(this.value)"> Search by City:<input type="text" name="city" onkeyup="showCity(this.value)"> </select> </form> <div id="row"></div> For the Javascript page I have: function showName(name) { if (name=="") { document.getElementById("row").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("row").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","results.php?name="+name,true); xmlhttp.send(); } function showCity(city) { if (city=="") { document.getElementById("row").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("row").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","results.php?city="+city,true); xmlhttp.send(); } And lastly for the php file i have: //get the parameters from URL $name=$_GET["name"]; $city=$_GET['city']; //Select Results $sql="SELECT name, city FROM $tbl_name WHERE name LIKE '%$name%' AND city LIKE '%$city%' $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['city'] . "</td>"; echo "</tr>"; } I think it is doing this because it only runs one function at a time and this overwrites the last one therefore i think i need a function to send all the parameters at once even if they've not been changed. Unfortunately im very new to programming and have very little experience with javascript so thought id ask the experts. Thanks in advance for your help!!
  3. Hi. I was hoping someone could tell me whether this is possible and if so how I could go about doing it preferably with a tutorial as im pretty new to programming. I have a database that will contain 100's of records. I want users to be able to select filter parameters on this data by both text and checkboxes with it automatically updating the results (hopefully without page reload). I managed this so far using this Jquery filter script: http://www.picnet.com.au/picnet-table-filter.html. As this will table will have so many rows however I think it would take ages to load so instead I would like to paginate the table but still allow filters applied to affect all records not just the ones displayed on the current page. Any ideas on how i could do this? Thanks in advance for your help.
  4. Thanks for your help. Putting the session_start(); at the top of the admin page did it. Cant believe it was so simply in the end. cheers!
  5. Hi. I am trying to create a very simple admin login page that will let only me access a number of pages. I am trying the following code for the login page: <?php session_start(); // Define your username and password $username = "username"; $password = "password"; if ($_POST['txtUsername'] == $username && $_POST['txtPassword'] == $password) { $_SESSION['admin']="true"; header("location: admin.php"); } ?> ### HTML code and form for entering in username and password with action echoing it back to itself ### On the admin.php page i then try: <?php if ($_SESSION['admin'] != "true") { header("location: login.php");} else { ?> ### code for the rest of the page ### I am fairly new to all this and cant understand why its remaining on the login page and not sending me to admin.php when the password and username are correct. Is this the correct way to be going about it? I envisaged simply adding the above code to the top of any page only the admin could see. Any help is much appreciated.
  6. Thanks for your reply, however im new to php and dont fully understand what is going on. Could you explain it a bit to me please. Thanks a lot.
  7. Hi. I am pretty new to this and am having difficulty looping through rows. I have the code below which first selects a name based upon the id sent from a GET on a separate page. It then has a second select query to get the data from all rows which have this name. I then want it to display the name, and city once but all of the comments. The code below only shows one of each though. Thanks in advance <?php $id = $_GET['id']; // Retrieve data from database $sql="SELECT landlord_name AS name FROM $tbl_name WHERE id=$id"; $query=mysql_query($sql); //loop through the rows while ($rows = mysql_fetch_array($query)){ $name = $rows['name']; } $sql2="SELECT city, landlord_name, landlord_comments FROM $tbl_name WHERE landlord_name= '$name'"; $query2=mysql_query($sql2) or die(mysql_error()); while ($data = mysql_fetch_array($query2)){ ?> <table width="600" border="1" cellspacing="0" cellpadding="0" align="center"> <tr> <div id="name"><? echo $name ?></div> <div id="city"><? echo $data['city']; ?></div> <div id="comments"><? echo $data['landlord_comments']; ?></div> </tr> </table> <? } //End While ?>
  8. Hi. I have a rating site where users fill in a name of what they are rating, comments about it and a rating and submit it to my database. I then have another page which shows all of these entries but only the name and overall rating using php. What I want is for users to click on the name and it take them to a separate page which displays all the comments and ratings for that item. As users can add items to rate I cant set up a page for each manually so was wondering how to do it dynamically. Everything i throw into google leads me in the wrong direction though. If someone could point me to a good tutorial or give me an idea about what to search id be very grateful. Cheers.
  9. Thanks so much everybody for your help it worked!!
  10. Hi. I have the following code where I grab the names and average overall rating from my database and group by the name. $sql="SELECT name, AVG(overall) AS overall FROM $tbl_name GROUP BY name ORDER BY AVG(overall) DESC"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ Does anybody know how I can count the number of names that have been grouped together? For instance: Name Overal ratingl John 2 Pete 5 John 8 It should group the john's, calculate the average rating (8+2)/2=5, and then show that there have been 2 johns making up the 5 rating? I've tried using the code below and messed around with it loads but cant get it to work: $sql="SELECT name, AVG(overall) AS overall FROM $tbl_name COUNT name GROUP BY name ORDER BY AVG(overall) DESC"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ echo $rows['Count name']; Thanks in advance.
  11. That was it. Works like a treat. Thank you so much for all your help!!
  12. Managed to work it out. I had checked= $variable in the form so instead replaced the whole thing with echo $variable. Thanks a lot!! Got the problem now in that it checks the buttons regardless of landlord name i.e: NAME Value Bob 2 John 4 It would check both the 2nd and 4th radio buttons. Anyone know how to make it only check the value that corresponds to the name?? Thanks
  13. Thank you it has stopped throwing that error at me however now it seems as though it is always saying that 5 is checked (or possibly all of them checked) regardless of the value. I looked in my database and the overall value is 1 yet it checks number 5. Any ideas? Thanks for your help so far.
  14. Thanks for the reply however it is giving me an error of: Fatal error: Call to undefined function AVG() in /srv/disk2/959619/www/studentlandlordreviews.co.uk/landlord-reviews.php on line 58 which refers to the: if (AVG(overall)==1){ I guess this means it doesnt know what AVG(overall) is so i tried this instead but still no luck: $avg =AVG(overall); if ($avg==1){ $check1='checked="checked"';} Thanks for your help.
×
×
  • 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.