Jump to content


Photo

newbie here, need some help


  • Please log in to reply
6 replies to this topic

#1 jonnash

jonnash

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 22 March 2013 - 09:04 PM

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
 
 


#2 requinix

requinix

    Hopeless Member

  • Moderators
  • 5,915 posts
  • LocationWA

Posted 22 March 2013 - 10:51 PM

Have you created a page that can show that kind of information yet? Once that's ready you can make this link to it.

#3 jonnash

jonnash

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 22 March 2013 - 11:16 PM

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, 22 March 2013 - 11:18 PM.


#4 haku

haku

    Advanced Member

  • Staff Alumni
  • 6,172 posts

Posted 23 March 2013 - 02:57 AM

Please use code tags around your code. It's the button that looks like <> in the editor.



#5 altafhpatel

altafhpatel

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 23 March 2013 - 03:10 AM

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, 23 March 2013 - 03:11 AM.


#6 jonnash

jonnash

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 23 March 2013 - 11:27 AM

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


#7 jonnash

jonnash

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 23 March 2013 - 11:49 AM

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com