How to relate database info in a select file??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rambaldi
    New Member
    • Mar 2007
    • 42

    How to relate database info in a select file??

    [code=html]Categoria:<sele ct name="categoria ">
    <option value="<?php echo $categoria;?>" SELECTED><?php echo $categoria;?></option>
    <option value="Geral">c at1</option>
    <option value="2">cat2</option>
    <option value="3">cat3</option>
    <option value="4">cat4</option>
    <option value="5">cat5</option>
    <option value="6">cat6</option>
    </select> <br>[/code]

    [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
    Last edited by pbmods; Jul 11 '07, 09:40 PM. Reason: Added code tags.
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    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.

    [CODE=php]

    // get the data
    $lcSelectStr =
    "SELECT
    a.ID, a.countryName as description, a.isDefault
    FROM countrycode a
    ORDER BY a.countryName ASC";
    $laResults=$loD B->queryGetData($ lcSelectStr); // using a data abstraction layer

    // loop through the results loading them into the drop down
    echo "<select id='list1'>"; // this is actually dynamic for me based on another variable
    foreach($laResu lts as $lcDataLine)
    {
    echo "<option value=" ."'" . $lcDataLine['ID'] . "'" ;
    if($lcDataLine['isDefault'])
    {
    echo "selected='sele cted'";
    }
    echo ">" . $lcDataLine['description'] ."</option>";
    }
    echo "</select>";
    [/CODE]

    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

    Comment

    • Rambaldi
      New Member
      • Mar 2007
      • 42

      #3
      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

      Comment

      • nathj
        Recognized Expert Contributor
        • May 2007
        • 937

        #4
        Originally posted by Rambaldi
        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

        Comment

        Working...