Schlo_50 Posted February 15, 2008 Share Posted February 15, 2008 Hey guys, I have passed $_GET['clienta'] from a.php to b.php. On b.php I have a drop menu which is linked to a flatfile database. I need to adapt the code below to get the drop menu to only display the values associated with $_GET['clienta']. I have had a go but it displays all values. <?php print "<select name=\"category\">"; $file = file("../usercats.txt"); foreach($file as $Key => $Val){ $Data[$Key] = explode("|", $Val); $username = trim($Data[$Key][0]); $catname = trim($Data[$Key][1]); $catid = trim($Data[$Key][2]); if($_GET['clienta'] == $username) { print "<option value=\"$catid\">$catname</option>"; } } print "</select>"; ?> Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/91258-_get-variable/ Share on other sites More sharing options...
rhodesa Posted February 15, 2008 Share Posted February 15, 2008 try this out: <?php print "<select name=\"category\">"; $file = file("../usercats.txt"); foreach($file as $line){ list($username,$catname,$catid) = explode("|",$line,3); if($_GET['clienta'] == $username) { print "<option value=\"$catid\">$catname</option>"; } } print "</select>"; ?> if that doesn't work, please post a snippet of usercats.txt Link to comment https://forums.phpfreaks.com/topic/91258-_get-variable/#findComment-467664 Share on other sites More sharing options...
Schlo_50 Posted February 15, 2008 Author Share Posted February 15, 2008 I used your snippet but it didn't work. <form name="form1" method="post" action="?id=uploadtest"> <table width="500" border="0" cellspacing="0" cellpadding="2"> <tr> <td width="138" class="text"><img src="images/point.png" width="11" height="8" border="0" />Client</td> <td width="354" class="text"> <?php if(isset($_POST['submit'])) { $var = $_POST['clienta']; print $_POST['clienta']; } print "<select name=\"clienta\">"; $filea = file("../users.txt"); foreach($filea as $Keya => $Vala){ $Dataa[$Keya] = explode("|", $Vala); $client = $Dataa[$Keya][0]; print "<option value=\"$client\">$client</option>"; } print "</select>"; ?></td> </tr> </table> <input name="submit" type="submit" value="submit"> </form> This is the script which is meant to pass the variable, but i think this is the problem. Link to comment https://forums.phpfreaks.com/topic/91258-_get-variable/#findComment-467677 Share on other sites More sharing options...
rhodesa Posted February 15, 2008 Share Posted February 15, 2008 Try my code with if($_POST['clienta'] == $username) { instead of if($_GET['clienta'] == $username) { Link to comment https://forums.phpfreaks.com/topic/91258-_get-variable/#findComment-467683 Share on other sites More sharing options...
Schlo_50 Posted February 15, 2008 Author Share Posted February 15, 2008 Seems to have done the trick. Thanks alot! Link to comment https://forums.phpfreaks.com/topic/91258-_get-variable/#findComment-467699 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.