...

View Full Version : hyperlink within a results table



zelig
11-16-2011, 12:25 AM
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!

amof
11-16-2011, 12:53 AM
something like this?



<?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>";

}

?>

zelig
11-16-2011, 06:13 PM
Hmm... It linked to the edit page, but it didn't populate the info from the database about that item.

zelig
11-21-2011, 02:02 AM
*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!

Adee
11-21-2011, 02:20 AM
In the edit form page..

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

then you have ..



$result = mysql_query($query);
$data = mysql_fetch_assoc($result);


form could be something like



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


and so on..

zelig
11-21-2011, 09:12 PM
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... :



<?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>

coding_begins
11-21-2011, 10:34 PM
have u tried echoing the query and see wat it returns:
SELECT * FROM `items` WHERE `id`=?", array($_POST['id']);

zelig
11-22-2011, 02:35 AM
Okay, I threw in a "echo $result;", but I don't see anything...

Just that same error.



<?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...

zelig
11-22-2011, 02:54 AM
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...

zelig
11-22-2011, 03:08 AM
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!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum