Re: enhanced_list_box, 2 tables from a database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear kNish,

first of all i have formated your PHP Code it looks better now.

<?php

 echo "<tr>\n";
 echo "  <td height=\"33\">&nbsp;</td>\n";
 echo "  <td width=\"14%\" class=\"style3\">Artist</td>\n";

 $options = mysql_query("SELECT artist_name FROM artist");
 $options=mysql_fetch_array($options);

 echo '<td>';

 enhanced_list_box(array(
   'table' => 'artist',
   'value_field' => 'artist_name'));

 function enhanced_list_box($options)
 {
   $sql = "select " . $options['value_field'];
   $sql .= " from " . $options['table'];
   $result = mysql_query($sql)or die("error in SQL");

   echo '<select name="', $options['value_field'],'" size="1">';
   while ($row = mysql_fetch_array($result, MYSQL_NUM))
     echo '<option value="' . $row[0] . '">' . $row[0] . '</option>';
   echo '</select>';
 }

 echo '  </td>';
 echo "</tr>\n";

 echo "<tr>\n";
 echo "  <td height=\"33\">&nbsp;</td>\n";
 echo "  <td width=\"14%\" class=\"style3\">Project</td>\n";

 $options = mysql_query("SELECT project_name FROM project");
 $options=mysql_fetch_array($options);

 echo '<td>';

 enhanced_list_box(array(
   'table' => 'project',
   'value_field' => 'project_name'));

 function enhanced_list_box($options)
 {
   $sql = "select " . $options['value_field'];
   $sql .= " from " . $options['table'];
   $result = mysql_query($sql)or die("error in SQL");

   echo '<select name="', $options['value_field'],'" size="1">';

   while ($row = mysql_fetch_array($result, MYSQL_NUM))
     echo '<option value="' . $row[0] . '">' . $row[0] . '</option>';

   echo '</select>';
 }

 echo '</td>';
?>

After i had check your code, my php interpreter shows me an fatal error on the browser.


"kNish" <singhai.nish@xxxxxxxxx> schrieb im Newsbeitrag news:81bfef2e0711070041p1a2ed9b3p4b972a5c985a7e8f@xxxxxxxxxxxxxxxxx
Hi,

A newbie question. I have more than one table to access from a database.

When I use the code as below, it gives no response on the web page.

What may I do to run more than one table from the same database into the
script.

BRgds,

kNish

.
.
.
.
<tr>
<td height="33">&nbsp;</td>
<td width="14%" class="style3">Artist</td>
<?php
$options = mysql_query("SELECT artist_name FROM artist");
$options=mysql_fetch_array($options);
echo '<td>';
enhanced_list_box(array(
'table' => 'artist',
'value_field' => 'artist_name'));
function enhanced_list_box($options){
$sql = "select " . $options['value_field'];
$sql .= " from " . $options['table'];
$result = mysql_query($sql)or die("error in SQL");
echo '<select name="', $options['value_field'],'" size="1">';
while ($row = mysql_fetch_array($result, MYSQL_NUM))
echo '<option value="' . $row[0] . '">' . $row[0] . '</option>';
echo '</select>';
}
echo '</td>';
?>
</tr>

<tr>
<td height="33">&nbsp;</td>
<td width="14%" class="style3">Project</td>
<?php
$options = mysql_query("SELECT project_name FROM project");
$options=mysql_fetch_array($options);
echo '<td>';
enhanced_list_box(array(
'table' => 'project',
'value_field' => 'project_name'));
function enhanced_list_box($options){
$sql = "select " . $options['value_field'];
$sql .= " from " . $options['table'];
$result = mysql_query($sql)or die("error in SQL");
echo '<select name="', $options['value_field'],'" size="1">';
while ($row = mysql_fetch_array($result, MYSQL_NUM))
echo '<option value="' . $row[0] . '">' . $row[0] . '</option>';
echo '</select>';
}
echo '</td>';
?>
</tr> <http://www.php.net/a>
.
.
.
.
.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux