Ok so Ive been working with PHP for a while now but now trying to go beyond the basics, Im building an admin panel for example for a database of cars, and Im intending for the user to be able to scroll down a table of entries populated by the database.

This is what I have so far
Example page - cars


	$result = mysql_query("SELECT * FROM car ORDER BY price DESC");
<table border='1'>
                            while($row = mysql_fetch_array($result))
                              echo "<tr>";
								  echo "<td>" . $row['type'] . "</td>";
								  echo "<td>" . $row['fuel'] . "</td>";
								  echo "<td>" . $row['doors'] . "</td>";
								  echo "<td>" . $row['colour'] . "</td>";
								  echo "<td>" . "£" . $row['price'] . "pppw" . "</td>";
                              echo "</tr>";

Now I was to insert another column for 'more info' which will take go to 'details.php' for say example Aston Martin with an ID of 2 or Ferrari with an ID of 5

Any ideas as Ive tried a number of different things which didnt work, probably as none of the examples I found were similar to my problem so I was trying to simplify and re-engineer them to my project, I can create a GET rule within to search for specific criteria such as blue or red on the browse page but not so it will pull the ID and pass it to the next page.

8 Years
Discussion Span
Last Post by user1701
while($row = mysql_fetch_array($result))
echo "<tr>";
echo "<td>" . $row['type'] . "</td>";
echo "<td>" . $row['fuel'] . "</td>";
echo "<td>" . $row['doors'] . "</td>";
echo "<td>" . $row['colour'] . "</td>";
echo "<td>" . "£" . $row['price'] . "pppw" . "</td>";
[B]echo "<td><a href=\"details.php?id={$row['id']}\">More details...</a></td>";[/B] 
echo "</tr>";

That should add a column with the "More details..." link. The id from the DB will be a parameter in the url to details.php.

You just pick up the $_GET['id'] variable and use it in your mysql query in the details.php page.


Thanks for that its all working now, pretty much how I originally thought it would work but I was just going about it in the wrong way :)


Hi again, similar but slightly different problem.

Im now trying to use this method to allow the ability to update specific entries via a form but Im having trouble passing the correct details between my two php pages which handle this operation. the form is contained within 'edit.php' and the script which is supposed to handle the update within 'update.php'


<form method="post" action="update.php?id=<? echo $row['id'] ?>">
        <label for="name">Make</label><input type="text" name="make" value="<? echo $row['make']; ?>"><br />
        <label for="name">Model</label><input type="text" name="model" value="<? echo $row['model']; ?>"><br/>
        <label for="name">Colour</label><input type="text" name="colour" value="<? echo $row['colour']; ?>"><br />
        <label for="name">Price</label><input type="text" name="price" value="<? echo $row['price']; ?>"><br />
        <input type="submit" name="submit" value="Update" />
        <input type="reset" name="reset" value="Reset" /> 


if (isset($_POST['submit'])) {
$make = $_REQUEST['make'];
$model = $_REQUEST['model'];
$colour = $_REQUEST['colour'];
$price = $_REQUEST['price'];

$id = $_GET["id"];
$update = "UPDATE car WHERE id='".$id."' SET make='".$make."', model='".$model."', colour='".$colour."', price='".$price."'";

$update=entry = mysql_query($update);

<p>you have now updated your <a href="details.php?id=<? echo $row['id'] ?>">ENTRY</a>.</p>

Am I on the right track or should I be looking to run the entire process within edit.php alone?


Sure thing, Ive fixed the problem with the update not doing anything by moving the placement of WHERE id='".$id."' to the end of the sql.

The only remaining issue with this function now is that for some reason the "you have updated you entry" link doesnt carry over the id, something may be telling me to go to bed

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.