i have two values in a table and instead of returning the values it returns the word "array" twice.

$mysql = new sqlConnection();
		
		$query = "SELECT DISTINCT status FROM  status ORDER BY status";
		$result = mysql_query($query) or die('Error, query failed');
	
		
		while ($row = mysql_fetch_array($result))
		{
	              echo "$row<br>";
		}
		$mysql->close();

Well with mysql_fetch_array you're telling it to get an associative array. To see the status use $row[status]

while ($row = mysql_fetch_array($result))
		{
	              echo $row[status] . "<br>";
		}

by status he means the name of the column

$row['a'];
$row['b'];

Well with mysql_fetch_array you're telling it to get an associative array. To see the status use $row[status]

while ($row = mysql_fetch_array($result))
		{
	              echo $row[status] . "<br>";
		}
you need to add ' ' in status.

       echo $row['status'];
you need to add ' ' in status.

       echo $row['status'];

Yes my bad...should have quotes around it.

Here is a more absolute way to print the information

while ($row = mysql_fetch_array($result))
{
   echo $row[0].'<br />';
}

This will give you the first queried object in the sql query line. if you add more to the sql query, each object queried is counted and place number incremented, starting with 0. Example

$query  = "SELECT name, subject, message FROM contact";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    echo "Name :{$row[0]} <br>" .
         "Subject : {$row[1]} <br>" . 
         "Message : {$row[2]} <br><br>";
}

would yield an output of

Name: Example
Subject: Something
Message: Sample output

Hope this helps!

now i only get the first option on the db how can i get every option in the db. in the array i have male and female. only male shows up in the list.

$mysql = new sqlConnection();
		$query = "SELECT DISTINCT status FROM  status ORDER BY status";
		$result = mysql_query($query) or die('Error, query failed');
		echo "<label for = 'sex'>Sexo:</label>
			<select id = 'sex' name = 'sex>\n";
		while ($row = mysql_fetch_array($result))
		{
			$sex = $row['status'];
			echo "<option value = '$sex'>'$sex'</option>";
		}
		$mysql->close();

Fixed it.

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.