I tried to write a function that generates selectboxes.
I would greatly appreciate any sugestions.
Keep getting these weird errors:
Warning: Supplied argument is not a valid MySQL-Link resource on line 18.
Warning: Supplied argument is not a valid MySQL result resource on line 20.
Code:
5 <?php
6
7 $db = mysql_connect('localhost', 'username', 'password');
8
9 mysql_select_db('reference');
10
11 function selectbox($name, $query, $value_field, $first_field_shown)
12 {
13 //$value_field & $first_field_shown should be numeric values.
14
15 echo "\t\t\t<select name=$name>\n";
16
17 $query="SELECT FROM tablename";
18 $result=mysql_query($query, $db);
19
20 while($name=mysql_fetch_array($result))
21 {
22 echo "\t\t\t\t<option value=" . $name[$value_field] . ">\n";
23 echo "\t\t\t\t\t";
24
25 //Cycles through all the fields in query.
26 for($i=$first_field_shown; $i++; $i==mysql_num_fields($result))
27 {
28 echo " " . $name[$i];
29 }
30
31 echo "\n";
32 echo "\t\t\t\t</option>\n";
33 }
34
35 echo "\t\t\t</select>\n";
36 }
37
38 ?>
39
40 Select Box That Includes Primary Key:<br>
41 <?php
42 $query="SELECT FROM tablename";
43
44 selectbox("reference", $query, 0, 0);
45 ?>
46 <br>
THANK YOU.