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
    New Coder
    Join Date
    Nov 2011
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    hyperlink within a results table

    Here is the scenario I'm stuck with.

    I have an output of all the items within a database and they're put into a table.

    How do I make it so that someone can click on the unique ID (primary key) so that they can open the create form (that was used to create the item) so that the details of that item can be changed and then resaved/modified?

    Thanks!

  • #2
    New Coder
    Join Date
    Feb 2011
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts
    something like this?

    PHP Code:
    <?php

    include_once('include/config.php'); 

    $Querytable mysql_query("SELECT * FROM db_users") or die (mysql_error()); 

    while (
    $row mysql_fetch_assoc($Querytable)) {

        
    $userid $row['userid'];
        
    $initials $row['initials'];
        
        echo 
    "<tr>";
        echo 
    "<td><a href=\"edituser.php?id=$userid\">$initials</a></td>";
        echo 
    "</tr>";



    ?>

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hmm... It linked to the edit page, but it didn't populate the info from the database about that item.

  • #4
    New Coder
    Join Date
    Nov 2011
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts
    *bump*

    So, it goes to the edit form, but doesn't pre-populate the info from the database.

    How would I go about fixing this?

    Thanks!

  • #5
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    In the edit form page..

    You need to make like a query so it does:
    SELECT * FROM table where id = 'whateverID'

    then you have ..

    PHP Code:
    $result mysql_query($query);
    $data mysql_fetch_assoc($result); 
    form could be something like

    Code:
    <form method="post" action="someaction.php">
    Name : <input type="text" name="prodname" value="<?php echo $data['name']; ?>" />
    </form>
    and so on..

  • #6
    New Coder
    Join Date
    Nov 2011
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok, I tried this, but I get an error now:


    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in edit_equipment.php on line 13

    Here is what I have so far, and it didn't populate the name into the field like I thought it would... :

    Code:
    <?php
    include("lib.php");
    define("PAGENAME", "Edit Equipment");
    
    if ($player->access < 100)
    
    $msg1 = "<font color=\"red\">"; //name error?
    $error = 0;
    
    $query = $db->execute("SELECT * FROM `items` WHERE `id`=?", array($_POST['id']));
    	
    	$result = mysql_query($query);
    	$data = mysql_fetch_assoc($result); 
    	
    $msg1 .= "</font>"; //name error?
    
    
    ?>
    
    <?=$could_not_register?>
    
    <h2 align="center"><strong>Item Creator:</strong></h2>
    <form method="post"  action="edit_equipment.php">
    <table width="86%" border="0">
      <tr>
        <td>
            <label>
              Name</label>
    </td>
        <td><label><input type="text" name="name" value="<?php echo $data['name']; ?>">
      </label>
      &lt;-- Name of Item
      <?=$msg1;?></td>
      </tr>
    </table>
    <?=$msg2;?>
          <input type="submit" name="register" value="Create Item!"> 
          <input type="reset" value="Reset Fields">
    </form>

  • #7
    Regular Coder
    Join Date
    Aug 2011
    Posts
    134
    Thanks
    20
    Thanked 0 Times in 0 Posts
    have u tried echoing the query and see wat it returns:
    SELECT * FROM `items` WHERE `id`=?", array($_POST['id']);

  • #8
    New Coder
    Join Date
    Nov 2011
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Okay, I threw in a "echo $result;", but I don't see anything...

    Just that same error.

    Code:
    <?php
    include("lib.php");
    define("PAGENAME", "Edit Equipment");
    
    if ($player->access < 100)
    
    $msg1 = "<font color=\"red\">"; //name error?
    $error = 0;
    
    $query = $db->execute("SELECT * FROM `items` WHERE `id`=?", array($_POST['id']));
    	
    	$result = mysql_query($query);
    	
    	echo $result;
    	
    	$data = mysql_fetch_assoc($result); 
    	
    $msg1 .= "</font>"; //name error?
    
    
    ?>
    Either I didn't do the echo correct, or there isn't anything...

  • #9
    New Coder
    Join Date
    Nov 2011
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok, when I throw in a "echo "$id";", it shows the right ID of the item that I clicked to edit... So it must be in the query somewhere that $result isn't pulling up...

  • #10
    New Coder
    Join Date
    Nov 2011
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok, another thing... I put in an echo $query, and it lists the field names rather than the actual data of the item. That could be the problem...

    Any clues?

    Thanks!!


  •  

    Posting Permissions

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