<html>
<head></head>
<body>
<?php
$id=$_GET['id'];
$hostname = "localhost";
$username = "jesus";
$password = "jesus";
$dbid = "jesus_jesus";
$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die("unable to connect");
$result=mysql_query("select * from jobs where owns='$id'");
while($myrow = mysql_fetch_array($result))
{
print "<option value='$myrow[0]' selected>$myrow[1]</option>";
}
?>
</body>
</html>

In this code i need first value selected default.i execute this code my last database value selected default.is any database solution to find the first position.so i can use if loof.
something like this.

while($myrow = mysql_fetch_array($result))
{
if(myrow[0] == first)
print "<option value='$myrow[0]' selected>$myrow[1]</option>";
else
print "<option value='$myrow[0]'>$myrow[1]</option>";
}

this should do it. any problems let me know.

<html>
<body>
<?php

$host = 'localhost';
$user = 'jesus';
$pass = 'jesus';
$db   = 'jesus_jesus';

$con = mysql_connect($host,$user,$pass) or die('Error: Could not connect');
mysql_select_db($db) or die ('Error: Could not select database');

$id = $_GET['id'];
$sql   = "SELECT * FROM `jobs` WHERE `owns` = '" . $id . "'";
$query = mysql_query($sql, $con);
$sel = '<select name="something">';
$i = 0;
while ($row = mysql_fetch_row($query)) {
	if ($i == 0) {
		$value = 'SELECTED value="' . $row[0] . '"';
	}
	else {
		$value = 'value="' . $row[0] . '"';
	}
	$sel .= '<option ' . $value . '>' . $row[1] . '</option>';
$i++;
}
$sel .= '</select>';

echo $sel;

?>
</body>
</html>

it's working .thank u
:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.