Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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