Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts

    Getting Info From A Table And Put Into Select Fields

    Can someone go to kansasoutlawwrestling.com/admin6.php and then click on create title. Then look in the main content frame. My question is how can I get the champion and contenders to be drop down select fields and show all the active wrestlers in a table I have called "wrestlers" or whatever I named it.

  • #2
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    PHP Code:
    echo '<select>';
    $data mysql_query("SELECT id_column, name_column FROM wrestlers");
    while(
    $row mysql_fetch_assoc($data)) {
        echo 
    '<option value="'.$row['id_column'].'">'.$row['name_column'].'</option>';
    }
    echo 
    '</select>'
    You might have to do some checks on the incoming data to make sure that none of the people have to wrestle themselves. I don't know much about the sport, but I don't think you can do that. If you do it with AJAX you could make it so that it adds a "WHERE id_column != 'id_from_first_select_field'" after the first select has been chosen - so that it doesn't show people who've already been selected in the following selects.
    Last edited by derzok; 07-28-2008 at 11:14 PM.
    zok@zoklet:~$ whereis zok
    zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com

  • Users who have thanked derzok for this post:

    CoolAsCarlito (07-28-2008)

  • #3
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts
    Thanks however I'm confused where do I put that at though. Do I put that in my code.

  • #4
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Instead of the html that shows the text field (<input type=....>), insert the code I posted above (with the correct column names, of course). If it's inside of html, you'll need to wrap it in <?php ?> tags so that it's:
    Code:
    some html goes here
    <?php
        My code goes here
    ?>
    More html goes here
    Instead of:

    Code:
    Some html goes here
        <input type="text" name="champion" />
    the rest of the html here
    zok@zoklet:~$ whereis zok
    zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com

  • Users who have thanked derzok for this post:

    CoolAsCarlito (07-28-2008)

  • #5
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts
    Wow that just goes to show I'm not thinking straight right now because I am still tired but thank you even though I did know that just not concentrating

  • #6
    Codeasaurus Rex
    Join Date
    Jun 2008
    Location
    Redmond, WA
    Posts
    659
    Thanks
    31
    Thanked 100 Times in 94 Posts
    I would recommend you implement templates instead of PHP intertwined with HTML, though. Check out this thread for more info on that.
    Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
    My posts, comments, code, and suggestions reflect only my personal views.
    Web Portfolio and Code Snippets: http://shanechism.com

  • #7
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts
    Well shoot now I get this:

    Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/content/y/a/n/yankeefaninkc/html/addtitle.php on line 64

    PHP Code:
    <?php
    // Connects to your Database
    $link mysql_connect("?""?""?") or die(mysql_error());
    mysql_select_db("?",$link) or die(mysql_error());
     
    if (!
    mysql_select_db("?"$link)) {
    echo 
    'Could not select database';
    exit;
    }
     
    //This code runs if the form has been submitted
    if (isset($_POST['addtitle'])) {
     
    //This makes sure they did not leave any fields blank
    if (!$_POST['titlename'] || !$_POST['type'] || !$_POST['status'] || !$_POST['champion'] || !$_POST['contender1'] || !$_POST['contender2'] || !$_POST['contender3'] ) {
    die(
    'You did not complete all of the required fields');
    }
     
    // checks if the title is in use
    if (!get_magic_quotes_gpc()) {
    $_POST['titlename'] = addslashes($_POST['titlename']);
    }
    $titlecheck $_POST['titlename'];
    $check mysql_query("SELECT titlename FROM titles WHERE titlename = '$titlecheck'")
    or die(
    mysql_error());
    $check2 mysql_num_rows($check);
     
    //if the title exists it gives an error
    if ($check2 != 0) {
    die(
    'Sorry, the title '.$_POST['titlename'].' is already in use.');
    }
     

    // now we insert it into the database
    $insert "INSERT INTO titles (titlename, type, status, champion, contender1, contender2, contender3)
    VALUES ('"
    .$_POST['titlename']."','".$_POST['type']."','".$_POST['status']."','".$_POST['champion']."','".$_POST['contender1']."','".$_POST['contender2']."','".$_POST['contender3']."')";
    $add_title mysql_query($insert,$link) or die(mysql_error());
    ?>
     

    <h1>Title is created!</h1>
     
    <?php
    }
    else
    {
    ?>
    <center><table border=1 cellpadding=5 cellspacing=0 width=350>
    <font color="#CC0000"><h2><center>Create a Title</h2></center></font>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <tr><td>Title Name:</td><td>
    <input type="text" name="titlename" maxlength="60">
    </td></tr>
    <tr><td>Type:</td><td>
    <select name="type">
    <option>Singles</option><option>Tag Team</option><option>Stable</option></select>
    </td></tr>
    <tr><td>Status:</td><td>
    <select name="status">
    <option>Active</option><option>Inactive</option></select>
    </td></tr>
    <tr><td>Champion:</td><td>
    <?php
    echo '<select>';
    $data mysql_query('SELECT * FROM singles');
    while(
    $row mysql_fetch_assoc($data)) {
        echo 
    '<option value="'.$row['wrestlingname'].'">'.$row['wrestlingname'].'</option>';
    }
    echo 
    '</select>'
    ?>
    </td></tr>
    <tr><td>Contender #1:</td><td>
    <?php
    echo '<select>';
    $data mysql_query("SELECT * FROM singles");
    while(
    $row mysql_fetch_assoc($data)) {
        echo 
    '<option value="'.$row['wrestlingname'].'">'.$row['wrestlingname'].'</option>';
    }
    echo 
    '</select>'
    ?>
    </td></tr>
    <tr><td>Contender #2:</td><td>
    <?php
    echo '<select>';
    $data mysql_query("SELECT * FROM singles");
    while(
    $row mysql_fetch_assoc($data)) {
        echo 
    '<option value="'.$row['wrestlingname'].'">'.$row['wrestlingname'].'</option>';
    }
    echo 
    '</select>'
    ?>
    <tr><td>Contender #3:</td><td>
    <?php
    echo '<select>';
    $data mysql_query("SELECT * FROM singles");
    while(
    $row mysql_fetch_assoc($data)) {
        echo 
    '<option value="'.$row['wrestlingname'].'">'.$row['wrestlingname'].'</option>';
    }
    echo 
    '</select>'
    ?>
    <tr><th colspan=2><input type="submit" name="createtitle" value="Create Title"></th></tr> </table>
    </form>
     
    <?php
    }
    ?>
    Last edited by CoolAsCarlito; 07-28-2008 at 11:40 PM. Reason: Forgot the code.

  • #8
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Quote Originally Posted by ShaneC View Post
    I would recommend you implement templates instead of PHP intertwined with HTML, though. Check out this thread for more info on that.
    As much as I like using templates, they can get messy. For beginners I think it's best to just use php to process and print html. I recently made a site that's fully templated and object oriented. I had to produce a table, and man was it messy. Here's the code: http://zb3.zoklet.net/stats2/code.html - check out table.php and try not to cry
    zok@zoklet:~$ whereis zok
    zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com

  • #9
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts
    Can someone tell me why I'm getting that error though?

  • #10
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Interesting, that code runs fine on my machine. Usually that error means that you're missing a ; on or before the line number given. Are you sure you're running the correct/current version of the code? I often times resolve bugs in my code by actually uploading the code that I'm making changes to after changing it - we're all guitly of doing that at least once.

    Line 64 is the first "echo" command of that block of code I gave you (which looks perfectly fine to me). So unless I'm missing something entirely obvious here, I think you're running the wrong code...
    Last edited by derzok; 07-29-2008 at 12:20 AM.
    zok@zoklet:~$ whereis zok
    zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com


  •  

    Posting Permissions

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