0

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();
6
Contributors
8
Replies
10
Views
7 Years
Discussion Span
Last Post by mrjoli021
0

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>";
		}
0

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'];

Edited by phpbeginners: n/a

0
you need to add ' ' in status.

       echo $row['status'];

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

0

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!

0

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();
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.