SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: drop down box

  1. #1
    SitePoint Evangelist jkh1978's Avatar
    Join Date
    May 2001
    Location
    Northern Virginia
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    drop down box

    http://www.coderedsports.com/rss.php

    I want the top box to highlight the sport that is showing the headlines... how can I do that? Here is all the code.

    PHP Code:

    <head>
    <title> Current Headlines </title>
    </head>
    <body>
    <h2>Headlines</h2>
    <form method=post action="<?=$PHP_SELF?>">
    <select size="1" name="sport" onChange="this.form.submit()">
        <option value="baseball">Baseball</option>
        <option value="basketball">Basketball</option>
        <option value="boxing">Boxing</option>
        <option value="cricket">Cricket</option>
        <option value="cycling">Cycling</option>
        <option value="American%20football">Football (US)</option>
        <option value="soccer">Football (soccer)</option>
        <option value="golf">Golf</option>
        <option value="horse%20racing">Horse racing</option>
        <option value="ice%20hockey">Ice hockey</option>
        <option value="major%20league%20soccer">Major league soccer</option>
        <option value="motor%20sports">Motor sports</option>
        <option value="Olympic%20sports">Olympic sports</option>
        <option value="rugby">Rugby</option>
        <option value="tennis">Tennis</option>
        <option value="wrestling">Wrestling</option>
        <option value="yachting">Yachting</option>
      </select>
    </form>
    <dl>
    <?php

    $insideitem 
    false;
    $tag "";
    $title "";
    $description "";
    $link "";

    function 
    startElement($parser$name$attrs) {
        global 
    $insideitem$tag$title$description$link;
        if (
    $insideitem) {
            
    $tag $name;
        } elseif (
    $name == "ITEM") {
            
    $insideitem true;
        }
    }

    function 
    endElement($parser$name) {
        global 
    $insideitem$tag$title$description$link;
        if (
    $name == "ITEM") {
            
    printf("<dt><b><a href='%s'>%s</a></b></dt>",
                
    trim($link),htmlspecialchars(trim($title)));
            
    printf("<dd>%s</dd>",htmlspecialchars(trim($description)));
            
    $title "";
            
    $description "";
            
    $link "";
            
    $insideitem false;
        }
    }

    function 
    characterData($parser$data) {
        global 
    $insideitem$tag$title$description$link;
        if (
    $insideitem) {
        switch (
    $tag) {
            case 
    "TITLE":
            
    $title .= $data;
            break;
            case 
    "DESCRIPTION":
            
    $description .= $data;
            break;
            case 
    "LINK":
            
    $link .= $data;
            break;
        }
        }
    }

    $xml_parser xml_parser_create();
    xml_set_element_handler($xml_parser"startElement""endElement");
    xml_set_character_data_handler($xml_parser"characterData");
    $fp fopen("http://p.moreover.com/cgi-local/page?c=Sports%3A%20$sport%20news&o=rss","r")
        or die(
    "Error reading RSS data.");
    while (
    $data fread($fp4096))
        
    xml_parse($xml_parser$datafeof($fp))
            or die(
    sprintf("XML error: %s at line %d"
                
    xml_error_string(xml_get_error_code($xml_parser)), 
                
    xml_get_current_line_number($xml_parser)));
    fclose($fp);
    xml_parser_free($xml_parser);

    ?>
    </dl>
    </body>
    </html>

  2. #2
    :) delemtri's Avatar
    Join Date
    Jun 2001
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <select thingy>
    <option<?php if ($var==1) { echo " selected"; } ?>>Blah 1</option>
    <option<?php if ($var==2) { echo " selected"; } ?>>Blah 2</option>
    <option<?php if ($var==3) { echo " selected"; } ?>>Blah 3</option>
    </select>

  3. #3
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Better yet, improve upon Oliver's excellent idea by using a series of echo()s so the interpreter doesn't have to jump in and out of PHP mode 17 times:
    PHP Code:
    <?php
    echo("<select thingy><option");
    if (
    $var==1) { echo(" selected=\"selected\""); } echo(">Blah 1</option>\n<option");
    if (
    $var==2) { echo(" selected=\"selected\""); } echo(">Blah 2</option>\n<option");
    if (
    $var==3) { echo(" selected=\"selected\""); } echo(">Blah 3</option>\n</select>");
    ?>
    Last edited by Aes; Oct 24, 2001 at 19:51.
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •