Need a bit help, newbie here

hello guys, new to php trying to learn by watching some videos from youtube.
I have learned how to insert and show the data from the database. But here is where I am having a bit problem.

here is a code
function page.

function page.

[php]function getPrinters() {
$query = mysql_query(“SELECT * FROM printers”) or die (mysql_error());
if (mysql_num_rows($query) == 0) {
echo “

<td colspan=“3”>No Printers Were Found”;
} else {
while($post = mysql_fetch_assoc($query)) {
echo “ ” . $post[‘Brand’] . “ ” . $post[‘Model’] . “ ” . $post[‘Office’] . “ ” . $post[‘Location’] . “ ” . $post[‘IPAddress’] . “ ” . $post[‘MACAddress’] . “ ” . $post[‘Ink Order’] . “ ” . $post[‘Stock’] . “ <a href=“delete.php?id=” . $post[‘id’] . “”>Delete
<a href=“edit.php?id=” . $post[‘id’] . “”>Edit ”;
}
}[/php]

I was wondering how I can create a link for item “Model”. So that when someone clicks on Model it will get taken to it’s own page and show all those values that were inserted into the database.

thanks for your help

So add a link into your display code.
Its the same method you used for <a href=“edit.php?id=” . $post[‘id’] . “”>Edit
If you have an ID for each database entry use that, or use the Model.
<a href='printers.php?ID=$post[‘id’] or <a href=‘printers.php?ID=$post[‘Model’]
where printers.php is the page you want to show the individual printer information.
[php]function getPrinters() {
$query = mysql_query(“SELECT * FROM printers”) or die (mysql_error());
if (mysql_num_rows($query) == 0) {
echo “

<td colspan=“3”>No Printers Were Found”;
} else {
while($post = mysql_fetch_assoc($query)) {
echo “ ” . $post[‘Brand’] . “ <a href='printers.php?ID=” . $post[‘id’] . "’>" . $post[‘Model’] . “ ” . $post[‘Office’] . “ ” . $post[‘Location’] . “ ” . $post[‘IPAddress’] . “ ” . $post[‘MACAddress’] . “ ” . $post[‘Ink Order’] . “ ” . $post[‘Stock’] . “ <a href=“delete.php?id=” . $post[‘id’] . “”>Delete
<a href=“edit.php?id=” . $post[‘id’] . “”>Edit ”;
}
}[/php]

Create a new function in your functions page. Add WHERE to your mysql_query because your wanting to only show specific results.

[php]function displayPrinter($ID) {
$query = mysql_query(“SELECT * FROM printers WHERE ID = ‘$ID’”) or die (mysql_error());
if (mysql_num_rows($query) == 0) {
echo “

<td colspan=“3”>No Printers Were Found”;
} else {
while($post = mysql_fetch_assoc($query)) {
echo “OUTPUT”;
}
}[/php]

On printers.php access the ID with $_GET[‘ID’]
Call to the function sending $_GET[‘ID’]
$function->displayPrinter($_GET[‘ID’]);

Hope you get the method

Sponsor our Newsletter | Privacy Policy | Terms of Service