MNSarahG Posted January 31, 2008 Share Posted January 31, 2008 Hi, I'm using PHP5 with MySQLi, which has proven to be kind of a challenge for my first PHP project. I'm having a hard time finding good resources of example code and stuff. So if anybody knows of any good, beginner-friendly information out there, please share! That said, I'm having trouble with a seemingly simple issue and I can't really research my way out of it. I've outputted a list of names from my DB, and I want each name to be a hyperlink that carries an employee ID # over to another page. My script looks like this: <?php $link = mysqli_connect( 'localhost', 'user', 'pw', 'db'); if (!$link) { printf("Can't connect to MySQL Server. Errorcode: %s\n", mysqli_connect_error()); exit; } if ($result = mysqli_query($link, 'SELECT employeeID, firstName, lastName FROM employees ORDER BY lastName')) { ?> <a href=/profile.php?employeeID=$employeeID> <?php /* Fetch the results of the query */ while( $row = mysqli_fetch_assoc($result) ){ printf("%s, %s</a><br><br>\n", $row['lastName'], $row['firstName']); }?> <?php mysqli_free_result($result); } mysqli_close($link); ?> This outputs the list of names just fine, but only the first one is a link, and the employee ID variable doesn't make it into the link (just $employeeID). I think this is some sort of issue with my syntax. Thanks in advance for any help - I'm really liking PHP and am excited to be able to actually make things that work on my own! - Sarah - Quote Link to comment https://forums.phpfreaks.com/topic/88769-hyperlinks-and-mysqli/ Share on other sites More sharing options...
MNSarahG Posted January 31, 2008 Author Share Posted January 31, 2008 I fixed part of it!! Everybody was probably really concerned. But I'm still struggling with getting the employee ID for each record to show up in the hyperlink. Again, help would be awesome. Here's what I've got for my query/output: if ($result = mysqli_query($link, 'SELECT employeeID, firstName, lastName FROM employees ORDER BY lastName')) { while( $row = mysqli_fetch_assoc($result) ){ printf("<a href=/profile.php?employeeID=$employeeID> %s, %s</a><br><br>\n", $row['lastName'], $row['firstName']); } Right now, each name links to "/profile.php?employeeID=" which is close... - Sarah - Quote Link to comment https://forums.phpfreaks.com/topic/88769-hyperlinks-and-mysqli/#findComment-454683 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.