Trouble Displaying an array of artists from a database.
Posted: Sat Dec 11, 2004 5:09 pm
I have a form where a user adds new data about a vinyl to a database. When the come to selecting the artist i want an option field which displays all the artists in the database so they can select the one they want. The trouble im having is that i have created the following functions:
however all i get is a title text box and an artist option field with no data in? Any ideas guys?
Code: Select all
<?php require_once('common_db.php');
function db_result_to_array($result)
{
$res_array = array();
for ($count=0; $row = @mysql_fetch_array($result); $count++)
$res_array[$count] = $row;
return $res_array;
}
function get_artists()
{
$link_id = db_connect();
$query = 'select artist_id from artists';
$result = @mysql_query($query);
if (!result)
return false;
$num_artists = @mysql_num_rows($result);
if($num_artists == 0)
return false;
$result = db_result_to_array($result);
return $result;
}
function addrecord(){
?>
<td width="581" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" width="581" height="600"><form name="newrecord" method="post" action="addnewrecord.php?">
<table>
<font color="#000000" size="2" face="Courier New, Courier, mono">
<tr>
<td>Title: </td>
<td><input name="title" type="text" maxlength="40" id="title"></td>
</tr>
<tr>
<td>Artist: </td>
<td><select name="artist_id">
<?php
$artist_array = get_artists();
foreach ($artist_array as $thisartist)
{
echo '<option value="';
echo $thisartist['artist_id'];
echo '"';
echo '>';
echo"\n";
}
?>
</select>
</td></table></form>
<div align="left"></div></td>
</tr>
</table></td>
</tr>
</table>
<?
}?>