jonnash Posted March 23, 2013 Share Posted March 23, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/276039-newbie-here-need-some-help/ Share on other sites More sharing options...
requinix Posted March 23, 2013 Share Posted March 23, 2013 Have you created a page that can show that kind of information yet? Once that's ready you can make this link to it. Quote Link to comment https://forums.phpfreaks.com/topic/276039-newbie-here-need-some-help/#findComment-1420426 Share on other sites More sharing options...
jonnash Posted March 23, 2013 Author Share Posted March 23, 2013 (edited) 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 March 23, 2013 by jonnash Quote Link to comment https://forums.phpfreaks.com/topic/276039-newbie-here-need-some-help/#findComment-1420430 Share on other sites More sharing options...
haku Posted March 23, 2013 Share Posted March 23, 2013 Please use code tags around your code. It's the button that looks like <> in the editor. Quote Link to comment https://forums.phpfreaks.com/topic/276039-newbie-here-need-some-help/#findComment-1420454 Share on other sites More sharing options...
altafhpatel Posted March 23, 2013 Share Posted March 23, 2013 (edited) 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 March 23, 2013 by altafhpatel Quote Link to comment https://forums.phpfreaks.com/topic/276039-newbie-here-need-some-help/#findComment-1420460 Share on other sites More sharing options...
jonnash Posted March 23, 2013 Author Share Posted March 23, 2013 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>"; } Quote Link to comment https://forums.phpfreaks.com/topic/276039-newbie-here-need-some-help/#findComment-1420539 Share on other sites More sharing options...
jonnash Posted March 23, 2013 Author Share Posted March 23, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/276039-newbie-here-need-some-help/#findComment-1420542 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.