rockinaway Posted January 12, 2007 Share Posted January 12, 2007 I was wondering is there any way I can check to see if a link has been clicked. As I am making a memberlist page with alphabetical letter sorting and I want to check if a user has clicked a letters link to sort... how can I do this? Quote Link to comment Share on other sites More sharing options...
papaface Posted January 12, 2007 Share Posted January 12, 2007 You could use GET. When someone clicks sort by something make the URL somepage.php?sort=alphaThen make a script or implement it into an existing one, to sort the data alphabetically by getting $_GET['sort']. Quote Link to comment Share on other sites More sharing options...
rockinaway Posted January 12, 2007 Author Share Posted January 12, 2007 I have listed the alphabet and made a link in a variable for each letter... I have ?sortal after my file name.. so what would I do.. if I wanted to check it in an IF statement?[code]if ($_GET['sortal']){}[/code]Sorry if I am stupid and dumb.. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted January 12, 2007 Share Posted January 12, 2007 So you have links similar to <a href="yourpage.php?sortal=a">A</a> etc?Well then this is how i would do it:<?php$letter = mysql_real_escape_string($_GET['sortal']);//using mysql_real_escape_string to prevent any malicous use of the sort$sql = "SELECT * FROM `yourtable` WHERE `userfield` LIKE '$letter%'";mysql_query($sql) or die (mysql_error());?>You use LIKE to allow you to place wildcard matches in your search term. A % siginfies any number of any character, and an underscore is used for one character of any type. Here, you want the letter that has been selected followed by any number of other characters. If no letter has been selected, then you would have a searchterm of just % in which case all results would be found. Quote Link to comment Share on other sites More sharing options...
rockinaway Posted January 12, 2007 Author Share Posted January 12, 2007 When I try that I get 'Notice: Undefined index: sortal'What do I do now?to add here is an example of the link..$sortbyal = '<a href="domain.com/file.php?sortal='.chr($var).'">A</a> Quote Link to comment Share on other sites More sharing options...
trq Posted January 12, 2007 Share Posted January 12, 2007 You need to wrap the code within an if statement, $_GET['sortal'] will only exist if the link has been clicked. So...[code]<?php if (isset($_GET['sortal'])) { $letter = mysql_real_escape_string($_GET['sortal']);//using mysql_real_escape_string to prevent any malicous use of the sort $sql = "SELECT * FROM `yourtable` WHERE `userfield` LIKE '$letter%'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { while ($row = mysql_fetach_assoc($result)) echo $row['username']."<br />"; } } } }?>[/code]Ive also extended the query a little to actually display the data. Quote Link to comment Share on other sites More sharing options...
rockinaway Posted January 12, 2007 Author Share Posted January 12, 2007 [code] LIKE '.$sortal%'');[/code]I get an error in SQL SyntaxAlso another thing, once the person has clicked and gone to the new page I want the click to be reset so the changes that occur from clicking do not occur again until they click.. Quote Link to comment Share on other sites More sharing options...
trq Posted January 12, 2007 Share Posted January 12, 2007 It should be...[code]LIKE '.$letter%'');[/code] Quote Link to comment Share on other sites More sharing options...
rockinaway Posted January 12, 2007 Author Share Posted January 12, 2007 Same problem.. it needs the second . else it doesn't seem to work without error.Also another thing, once the person has clicked and gone to the new page I want the click to be reset so the changes that occur from clicking do not occur again until they click.. Quote Link to comment 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.