1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Fetching database data - noobie help

Discussion in 'PHP' started by Pizzaman1123, Dec 26, 2012.

  1. #1
    I am currently fetching data and I got that working. I pull up the "name" from the table with this in a drop menu:

    mysql_connect('localhost:3306', 'root', '');
    mysql_select_db('champion');

    $sql = "SELECT name FROM champion";
    $result = mysql_query($sql);

    echo "<select name='champion'>";
    while ($row = mysql_fetch_array($result)) {
    echo "<option value='" . $row['name'] ."'>" . $row['name'] ."</option>";
    }
    echo "</select>";

    The main thing I'm trying to do here is create two drop down menus with the name of champions (got one), it can be the same name in both fields but I want to display a 3rd field of text that shows the relationship between both names that are displayed. I think I can handle the mysql tables but I'm not how this would work in php. Any help will be greatly appreciated!
     
    Pizzaman1123, Dec 26, 2012 IP
  2. soerosentiqoe

    soerosentiqoe Member

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    you can share the table
    i think good for you if you use jquery.ajax inside
     
    soerosentiqoe, Dec 26, 2012 IP
  3. Pizzaman1123

    Pizzaman1123 Peon

    Messages:
    219
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I don't know ajax :p
    I'm just starting php. I can use the same table but I guess what I'm trying to do it a operator I believe? like x+y=c? example: When Annie and drake are chosen a box will display varchar field of text from database.
     
    Pizzaman1123, Dec 26, 2012 IP
  4. solomon.flik

    solomon.flik Member

    Messages:
    22
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    33
    #4
    <?php
     
    $mysql_hostname = "localhost:3306";
    $mysql_user = "root";
    $mysql_password = "";
    $mysql_database = "champion";
    $prefix = "";
    $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("No connection");
    mysql_select_db($mysql_database, $bd) or die("No connection");
    mysql_set_charset('utf8',$bd);
     
     
    $sql = "SELECT * FROM name ORDER BY id DESC";
     
     
     
    $num_rows = mysql_num_rows(mysql_query($sql));
     
     
     
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result))
    {
    $name=$row['name'];
     
    ?><li><?php
     
     
     
     
    echo $name ;
     
     
     
    }
     
    ?>
    PHP:
    use this code
     
    solomon.flik, May 15, 2013 IP