Jump to content

newbie here, need some help


jonnash

Recommended Posts

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 getPrinters() {
$query = mysql_query("SELECT * FROM printers") or die (mysql_error());
if (mysql_num_rows($query) == 0) {
echo "<tr><td colspan=\"3\">No Printers Were Found</td></tr>";
} else {
while($post = mysql_fetch_assoc($query)) {
echo "<tr><td>" . $post['Brand'] . "</td><td>" .  $post['Model'] . "</td><td>" . $post['Office'] . "</td><td>" . $post['Location'] . "</td><td>" . $post['IPAddress'] . "</td><td>" . $post['MACAddress'] . "</td><td><a href=\"delete.php?id=" . $post['id'] . "\">Delete</a><br /><a href=\"edit.php?id=" . $post['id'] . "\">Edit</a></td></tr>";
 
}
 
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
 
 
Link to comment
Share on other sites

I have a basic sample page with tables that lists the values from the database. I am very lost here

 

 

<?php 
include('includes/PrintFunctions.php'); 
?>
<html>
<head>
<title><?php echo $Model; ?></title>
</head>
<body>
<table>
<tr>
<td>Brand</td><td><?php echo $Brand; ?></td>
</tr>
<tr>
<td>Model:</td><td><?php echo $Model; ?></td>
</tr>
<tr>
<td>Office:</td><td><?php echo $Office; ?></td>
</tr>
<tr>
<td>Location:</td><td><?php echo $Location; ?></td>
</tr>
<tr>
<td>IP Address:</td><td><?php echo $IPAddress; ?></td>
</tr>
<tr>
<td>MAC Address:</td><td><?php echo $MACAddress; ?></td>
</tr>
</table>
</body>
</html>
 
This is how I originally was hoping the page would look, those values will get pulled from the database and get placed here
Edited by jonnash
Link to comment
Share on other sites

function getPrinters() {
$query = mysql_query("SELECT * FROM printers") or die (mysql_error());
if (mysql_num_rows($query) == 0) {
echo "<tr><td colspan=\"3\">No Printers Were Found</td></tr>";
} else {
while($post = mysql_fetch_assoc($query)) {
$bran=$post['Brand'];
$mod=$post['Model'];
$off=$post['office'];
$loc=$post['Location'];
$ip=$post['IPAddress'];
$mac=$post['MACAddress'];
$id=$post['id'];
echo "<tr><td>" . $bran . "</td><td>" .  $mod . "</td><td>" . $off . "</td><td>" . $loc . "</td><td>" . $ip . "</td><td>" . $post['MACAddress'] . "</td><td><a href=\"delete.php?id=" . $id . "\">Delete</a><br /><a href=\"edit.php?id=" . $id . "\">Edit</a></td></tr>";
}

Here you function look like this now...

 

Now after that in the page i mean modelsample.php look like this

 

<?php 
include('includes/PrintFunctions.php'); 
?>
<html>
<head>
<title><?php echo $mod; ?></title>
</head>
<body>
<table>
<tr>
<td>Brand</td><td><?php echo $bran; ?></td>
</tr>
<tr>
<td>Model:</td><td><?php echo $mod; ?></td>
</tr>
<tr>
<td>Office:</td><td><?php echo $Off; ?></td>
</tr>
<tr>
<td>Location:</td><td><?php echo $loc; ?></td>
</tr>
<tr>
<td>IP Address:</td><td><?php echo $ip; ?></td>
</tr>
<tr>
<td>MAC Address:</td><td><?php echo $mac; ?></td>
</tr>
</table>
</body>
</html>
Edited by altafhpatel
Link to comment
Share on other sites

thank you!

but how do I turn the Model into a link that will get taken to the modsample.php page?

 

function getPrinters() {
$query = mysql_query("SELECT * FROM printers") or die (mysql_error());
if (mysql_num_rows($query) == 0) {
echo "<tr><td colspan=\"3\">No Printers Were Found</td></tr>";
} else {
while($post = mysql_fetch_assoc($query)) {
$bran=$post['Brand'];
$mod=$post['Model'];
$off=$post['office'];
$loc=$post['Location'];
$ip=$post['IPAddress'];
$mac=$post['MACAddress'];
$id=$post['id'];
echo "<tr><td>" . $bran . "</td><td>" .  $mod . "</td><td>" . $off . "</td><td>" . $loc . "</td><td>" . $ip . "</td><td>" . $post['MACAddress'] . "</td><td><a href=\"delete.php?id=" . $id . "\">Delete</a><br /><a href=\"edit.php?id=" . $id . "\">Edit</a></td></tr>";
}
Link to comment
Share on other sites

Okay I figured out how to make the link

 

echo "<tr><td>" . $bran . "</td><td>" .  '<a href="modsample.php?id=" . $mod . "\">Model</a>' . "</td><td>" . $off . "</td><td>" . $loc . "</td><td>" . $ip . "</td><td>" . $mac. "</td><td>" .  $Ink . "</td><td>" . $Stock . "</td><td><a href=\"delete.php?id=" . $id . "\">Delete</a><br /><a href=\"edit.php?id=" . $id . "\">Edit</a></td></tr>";

 

But I when I get taken to the modsample.php page I get error

"Notice: Undefined variable: bran in C:\wamp\www\web\printer 2\printer\admin\modsample.php on line 11"

 

 

<?php 
include('includes/PrintFunctions.php'); 
?>
<html>
<head>
<title><?php echo $mod; ?></title>
</head>
<body>
<table>
<tr>
<td>Brand</td><td><?php echo $bran; ?></td>
</tr>
<tr>
<td>Model:</td><td><?php echo $mod; ?></td>
</tr>
<tr>
<td>Office:</td><td><?php echo $off; ?></td>
</tr>
<tr>
<td>Location:</td><td><?php echo $loc; ?></td>
</tr>
<tr>
<td>IP Address:</td><td><?php echo $ip; ?></td>
</tr>
<tr>
<td>MAC Address:</td><td><?php echo $mac; ?></td>
</tr>
<tr>
<td>Ink Type:</td><td><?php echo $Ink; ?></td>
</tr>
</table>
</body>
</html>s
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.