If you want an array output as JSON then add your rows to an array and then jsonify the array like this
<?php
mysql_connect("localhost", "root", "password") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
$result = mysql_query(" select part_name from Services_parts where part_id= 1 ") or die(mysql_error());
$j_out = array();
while( $row = mysql_fetch_array( $result ) )
{
$j_out[] = $row['part_name'];
}
echo json_encode($j_out);
?>
If you want an object that contains an array of results then do this
<?php
mysql_connect("localhost", "root", "password") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
$result = mysql_query(" select part_name from Services_parts where part_id= 1 ") or die(mysql_error());
$j_out = new stdClass();
while( $row = mysql_fetch_array( $result ) )
{
$j_out->part_names[] = $row['part_name'];
}
echo json_encode($j_out);
?>
Actually as you are only getting a single row from the database you could do this, removing the need for a unnecessary loop and making the returned object easier to deal with in the javascript.
<?php
mysql_connect("localhost", "root", "password") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
$result = mysql_query(" select part_name from Services_parts where part_id= 1 ") or die(mysql_error());
$row = mysql_fetch_array( $result );
$j_out = new stdClass();
$j_out->part_name = $row['part_name'];
echo json_encode($j_out);
?>
Please dont use the mysql_
database extensions, it is deprecated (gone for ever in PHP7)
Especially if you are just learning PHP, spend your energies learning the PDO
or mysqli_
database extensions,
and here is some help to decide which to use