Jump to content

wouterblacquiere

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Everything posted by wouterblacquiere

  1. Thanks very much for the tip. It worked beautifully! However, I do not understand why it works. You would think that if I want the player's name that can appear in both the white and the black columns, surely I need the AND clause? Why does the OR clause show them both? All the best, Wouter.
  2. Hello, I'm fairly new to php and I'm working on a website for a chess club. I'd like the user to select all of his or her personal results from a general results table. The results table looks as follows: id name_white name_black result season_id 1 john pete 1-0 2010-2011 2 charles steve 0-1 2010-2011 3 richard john 1-0 2010-2011 etc 11 isaac john 1-0 2011-2012 12 william kate 0-1 2011-2012 13 john bobby 1-0 2011-2012 etc Let us say that the user wants to see all the results of player john in the 2010-2011 season. The following query (probably quite naively) gives me the error "supplied argument is not a valid MySQL result resource": $result_personal = mysql_query("SELECT * FROM results WHERE name_white = '$seleted_name' AND name_black = '$selected_name' AND season id ='$selected_season'"); Could anyone help me steer in the right direction? Should I use a JOIN query instead? Or a IN query? All the best and thanks in advance for your time, Wouter.
  3. Thanks very much for your helpful tips. Using sessions turned out to do the trick.
  4. Wow! We're getting really close. Thank you very much! The page now opens the data which I set to the default value and the sort function works perfectly when the column headers are clicked. Also, when the user changes the data she or he wants to see by selecting an option from the listbox, the new data is being displayed perfectly. However, the last bit of trouble is that the sort function only works for the first, default data. When the user changes to a new set of data, clicking on the column header now resets the page to the default value, and we're back at the start again. Here are the essential parts of the code: First the html code for the listbox: <form action="index.php" method="get"> <select name="selectedoption"> <option value ="1">1</option> <option value ="2">2</option> etc... </select> <input name="submitbutton" type="submit" value="Choose" /> </form> Then the php code for setting the selectedoption variable and the default data to display: <?php if (isset($_GET['selectedoption'])) { $selectedoption = $_GET['selectedoption']; } else { $selectedoption = 2; //change it to whatever you want... } ?> Finally the php code for sorting the data by clicking the column headers <?php include 'includes/connection.php'; $Default = 'nr'; $Columns = array('nr','name', ...); $sort = isset($_GET['sort']) && in_array($_GET['sort'], $Columns) ? $_GET['sort'] : $Default; $order = (isset($_GET['order']) && strcasecmp($_GET['order'], 'DESC') == 0) ? 'DESC' : 'ASC'; $result = mysql_query("SELECT * FROM table WHERE id = '$selectedoption' ORDER BY $sort $order"); ?> <table border='0' cellpadding='3'> <tr> <td><a href='?sort=nr&order=<?php echo $order == 'DESC' ? 'ASC' : 'DESC' ?>'>Nr</a></td> <td><a href='?sort=name&order=<?php echo $order == 'DESC' ? 'ASC' : 'DESC' ?>'>Name</a></td> ... </tr> <?php while ($row = mysql_fetch_assoc($result)) { echo "<tr> <td>$row[nr]</td> <td>$row[name]</td> ... </tr>"; } echo "</table>"; ?> Does anyone know how I can get the sort script to run without setting the data to the default value? Thank in advance for your time. All the best, Wouter.
  5. Hey there, I´ve got an index.php page that displays data from a database. (SELECT * FROM table WHERE id=1 ORDER BY $sort $order) The user can then sort this data by clicking on the column header. This works fine. Now I´d like to add a listbox so the user can also change the data (id=2, id=3, etc.) she/he wishes to sort. This is where I run into a little trouble. The query I'm trying to use to display the data is SELECT * FROM table WHERE id = '$selectedoption' ORDER BY $sort $order The selectedoption variable is $selectedoption = $_GET['selectedoption']; and the listbox code starts like this <form action="index.php" method="get"> <select name="selectedoption"> <option value ="1">1</option> <option value ="2">2</option> etc. Now the page doesn't display any information at all, until the user selects 1 or 2 or etc. More importantly: the page then loses the ability to sort, because clicking on any of the column headers now brings us back to the empty page. Could anyone give me a tip of where to go next? All the best. Wouter.
  6. Thanks a lot for your help and for pointing me towards sound database design. I shall have some reading to do from now on. All the best, Wouter.
  7. Thank you both for thinking along with me! I think I can safely conclude that I should rethink the design of my database. Instead of one database with a long list of tables (each table representing one played round and consisting of 11 columns and 26 rows) I now have one database with only two tables: one table with only one column called round_id (primary key) and one table now consisting of 12 columns (nr, name, points, games played, wins, losses, etc. and an extra column called round_id which is indexed and foreign keyed and linked to the primary key of the first table) and many sets of 26 rows (the number of players each round). Could you point me in the direction of where to go next? How should I go about displaying portions of the second table (for instance only the 26 rows and 11 columns with the round_id of 10) and let the user choose which round to view (for instance through a list box)? Please do feel free not to post perfect and long lines of code, as I am fully aware that understanding the concepts behind the code is much more valuable than copying and pasting a code you provide without me grasping why it works. All the best for now.
  8. Dear everyone, I am reasonably new to php, so there is a chance that what I am asking for may exceed my grasp. Nevertheless I'd like to try: Is it possible to let the user choose (by using a drop down listbox for instance) which table from a database to display on a page? And/or which database to display on a page? Background information: I'm working on a website for my chess club. I've already got a working page (html,css) with a table of the standings (mysql, php) of the latest round (with position number, name, points, wins, losses, etc). By clicking on the column header, it sorts the respective column. What I'd finally like to do is let the user choose to display a different round (table), or even a different season (database). I could make a seperate page for each round, but I'd like to know if there's a more elegant way to do this by using only one page and one or more databases. Thanks in advance for any tips and best wishes from The Netherlands, Wouter.
×
×
  • 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.