473,513 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to relate database info in a select file??

42 New Member
Expand|Select|Wrap|Line Numbers
  1. Categoria:<select name="categoria"> 
  2. <option value="<?php echo $categoria;?>" SELECTED><?php echo $categoria;?></option> 
  3. <option value="Geral">cat1</option> 
  4. <option value="2">cat2</option> 
  5. <option value="3">cat3</option> 
  6. <option value="4">cat4</option> 
  7. <option value="5">cat5</option> 
  8. <option value="6">cat6</option> 
  9. </select> <br>
[Please use CODE tags when posting source code. Thanks! --pbmods]

the question is: the camps where is named cat1, cat2, etc... how i can put values from the database???
I know how to open and do the query's but i dont know how to put in the select camps
Jul 11 '07 #1
3 1434
nathj
938 Recognized Expert Contributor
Hi,

I have done just this sort of thing to display a drop down box of country names based on a table in a database. Here is the code I used and obviously this relies on my particular data strucutre but you should be able to modify it.

Expand|Select|Wrap|Line Numbers
  1.  
  2. // get the data
  3. $lcSelectStr = 
  4.             "SELECT 
  5.             a.ID, a.countryName as description, a.isDefault
  6.             FROM countrycode a
  7.             ORDER BY a.countryName ASC";    
  8. $laResults=$loDB->queryGetData($lcSelectStr); // using a data abstraction layer
  9.  
  10. // loop through the results loading them into the drop down
  11. echo "<select id='list1'>"; // this is actually dynamic for me based on another variable 
  12.            foreach($laResults as $lcDataLine)
  13.         {               
  14.             echo "<option value=" ."'" . $lcDataLine['ID'] . "'" ;
  15.             if($lcDataLine['isDefault'])
  16.             {
  17.                 echo "selected='selected'";
  18.             }
  19.             echo ">" . $lcDataLine['description'] ."</option>";
  20.         }
  21.         echo "</select>";
  22.  
So having retreived the data you run through the array that is set and load each item into the drop down. I have an extra check so that the default can be set. As my site will be aimed at UK residents I set the UK as the default to save them looking through the list for it.

If you have any questions about this then give me a shout and I'll do my best to help you out further.
nathj
Jul 12 '07 #2
Rambaldi
42 New Member
Thanks my friend, this code help me to organize my categories []

Another similar situation:

How can i get values from links???

I mean, imagine that the client wanna search videos through categories.

Instead put the categories by select boxes, i could show them by normal links that whe a client press it, the next page would show all the videos from the category selected.

my question is: how i can identify each category by is id and how i can save the id on the next page so i could use it to make a query to find the videos???

if y'all didnt understand, alert me ;)

Rambaldi
Jul 12 '07 #3
nathj
938 Recognized Expert Contributor
Thanks my friend, this code help me to organize my categories []

Another similar situation:

How can i get values from links???

I mean, imagine that the client wanna search videos through categories.

Instead put the categories by select boxes, i could show them by normal links that whe a client press it, the next page would show all the videos from the category selected.

my question is: how i can identify each category by is id and how i can save the id on the next page so i could use it to make a query to find the videos???

if y'all didnt understand, alert me ;)

Rambaldi
It sounds to me like the links to the categories need to end with ?id=xx where xx is the id of the category so that on the next page yu can used $_GET['id'] to retreive the data from the database. This means that one page could be used to chow videos of any category.

If you do not have a database then array or a formatted text file could serve as a useful substitue.

It is definitley a query string you require though.

Cheers
nathj
Jul 13 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

16
2869
by: John | last post by:
Hello. If I want to set up my first database and start using it in Dreamweaver what do I need to do? The book I'm working on has a CD with the database on. It is telling me to put it in the...
7
8670
by: RCS | last post by:
Okay, a rather 'interesting' situation has arisen at a place I work: I need to convert a database from Access to something that can be used over the web. I am currently maintaining and...
3
1496
by: Pasquale | last post by:
I have a database used for contact information and another for event information. As part of the event database, we would like to keep record of the people that are attending a certain event. These...
0
2581
by: roiavidan | last post by:
Hi, I'm having a bit of a problem with a small application I wrote in C#, which uses an Access database (mdb file) for storing financial data. After looking for a similiar topic and failing to...
7
1608
by: maxvalery | last post by:
Hi, I have been scouring the Internet for a good read on creating webpages whose address depends on data retrieved from a from via GET method OR a MySQL database ... but counldn't find anything...
4
2394
by: RSH | last post by:
Hi, I have a situation where I have created a little application that makes an Access database from a SQL Database for reporting purposes. it does the job well, but it seems a bit slow. Is...
1
3710
by: Rameel | last post by:
Friends, I'm probably being more critical with VB.Net Windows application. I have Developed VisualStudio 20005 VB.Net Windows application how willl i be able to save a specific record into my...
2
1766
by: gvijayasurya | last post by:
11. What are the different tables present in mysql, which type of table is generated when we are creating a table in the following syntax: create table employee(eno int(2),ename varchar(10)) ? 12....
1
2342
by: markla | last post by:
Hi, I have an Entity data model built in Entity Framework, which sources data primarily from an MS SQL 2008 database, and sources some static (data dictionary) values from code-based objects. I...
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7545
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7539
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3228
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.