RE: My question in precise reg PHP and relational tables.

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

 



Yes, you can do something like this:

// setup connection variables to access your database
$connection = mysql_connect(HOST, USER, PASS);

//select your database
mysql_select_db(DB);

//prep query to get all the categories
$sql = "SELECT * FROM category ORDER BY number ASC";

// prep your array
$sql_result = mysql_query($sql,$connection)
	or die("Couldn't execute query.");

// load each value into an array and build the option block	
while ($row = mysql_fetch_array($sql_result)) {
	$category_type = $row["category"];
	$option_block .= "<OPTION
value=\"$category_type\">$category_type</OPTION>";
 }

then in your form, use this code for the select box:

<SELECT name="product_type">
<? echo "$option_block"; ?>
</SELECT>

This will give you a drop down list that is dynamicly generated each time
the page is viewed by the values in your category table.


Cheers
Jason

-----Original Message-----
From: Phanivas Vemuri [mailto:vas2u@hotmail.com]
Sent: Tuesday, December 17, 2002 5:45 PM
To: jason.selph@hp.com; bbonkosk@tampabay.rr.com
Cc: php-db@lists.php.net
Subject: RE:  My question in precise reg PHP and relational
tables.


hi,
I have added my question , my main Aim at the end of this explanation.

I have two tables.

1.ProgramClips ( id, progSummary, category, videoFile)PRIMkey = id.
and each id may have 2 or three categories.

2.Category( number,category).
categories are :
Beef , diary, horticulture etc;

I am using PhpMyAdmin as the interface for the mySql Database.
The PhpMyAdmin uses a text filed to show the values of the category.

If there are two or more categories for example Beef and Diary then    "Beef

| Diary" is shown in the text field.

Now I want to change that text field into a drop down list and enable 
multiple selection of the values. And if I want to update the category field

in program clips I will select one or more values in the drop down list and 
do some programming to put a pipe symbol in between the selected values ( in

order to make MySQL to understand and interpret).

::::::::::::::::::::::::::::::::::::::::::::::::::::::

My Question in Precise is
1. is there aby way in realation databases that the values that appear in 
the FORM are the values from the 'categories' table. If I add more 
categories then those values can be automatically added into the FORM from 
whcih I update the 'category' field in 'programClips' table.

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* 
http://join.msn.com/?page=features/virus


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

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux