newbtophp Posted September 11, 2009 Share Posted September 11, 2009 Im having some trouble, i am echoing info from a table in to drop down options, the problem is i only want to echo one of each, so say if their were 10 of the same option, I'd only echo the first (1) option. Im guessing preg_match? Heres my code: <select name="script" id="script"> <option value="" selected>- Script -</option> <?php //Include connection include("conn.php"); $sql = "SELECT * FROM scripts"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { ?> <option value="<? echo $row["script"]; ?>"><? echo $row["script"]; ?></option> <? } ?> </select> Like for example: Drop down echos: awesome, awesome, awesome, I'd only echo the first awesome, the reason i need to echo first, is because its attached to an id. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/173923-solved-match-help/ Share on other sites More sharing options...
rhodesa Posted September 11, 2009 Share Posted September 11, 2009 how about: <select name="script" id="script"> <option value="" selected>- Script -</option> <?php //Include connection include("conn.php"); $sql = "SELECT DISTINCT(script) FROM scripts"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { ?> <option value="<? echo $row["script"]; ?>"><? echo $row["script"]; ?></option> <? } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/173923-solved-match-help/#findComment-916837 Share on other sites More sharing options...
newbtophp Posted September 11, 2009 Author Share Posted September 11, 2009 That worked fine, but it dont display the first option/match, the reason i know this is because Im echo'ing the options and then using file_get_contents, and the results are arranged like: newest at the bottom and oldest at the top. But i want: Newest at the top and oldest at bottom. Anyway to solve that? Maybe this will help (the code im using for file_get_contents) <?php $url = "http://www.site.com/test.php"; $rurl = file_get_contents($url); $i = 1; while($i <= 5) { $start = explode('<b>PDFSearch', $rurl); $end = explode('<br><br>', $start[$i]); $table .= $end[0]; $i++; } echo $table; ?> Quote Link to comment https://forums.phpfreaks.com/topic/173923-solved-match-help/#findComment-916842 Share on other sites More sharing options...
rhodesa Posted September 11, 2009 Share Posted September 11, 2009 is there a field in the DB you can sort by? like an auto_increment id? assuming it's called script_id, you would just do: <select name="script" id="script"> <option value="" selected>- Script -</option> <?php //Include connection include("conn.php"); $sql = "SELECT DISTINCT(script) FROM scripts ORDER BY script_id DESC"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { ?> <option value="<? echo $row["script"]; ?>"><? echo $row["script"]; ?></option> <? } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/173923-solved-match-help/#findComment-916860 Share on other sites More sharing options...
newbtophp Posted September 16, 2009 Author Share Posted September 16, 2009 Thanks solved! Quote Link to comment https://forums.phpfreaks.com/topic/173923-solved-match-help/#findComment-919687 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.