PHP - League Position In Mysql
I have a query at the moment that gives a name, number of rides and number of points
SELECT COUNT( `points` ) AS 'rides', SUM( `points` ) AS 'pts', rider_name FROM tbl_heat WHERE card_id = $card GROUP BY `rider_name` ORDER BY pts DESCwhat I want to do now is add the position in a league table, I have tried amending the query and have the following SELECT @serial := @serial +1 AS pos, rider_name FROM( SELECT COUNT( `points` ) AS 'rides', SUM( `points` ) AS 'pts', rider_name FROM tbl_heat JOIN ( SELECT @serial :=0 ) AS init WHERE card_id = $card GROUP BY `rider_name` ORDER BY pts DESC ) as sortedhowever this query doesn't give what I am after, not sure how far off getting it right, any help would be great Similar TutorialsI have finally worked out how to get a football league table query up and running (mainly by stealing code from elsewhere and adapting it to work the way I want it to!) but need to try to tweak it for a couple of other pages. The test page with it on is at http://www.margate-fc.com/content/test/table.php The query is $i = 1; $ht = "g.home_team = t.team_id"; $at = "g.away_team = t.team_id"; $hw = "g.home_goals > g.away_goals"; $aw = "g.home_goals < g.away_goals"; $d = "g.home_goals = g.away_goals"; $hg ="g.home_goals"; $ag ="g.away_goals"; $table = mysql_query("SELECT t.team_name as Tm, @rownum := @rownum+1 AS rank , (sum(CASE WHEN (".$ht." AND ".$hw.")OR(".$at." AND ".$aw.") THEN 3 ELSE 0 END) + sum(CASE WHEN (".$ht." OR ".$at.") AND ".$d." THEN 1 ELSE 0 END)) AS P , (sum(CASE WHEN (".$ht." AND ".$hw.") THEN 3 ELSE 0 END) + sum(CASE WHEN (".$ht.") AND ".$d." THEN 1 ELSE 0 END)) AS HP , (sum(CASE WHEN (".$at." AND ".$aw.") THEN 3 ELSE 0 END) + sum(CASE WHEN (".$at.") AND ".$d." THEN 1 ELSE 0 END)) AS AP , count(CASE WHEN (".$ht." OR ".$at.") THEN 1 ELSE 0 END) as GP , sum(CASE WHEN (".$ht." ) THEN 1 ELSE 0 END) as HGP , sum(CASE WHEN ".$at." THEN 1 ELSE 0 END) as AGP , sum(CASE WHEN (".$ht." AND ".$hw.") OR (".$at." AND ".$aw.") THEN 1 ELSE 0 END) AS W , sum(CASE WHEN (".$ht." AND ".$hw.") THEN 1 ELSE 0 END) AS HW , sum(CASE WHEN (".$at." AND ".$aw.") THEN 1 ELSE 0 END) AS AW , sum(CASE WHEN (".$ht." AND ".$d.") OR (".$at." AND ".$d.") THEN 1 ELSE 0 END) AS D , sum(CASE WHEN (".$ht." AND ".$d.") THEN 1 ELSE 0 END) AS HD , sum(CASE WHEN (".$at." AND ".$d.") THEN 1 ELSE 0 END) AS AD , sum(CASE WHEN (".$ht." AND ".$aw.") OR (".$at." AND ".$hw.") THEN 1 ELSE 0 END) AS L , sum(CASE WHEN (".$ht." AND ".$aw.") THEN 1 ELSE 0 END) AS HL , sum(CASE WHEN (".$at." AND ".$hw.") THEN 1 ELSE 0 END) AS AL , SUM(CASE WHEN (".$ht.") THEN ".$hg." WHEN (".$at.") THEN ".$ag." END) as GF , SUM(CASE WHEN (".$ht.") THEN ".$hg." END) as HGF , SUM(CASE WHEN (".$at.") THEN ".$ag." END) as AGF , SUM(CASE WHEN (".$ht.") THEN ".$ag." WHEN (".$at.") THEN ".$hg." END) as GA , SUM(CASE WHEN (".$ht.") THEN ".$ag." END) as HGA , SUM(CASE WHEN (".$at.") THEN ".$hg." END) as AGA , (SUM(CASE WHEN (".$ht.") THEN ".$hg." WHEN (".$at.") THEN ".$ag." END) - SUM(CASE WHEN (".$ht.") THEN ".$ag." WHEN (".$at.") THEN ".$hg." END)) as GD , (SUM(CASE WHEN (".$ht.") THEN ".$hg." END) - SUM(CASE WHEN (".$ht.") THEN ".$ag." END)) as HGD , (SUM(CASE WHEN (".$at.") THEN ".$ag." END) - SUM(CASE WHEN (".$at.") THEN ".$hg." END)) as AGD from teams t left join all_games g on t.team_id in (g.home_team,g.away_team) WHERE comp = '1' AND home_goals IS NOT NULL AND date BETWEEN '2010-07-01' AND '2011-06-31' GROUP BY t.team_id ORDER BY P desc, GD desc, GF desc and the html (although some of the css still is not done and some code still needs tidying) is Code: [Select] <table width="" border="0" cellpadding="0" cellspacing="0" BORDER=1 RULES=ROWS FRAME=BOX> <tr> <td></td><td></td> <td colspan="9" align="center" bgcolor="#00FF99">ALL</td> <td colspan="9" align="center" >Home</td> <td colspan="9" align="center">Away</td> </tr> <tr> <td class="hdcell" >POS</td> <td class="hdcell" >Team</td> <td width="30" class="hdcell">P</td> <td width="30" class="hdcell">W</td> <td width="30" class="hdcell">D</td> <td width="30" class="hdcell">L</td> <td width="30" class="hdcell">F</td> <td width="30" class="hdcell">A</td> <td width="30" class="hdcell">GD</td> <td width="30" class="hdcell">Pts</td> <td width="30" class="hdcell"></td> <td></td> <td width="30" class="hdcell">P</td> <td width="30" class="hdcell">W</td> <td width="30" class="hdcell">D</td> <td width="30" class="hdcell">L</td> <td width="30" class="hdcell">F</td> <td width="30" class="hdcell">A</td> <td width="30" class="hdcell">GD</td> <td width="30" class="hdcell">Pts</td> <td></td> <td width="30" class="hdcell">P</td> <td width="30" class="hdcell">W</td> <td width="30" class="hdcell">D</td> <td width="30" class="hdcell">L</td> <td width="30" class="hdcell">F</td> <td width="30" class="hdcell">A</td> <td width="30" class="hdcell">GD</td> <td width="30" class="hdcell">Pts</td> </tr> <?php while ($row_table = mysql_fetch_assoc($table)){ echo '<tr> <td style="text-align:left" width="30">'.$i.'</td>'; echo '<td style="text-align:left">'.$row_table['Tm'].'</td> <td style="text-align:left">'.$row_table['GP'].'</td> <td style="text-align:left">'.$row_table['W'].'</td> <td style="text-align:left"> '.$row_table['D'].'</td> <td style="text-align:left"> '.$row_table['L']. '</td> <td style="text-align:left"> '.$row_table['GF']. '</td> <td style="text-align:left"> '.$row_table['GA']. '</td> <td style="text-align:left"> '.$row_table['GD']. '</td> <td style="text-align:left"> '.$row_table['P']. '</td> <td style="text-align:left"></td> <td style="text-align:left"></td> <td style="text-align:left">'.$row_table['HGP'].'</td> <td style="text-align:left">'.$row_table['HW'].'</td> <td style="text-align:left">'.$row_table['HD'].'</td> <td style="text-align:left"> '.$row_table['HL']. '</td> <td style="text-align:left"> '.$row_table['HGF']. '</td> <td style="text-align:left"> '.$row_table['HGA']. '</td> <td style="text-align:left"> '.$row_table['HGD']. '</td> <td style="text-align:left"> '.$row_table['HP']. '</td> <td style="text-align:left"></td> <td style="text-align:left">'.$row_table['AGP'].'</td> <td style="text-align:left">'.$row_table['AW'].'</td> <td style="text-align:left">'.$row_table['AD'].'</td> <td style="text-align:left"> '.$row_table['AL']. '</td> <td style="text-align:left"> '.$row_table['AGF']. '</td> <td style="text-align:left"> '.$row_table['AGA']. '</td> <td style="text-align:left"> '.$row_table['AGD']. '</td> <td style="text-align:left"> '.$row_table['AP']. '</td> </tr>'; $i++; } ?> </table> As I said, this works fine in the test page but there are two other things that I am looking to do with it and one way I hope to streamline the code. Firstly the code bit..... There is a bit of replication that I was hoping to eliminate by using the sum function but from what I can see this cannot be done with Alias's. I was hoping to change the code , sum(CASE WHEN (".$ht." AND ".$hw.") OR (".$at." AND ".$aw.") THEN 1 ELSE 0 END) AS W , sum(CASE WHEN (".$ht." AND ".$hw.") THEN 1 ELSE 0 END) AS HW , sum(CASE WHEN (".$at." AND ".$aw.") THEN 1 ELSE 0 END) AS AW to , sum(HW + PW) AS W , sum(CASE WHEN (".$ht." AND ".$hw.") THEN 1 ELSE 0 END) AS HW , sum(CASE WHEN (".$at." AND ".$aw.") THEN 1 ELSE 0 END) AS AW but that just causes no records to be shown. Is there a way around this or is there no way to aggregate alias's? Secondly, the other pages. There are 2 other pages that I want to use similar data on and I think what I want to do is quite simple. On the front page of the site I want a stripped down version of the table which shows just five records, that of my team, Margate, and the two positions above and two below. At the moment Margate are in 19th position so I would want it to show rows 17,18,19,20,21. If Margate were 10th I would want it to show 8,9,10,11,12. I would imagine that there is a way of finding which position Margate is in then setting the OFFSET to that -2 but after extensive Googling (I did spot it in exactly the context I need some time back when I did not need it!) I cannot find anything as I basically do not know what I need to ask for! The final thing is that each team has its own page and on that page I want to show their position in the League in a friendly style, such as 19th as opposed to 19. I would imagine that I would need to pull the whole league table in as opposed to using a query that matches the team otherwise it would only have one result and each team would show as being 1st. I would only want to show the position of the relevant team but obviously the whole query would need to be run to get that position. How would I then find the relative teams position? I think that the ideal thing would be to use a VIEW but am working with a MySQL 4 database. Any help or advice will, as always, be appreciated. Thanks in advance Steve Hi all, this is my first post on this site. I've built a few amateur sites in the past but am keen to utilize php combined with mysql for my current project. However, I have little knowledge of php and am just picking it up as I go (same way I've done for all my computer knowledge) What I'm looking for may sound simple, but I really don't know where to start and I'm hoping there are some kind souls here that will lend a hand. SQL Database Name Score John 42 Peter 46 Michael 56 Angela 46 (many rows like this) I am looking to output on my page a table of the top ten scores like this. However it's not quite that simple, should there be a tie on any score I want it to appear like so: 1. Michael 56 2. Angela 46 Peter 46 4. John 42 (onwards to 10) I want this to run from positions 1 thru 10, but should the 10th score in the database be equal to the 11th (12th, 13th etc) I would like them displayed too. For example: 9. Rafael 31 10. Sandy 29 Bernard 29 Jackie 29 Is this possible or would I be better off just sorting the info in excel and hard coding the info everytime? Hope somebody can help. Thanks in advance. Hi All I am trying to insert a feed on my site that automatically updates the football league etc like this one http://news.bbc.co.uk/sport1/hi/football/eng_div_1/table/default.stm is there a way to do this please? thanks I have this code:
<td><form action="" method="post" name="TableData" class="style5" id="TableData"> <table width="800" border="0" bordercolor="#000000" background="Assets/Tablebar.gif"> <!--DWLayoutTable--> <tr> <td width="183" height="20" align="center"><div align="center" class="style11 style1"></div></td> <td width="317" align="center"><div align="center" class="style11"><span class="style2"><?php echo $row_TableData['UserID']; ?></span></div></td> <td width="136" align="center"><div align="center" class="style11"><span class="style2"><?php echo $row_TableData['UserName']; ?></span></div></td> <td width="136" align="center"><div align="center" class="style2 style11"><span class="style11"><span class="style2"><?php echo $row_TableData['Score']; ?></span></span></div></td> <td width="103" align="center" valign="top"><span class="style2 style11"> <?php for($i = 0; $i < $row_TableData['TourWins']; $i++) { echo '<img src="Assets/Medal.gif" />'; } ?> </span></td> </tr> </table> </form> </td> The Table displays fine and it sorts fine win Highest to lowest score, I am wanting to put place numbers Like 1,2,3,4 etc in the first Colom which is in bold, but I don't know what to use. any help would be great. Hi Everyone, I was looking for some direction on how to go about this. A client has asked to set up a small league table with 12 teams where simply they can add fixtures and the result of that fixture. So pending on what the result is if they win they get 2 points and if they loose they get nothing and this will determine what position they are in the league table. Any help on this matter would be greatly appreciated even a small step in the right direction Thanks Barry Is there a way to get the mysql's internal pointer position? I have searched Google, found this: Code: [Select] <?php function mysql_pointer_position($result_set) { $num_rows = mysql_num_rows($result_set); $i = 0; while($result = mysql_fetch_array($result_set)) { $i++; } $pointer_position = $num_rows - $i; //Return pointer to original position if($pointer_position <= $num_rows - 1) { mysql_data_seek($result_set, $pointer_position); } return $pointer_position; } ?> But I don't really like it. Is there a better way to find the current position of the internal pointer? Hey guys. Me again... Essentially what i am doing is pulling data from a MySQL database about the number of thumbnails on a page. The user can then change this using a <select> dropdown menu. How ever, i want the <select> to default to the amount already specified by the Database. I know i can do this by inserting a Selected attribute to one of the <options> but what is the best way of doing this? Heres my code.. $NumberOfThumbnails = mysql_result($data, 0,"NumberOfThumbnails"); <select name="numberofthumbnails"> <option value="0">None</option> <option value="2">2</option> <option value="4">4</option> <option value="6">6</option> <option value="8">8</option> <option value="10">10</option> <option value="12">12</option> <option value="14">14</option> <option value="16">16</option> <option value="18">18</option> <option value="20">20</option> <option value="22">22</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> </select> Thanks - Danny create table mimi (mimiId int(11) not null, mimiBody varchar(255) ); <?php //connecting to database include_once ('conn.php'); $sql ="SELECT mimiId, mimiBody FROM mimi"; $result = mysqli_query($conn, $sql ); $mimi = mysqli_fetch_assoc($result); $mimiId ='<span>No: '.$mimi['mimiId'].'</span>'; $mimiBody ='<p class="leading text-justify">'.$mimi['mimiBody'].'</p>'; ?> //what is next? i want to download pdf or text document after clicking button or link how to do that Hello. i have created a template in dreamweaver, however when i added php code to a page the position of my bottom div got messed up... it works 100% with just text. I have a container div with other divs in it. inside the container div i have a div named content, and this div is the only div which is editable. in the bottom (outside of the container div) i have a bottom div which is centered with margin:0 auto; this divs position gets totally messed up once i add php code in the content div. http://elevweb.skit.no/0111nema/action_adventure.php here is the link to the page with php with it, as u can see the div with facebook etc in it got a messed up position. Hi, I have 2 pages, config.php and category.php config.php is Code: [Select] class CategoryWork { public $form = ""; public $error = ""; public $add_form = "<br /><p><strong>Add New Category</strong></p><form id=\"form1\" name=\"form1\" method=\"post\" action=\"category.php?action=add\"> <table width=\"550\" height=\"170\" border=\"0\"> <tr> <td width=\"153\">Name :</td> <td colspan=\"2\"><label for=\"cat_name\"></label> <input name=\"cat_name\" type=\"text\" id=\"cat_name\" size=\"50\" maxlength=\"50\" /></td> </tr> <tr> <td>Slug :</td> <td colspan=\"2\"><label for=\"cat_slug\"></label> <input name=\"cat_slug\" type=\"text\" id=\"cat_slug\" size=\"50\" maxlength=\"50\" /></td> </tr> <tr> <td>Description</td> <td colspan=\"2\"><label for=\"cat_desc\"></label> <textarea name=\"cat_desc\" id=\"cat_desc\" cols=\"48\" rows=\"10\"></textarea></td> </tr> <tr> <td> </td> <td width=\"97\"><input type=\"submit\" name=\"button\" id=\"button\" value=\"Submit\" /></td> <td width=\"286\"><input type=\"reset\" name=\"button2\" id=\"button2\" value=\"Reset\" /></td> </tr> <tr> <td> </td> <td colspan=\"2\"></td> </tr> </table> </form>"; public $edit_form1_first = "<br /><p><strong>Edit Category</strong></p><form id=\"form1\" name=\"form1\" method=\"post\" action=\"category.php?action=edit\"> <table width=\"454\" height=\"79\" border=\"0\"> <tr> <td width=\"110\">Category :</td> <td width=\"334\"><label for=\"select\"></label> <select name=\"select_cat\" id=\"select\">"; public $edit_form1_last = "</select> </td> </tr> <tr> <td> </td> <td><input type=\"submit\" name=\"button\" id=\"button\" value=\"Submit\" /></td> </tr> </table> </form>"; public $invalid_get_error = "<br /><br /><p><font color=\"#990000\"><strong><em>ERROR : Invalid Option.</em></strong></font></p>"; public function CheckAction($action){ if(!isset($action)) { header("Location:dashboard.php"); } else { $action = $action; if($action == "add") { $this->form = NULL; $this->form = $this->add_form; } else if ($action == "edit") { $this->form = NULL; $this->form = $this->GenerateDropDown(); } else if ($action == "del") { $this->form = "del"; } else { $this->form = $this->invalid_get_error; } // if else .. else if ends here }// if else ends here } // Function CheckAction ends public function ValidateAddForm($name, $slug, $desc){ if(isset($name) || isset($slug) || isset($desc)) { if($name == NULL || $slug == NULL || $desc == NULL) { $this->error = "<br /><br /><p><font color=\"#990000\"><strong><em>ERROR : All 3 fields are required.</em></strong></font></p>"; } else { // Data Insert in database $name = $name; $slug = $slug; $desc = $desc; $check_category_query = "SELECT * FROM category where slug = '$slug'"; $check_category_result = mysql_query($check_category_query); $check_category_count = mysql_num_rows($check_category_result); if($check_category_count == 1) { $this->error = "<br /><br /><p><font color=\"#990000\"><strong><em>ERROR : Slug Already exists.</em></strong></font></p>"; } else if ($check_category_count == 0) { // Do insertion in database $categoryinsert_query = "INSERT INTO category (name, slug, description) VALUES ('$name', '$slug', '$desc')"; $categoryinsert_result = mysql_query($categoryinsert_query); $this->error = "<br /><br /><font color=\"#009900\"><p><em><strong>Success, Category added.</strong></em></p></font>"; } } } } // function ends here public function GenerateDropDown(){ $dropdown_query = "SELECT * FROM category ORDER BY name"; $dropdown_result = mysql_query($dropdown_query); echo $this->edit_form1_first; while($row = mysql_fetch_array($dropdown_result)) { echo "<option value=".$row['id'].">".$row['name']."</option>"; } echo $this->edit_form1_last; } // end of GenerateDropDown function } Here is the code of category.php page Code: [Select] <?php include('config.php'); $system = new SystemAdmin; $categorywork = new CategoryWork; $system->ValidateToken($_COOKIE['token']); $categorywork->CheckAction($_GET['action']); $categorywork->ValidateAddForm($_POST['cat_name'], $_POST['cat_slug'], $_POST['cat_desc']); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Welcome <?php echo $system->username; ?></title> <?php echo $system->metalines; ?> <?php echo $system->slug_javascript; ?> </head> <body> <h1>Welcome <?php echo $system->username; ?>,</h1> <?php echo $system->mainmenu; ?> <?php echo $system->spryfunctions; ?> <?php echo $categorywork->error; ?> <?php echo $categorywork->form; ?> </body> </html> Problem is that when I go to /category.php?action=edit, it shows dropdown at the top of page and not at the position of <?php echo $categorywork->form; ?> I have attached a screenshot, please go through it. How can I solve this ? Second problem is how can I hide undefined index notice ? Hey Guys Ok I can postion text using the GD library using the following: Code: [Select] imagefttext($rImg, 13, 0, 105, 55, $black, $font_file,$Username); How would do the same using an image? For example Code: [Select] whateverfunction($rImg, 13, 0, 105, 55,$ImagePath); Thanks a million. guys i have a submit button that if(isset($_POST['sub_diplo'])) { $_SESSION['tmp']=$_SESSION['tmp']." counts "; } but tthe button is at the end of the page so when i press the button the page reloads and gose to start! exept that my code working! so is any way to move page to first location?? thanks Hey all, If I have a number like this: 1245 then I want a '.' inserted at position -2: 12.45 how do I do that in the most simple and elegant way? 74342 -> 743.42 I'm looking for one or two talented Laravel guys in the Dallas area who write clean code, document well, and love pushing the limits of their own abilities. It is important that the developers we hire are local. Please do not respond if you do not live in the Dallas area.
Preferred knowledge
- Laravel
- AngularJS
- NodeJS
- jQuery
- MySQL
- HTML/CSS
- e-Commerce
- Paranoid about security
- Performance minded
We are developing applications that will process millions of dollars in transactions every month. Performance, security, and the ability to scale is paramount.
Thank you
Hi all, Not sure if this is a browser feature kind of thing, or if it can be done with a script. I'm looking at my page: www.mysite.com/index.php?start=0 I scroll to the bottom of the page with the vertical scroll bar, and then click the pagation link to start on page 2, record #50: www.mysite.com/index.php?start=50 Of course, the vertical scroll bar jumps back to the it jumps to the top of my page. Is there a way to make it remember that the scroll bar was at the bottom (or in the middle)? Thanks. Hello everyone, I'm simply trying to move a character on a map. When the user selects a direction and a speed the character is moved on the map. Simple right? I've tried a few methods of doing this to no avail. I will list the different things I've tried. Code: [Select] <form action="index.php?do=move" method="post"> <select name="direction"> <option value="north" selected>North</option> <option value="south">South</option> <option value="east">East</option> <option value="west">West</option> </select> <select name="speed"> <option value="move0" selected>Feet +0</option> <option value="move1">Goat +1</option> <option value="move2">Donkey +2</option> <option value="move3">Cow +3</option> <option value="move4">Pig +4</option> <option value="move5">Horse +5</option> </select><br /> <input type="submit" name="post" value="Move"> </form> if (isset($_POST["post"])) { if (isset($_POST["direction"]) == "north") {$latitude++; if ($longitude > $controlrow["gamesize"]) { $latitude = $controlrow["gamesize"]; } } elseif ((isset($_POST["direction"]) == "north") AND (($_POST["speed"]) == "move1")) {$latitude++; if ($latitude > ($controlrow["gamesize"]*2)) { $latitude = ($controlrow["gamesize"]*2); } } elseif ((isset($_POST["direction"]) == "north") AND (($_POST["speed"]) == "move2")) {$latitude++; if ($latitude > ($controlrow["gamesize"]*3)) { $latitude = ($controlrow["gamesize"]*3); } } elseif ((isset($_POST["direction"]) == "north") AND (($_POST["speed"]) == "move3")) {$latitude++; if ($latitude > ($controlrow["gamesize"]*4)) { $latitude = ($controlrow["gamesize"]*4); } } elseif ((isset($_POST["direction"]) == "north") AND (($_POST["speed"]) == "move4")) {$latitude++; if ($latitude > ($controlrow["gamesize"]*5)) { $latitude = ($controlrow["gamesize"]*5); } } elseif ((isset($_POST["direction"]) == "north") AND (($_POST["speed"]) == "move5")) {$latitude++; if ($latitude > ($controlrow["gamesize"]*6)) { $latitude = ($controlrow["gamesize"]*6); } } elseif (isset($_POST["direction"]) == "south") {$latitude--; if ($latitude < ($controlrow["gamesize"]*-1)) { $latitude = ($controlrow["gamesize"]*-1); } } elseif ((isset($_POST["direction"]) == "south") AND (($_POST["speed"]) == "move1")) {$latitude--; if ($latitude < ($controlrow["gamesize"]*-2)) { $latitude = ($controlrow["gamesize"]*-2); } } elseif ((isset($_POST["direction"]) == "south") AND (($_POST["speed"]) == "move2")) {$latitude--; if ($latitude < ($controlrow["gamesize"]*-3)) { $latitude = ($controlrow["gamesize"]*-3); } } elseif ((isset($_POST["direction"]) == "south") AND (($_POST["speed"]) == "move3")) {$latitude--; if ($latitude < ($controlrow["gamesize"]*-4)) { $latitude = ($controlrow["gamesize"]*-4); } } elseif ((isset($_POST["direction"]) == "south") AND (($_POST["speed"]) == "move4")) {$latitude--; if ($latitude < ($controlrow["gamesize"]*-5)) { $latitude = ($controlrow["gamesize"]*-5); } } elseif ((isset($_POST["direction"]) == "south") AND (($_POST["speed"]) == "move5")) {$latitude--; if ($latitude < ($controlrow["gamesize"]*-6)) { $latitude = ($controlrow["gamesize"]*-6); } } elseif (isset($_POST["direction"]) == "east") {$longitude++; if ($longitude > $controlrow["gamesize"]) { $longitude = $controlrow["gamesize"]; } } elseif ((isset($_POST["direction"]) == "east") AND (($_POST["speed"]) == "move1")) {$longitude++; if ($longitude > ($controlrow["gamesize"]*2)) { $longitude = ($controlrow["gamesize"]*2); } } elseif ((isset($_POST["direction"]) == "east") AND (($_POST["speed"]) == "move2")) {$longitude++; if ($longitude > ($controlrow["gamesize"]*3)) { $longitude = ($controlrow["gamesize"]*3); } } elseif ((isset($_POST["direction"]) == "east") AND (($_POST["speed"]) == "move3")) {$longitude++; if ($longitude > ($controlrow["gamesize"]*4)) { $longitude = ($controlrow["gamesize"]*4); } } elseif ((isset($_POST["direction"]) == "east") AND (($_POST["speed"]) == "move4")) {$longitude++; if ($longitude > ($controlrow["gamesize"]*5)) { $longitude = ($controlrow["gamesize"]*5); } } elseif ((isset($_POST["direction"]) == "east") AND (($_POST["speed"]) == "move5")) {$longitude++; if ($longitude > ($controlrow["gamesize"]*6)) { $longitude = ($controlrow["gamesize"]*6); } } elseif (isset($_POST["direction"]) == "west") {$longitude--; if ($longitude < ($controlrow["gamesize"]*-1)) { $longitude = ($controlrow["gamesize"]*-1); } } elseif ((isset($_POST["direction"]) == "west") AND (($_POST["speed"]) == "move1")) {$longitude--; if ($longitude < ($controlrow["gamesize"]*-2)) { $longitude = ($controlrow["gamesize"]*-2); } } elseif ((isset($_POST["direction"]) == "west") AND (($_POST["speed"]) == "move2")) {$longitude--; if ($longitude < ($controlrow["gamesize"]*-3)) { $longitude = ($controlrow["gamesize"]*-3); } } elseif ((isset($_POST["direction"]) == "west") AND (($_POST["speed"]) == "move3")) {$longitude--; if ($longitude < ($controlrow["gamesize"]*-4)) { $longitude = ($controlrow["gamesize"]*-4); } } elseif ((isset($_POST["direction"]) == "west") AND (($_POST["speed"]) == "move4")) {$longitude--; if ($longitude < ($controlrow["gamesize"]*-5)) { $longitude = ($controlrow["gamesize"]*-5); } } elseif ((isset($_POST["direction"]) == "west") AND (($_POST["speed"]) == "move5")) {$longitude--; if ($longitude < ($controlrow["gamesize"]*-6)) { $longitude = ($controlrow["gamesize"]*-6); } } } Also if ((isset($_POST["post"]) == "north") && (isset($_POST["speed"]) == "move0")) { $latitude++; if ($latitude > $controlrow["gamesize"]) { $longitude = $controlrow["gamesize"]; } } else { if ((isset($_POST["post"]) == "north") && (isset($_POST["speed"]) == "move1")) { $latitude++; if ($latitude > ($controlrow["gamesize"]*2)) { $latitude = ($controlrow["gamesize"]*2); } } else { if ((isset($_POST["post"]) == "north") && (isset($_POST["speed"]) == "move2")) { $latitude++; if ($latitude > ($controlrow["gamesize"]*3)) { $latitude = ($controlrow["gamesize"]*3); } } else { if ((isset($_POST["post"]) == "north") && (isset($_POST["speed"]) == "move3")) { $latitude++; if ($latitude > ($controlrow["gamesize"]*4)) { $latitude = ($controlrow["gamesize"]*4); } } else { if ((isset($_POST["post"]) == "north") && (isset($_POST["speed"]) == "move4")) { $latitude++; if ($latitude > ($controlrow["gamesize"]*5)) { $latitude = ($controlrow["gamesize"]*5); } } else { if ((isset($_POST["post"]) == "north") && (isset($_POST["speed"]) == "move5")) { $latitude++; if ($latitude > ($controlrow["gamesize"]*6)) { $latitude = ($controlrow["gamesize"]*6); } } } } } } } Any help would be appreciated. If you need more info just ask. Thanks, Waffles Hi guys, thank for any help. This does not appear like a difficult problem but it has me stymied. I have several selects, the 1st item of each is "--Specify--" so that the user has to specifically choose an item. Once an item is selected on any select the others should be set to the 1st item or "--Specify--" to avoid confusion. If you want to see the complete code it on this web page: http://chordsandguitar.com/progressions-test.php The relevant code is: Code: [Select] if ($prog1_menu != "--Specify1--") { $prog2_menu = "--Specify--"; echo "set prog2 to Specify"; } if ($prog2_menu != "--Specify2--") { $prog1_menu = "--Specify--"; echo "set prog1 to Specify"; } echo "<form action = \"progressions-test.php?s_sort_all=$sort_all&s_prog1_menu=$prog1_menu&s_prog2_menu=$prog2_menu&s_prog1_trigged=$prog1_trigged&s_prog2_trigged=$prog2_trigged\" method = \"GET\">"; //also stores the values of the drop-downs when Select button is pushed so they can be retrieved when the web page is loaded again echo " Ascending bass line"; echo "<br />"; echo "Select a progression: <a href=\"http://www.chordsandguitar.com/progressions-test.php?s_sort_all=All&s_prog1_menu=--Select--&s_prog2_menu=--Select--\"\"><big>ALL</big></a>"; echo " "; echo "<select name=\"prog1_menu\" onchange=\"this.form.submit();\">"; echo "<option value=\"--Specify1--\">--Specify--</option>"; if ($prog1_menu == "ii-iii-IV-V progression") echo "<option SELECTED value=\"ii-iii-IV-V progression\">ii-iii-IV-V progression</option>"; else echo "<option value=\"ii-iii-IV-V progression\">ii-iii-IV-V progression</option>"; if ($prog1_menu == "I-ii-IV-V progression") echo "<option SELECTED value=\"I-ii-IV-V progression\">I-ii-IV-V progression</option>"; else echo "<option value=\"I-ii-IV-V progression\">I-ii-IV-V progression</option>"; if ($prog1_menu == "I-iii-IV-V progression") echo "<option SELECTED value=\"I-iii-IV-V progression\">I-iii-IV-V progression</option>"; else echo "<option value=\"I-iii-IV-V progression\">I-iii-IV-V progression</option>"; echo "</select>"; echo " "; echo "<select name=\"prog2_menu\" onchange=\"this.form.submit();\">"; echo "<option value=\"--Specify2--\">--Specify--</option>"; if ($prog2_menu == "I-sharpIo7-ii7-sharpIIo7 progression") echo "<option SELECTED value=\"I-sharpIo7-ii7-sharpIIo7 progression\">I-#Io7-ii7-#IIo7 progression</option>"; else echo "<option value=\"I-sharpIo7-ii7-sharpIIo7 progression\">I-#Io7-ii7-#IIo7 progression</option>"; if ($prog2_menu == "I-sharpIo7-ii7-V7 progression") echo "<option SELECTED value=\"I-sharpIo7-ii7-V7 progression\">I-#Io7-ii7-V7 progression</option>"; else echo "<option value=\"I-sharpIo7-ii7-V7 progression\">I-#Io7-ii7-V7 progression</option>"; echo "</select>"; echo "</form>"; I am trying to identify which select box has been used so that I can set all the other boxes to the 1st item but I wind up re-setting all the boxes. Cheers, Jacques This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=357646.0 Hello everyone, Sorry if this has been answered but if it has I can't find it anywhere. So, from the begining then. Lets say I had a member table and in it I wanted to store what their top 3 interests are. Their$ row has all the usual things to identify them userID and password etc.. and I had a further 3 columns which were labled top3_1 top3_2 & top3_3 to put each of their interests in from a post form. If instead I wanted to store this data as a PHP Array instead (using 1 column instead of 3) is there a way to store it as readable data when you open the PHPmyadmin? At the moment all it says is array and when I call it back to the browser (say on a page where they could review and update their interests) it displays 'a' as top3_01 'r' as top3_02 and 'r' as top3_03 (in each putting what would be 'array' as it appears in the table if there were 5 results. Does anyone know what I mean? For example - If we had a form which collected the top 3 interests to put in a table called users, Code: [Select] <form action="back_to_same_page_for_processing.php" method="post" enctype="multipart/form-data"> <input name="top3_01" type="text" value="enter interest number 1 here" /> <input name="top3_02" type="text" value="enter interest number 2 here" /> <input name="top3_03" type="text" value="enter interest number 3 here" /> <input type="submit" name="update_button" value=" Save and Update! " /> </form> // If my quick code example for this form is not correct dont worry its not the point im getting at :) And they put 'bowling' in top3_01, 'running' in top3_02 and 'diving' in top3_03 and we catch that on the same page with some PHP at the top --> Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' With me so far? If I had a table which had 3 columns (1 for each interest) I could put something like - Code: [Select] include('connect_msql.php'); mysql_query("Select * FROM users WHERE id='$id' AND blah blah blah"); mysql_query("UPDATE users SET top3_01='$top3_01', top3_02='$top3_02', top3_03='$top3_03' WHERE id='$id'"); And hopefully if ive got it right, it will put them each in their own little column. Easy enough huh? But heres the thing, I want to put all these into an array to be stored in the 1 column (say called 'top3') and whats more have them clearly readable in PHPmyadmin and editable from there yet still be able to be called back an rendered on page when requested. Continuing the example then, assuming ive changed the table for the 'top3' column instead of individual colums, I could put something like this - Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' $top3_array = array($top3_01,$top3_02,$top3_03); include('connect_msql.php'); mysql_query("UPDATE members SET top3='$top3_array' WHERE id='$id' AND blah blah blah"); But it will appear in the column as 'Array' and when its called for using a query it will render the literal string. a r r in each field instead. Now I know you can use the 'serialize()' & 'unserialize()' funtcions but it makes the entry in the database practically unreadable. Is there a way to make it readable and editable without having to create a content management system? If so please let me know and I'll be your friend forever, lol, ok maybe not but I'd really appreciate the help anyways. The other thing is, If you can do this or something like it, how am I to add entries to that array to go back into the data base? I hope ive explained myself enough here, but if not say so and I'll have another go. Thanks very much people, L-PLate (P.s if I sort this out on my own ill post it all here) |