doh! Thanks for that and for the tip about initialising it first.
However, it still doesn't work 😕
Full code is as follows - you can ignore the stuff in the if($artist_type=="band") condition as I'm feeding it the value individual every time.
function return_artists($artist_type){
if($artist_type=="band"){
$sql_what="bc_id, bc_title";
$sql_from="FROM pp_bands_collabs";
$sql_where="WHERE bc_status = \"a\" ORDER BY bc_title";
$sql_action="SELECT";
include("submit.inc");
if(!mysql_num_rows($result)) return "0";
else {
//simply whack all band names into the array $artist_list
while($query_data = mysql_fetch_row($result)){
$padded_id = sprintf("%05s",$query_data[0]);
$display_name ="$padded_id"." - "."$query_data[1]";
$artist_list[]="$display_name";
}
}
}
elseif($artist_type=="individual"){
$sql_what="ind_id, ind_forname, ind_surname, ind_initials";
$sql_from="FROM pp_individuals";
$sql_where="WHERE ind_status = \"a\"";
$sql_action="SELECT";
include("submit.inc");
if(!mysql_num_rows($result)) return "0";
else {
//shuffle into format Surname Forename Initial and remove leading spaces
//and hyphens if artist only has one name.
//$count=1;
$artist_list = array();
while($query_data = mysql_fetch_row($result)){
$padded_id = sprintf("%05s",$query_data[0]);
$ordered_name = "$query_data[2]".", "."$query_data[1]"." "."$query_data[3]";
$ordered_name = ltrim($ordered_name, " -,");
$ordered_name = rtrim($ordered_name, " -");
$display_name = "$padded_id"." - "."$ordered_name";
$artist_list[]="$display_name";
//echo "$artist_list[$count] <br />";
//$count++;
}
}
}
return $artist_list;
}
The code that I'm using to try and interpret the returned value is:
<form name="new_ind" method="post" action="somescript.php">
<select name="ind_exist">
<?php
return_artists("individual");
$counter=0;
while($artist_list){
echo "<option>$artist_list[$counter]</option>";
$counter++;
}
?>
</select>
</form>
I'm taking it that I can probably do without the counter bit there too but at least I got it in the right place this time!