Jump to content

[SOLVED] Match help


newbtophp

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/173923-solved-match-help/
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/173923-solved-match-help/#findComment-916837
Share on other sites

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;
                
?>

Link to comment
https://forums.phpfreaks.com/topic/173923-solved-match-help/#findComment-916842
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/173923-solved-match-help/#findComment-916860
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.