greens85 Posted July 20, 2009 Share Posted July 20, 2009 Hi all, I have the following code which drags out all jobs from a database: <?php // Make a MySQL Connection $query = "SELECT * FROM edworld_jobs ORDER BY jobID DESC"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo '<strong>Job Ref:</strong>'." ".$row['jobref'];?> <br/> <?php echo '<strong>Job Title:</strong>'." ".$row['jobtitle'];?> <br/> <br/> <a href="edit.php" class="bodylinks">Edit Vacancy</a> <?php echo '<hr style width="100%" size="1" noshade="noshade" color="#999999">'; } ?> How can I make a link which then drags up the job in another page by ID. So that each link has the jobID associated with it? thanks Quote Link to comment https://forums.phpfreaks.com/topic/166653-solved-edit-an-article-by-id/ Share on other sites More sharing options...
greens85 Posted July 20, 2009 Author Share Posted July 20, 2009 think i have solved this by doing the following: <a href="<?php echo $row[0] ?>" class="bodylinks">Edit Vacancy</a> Quote Link to comment https://forums.phpfreaks.com/topic/166653-solved-edit-an-article-by-id/#findComment-878776 Share on other sites More sharing options...
play_ Posted July 20, 2009 Share Posted July 20, 2009 Not sure you mean by drag, but i think you mean this: <a href="edit.php?id=<?php echo $row['jobID']; ?>" class="bodylinks">Edit Vacancy</a> and on next page, you'd do $_GET['id']; Quote Link to comment https://forums.phpfreaks.com/topic/166653-solved-edit-an-article-by-id/#findComment-878777 Share on other sites More sharing options...
wildteen88 Posted July 20, 2009 Share Posted July 20, 2009 Change this line <a href="edit.php" class="bodylinks">Edit Vacancy</a> to <a href="edit.php?id=<?php echo $row['jobID']?>" class="bodylinks">Edit Vacancy</a> Now in edit.php to retrieve the Job id. you'd use $_GET['id']. Example code for edit.php if(isset($_GET['id']) && is_numeric($_GET['id'])) { $job_id = (int) $_GET['id']; $sql = 'SELECT * FROM edworld_jobs WEHERE jobID = '.$job_id; $result = mysql_query($sql); if(mysql_num_rows($result) == 1) { // display form to edit job } } Quote Link to comment https://forums.phpfreaks.com/topic/166653-solved-edit-an-article-by-id/#findComment-878780 Share on other sites More sharing options...
greens85 Posted July 20, 2009 Author Share Posted July 20, 2009 Hi Wildteen, Ive changed it to your code and although it looks like it should work, when I hover over the links they have no idea associated with them: i.e. edit.php?id= Any ideas what ive done wrong here? And when i click through it returns a blank page Quote Link to comment https://forums.phpfreaks.com/topic/166653-solved-edit-an-article-by-id/#findComment-878789 Share on other sites More sharing options...
greens85 Posted July 20, 2009 Author Share Posted July 20, 2009 Ah solved the ID problem.. it needed to be a capital J for JobID... however its still returning a blank page on the click through... do i need to drag the appropriate fields into the form? Quote Link to comment https://forums.phpfreaks.com/topic/166653-solved-edit-an-article-by-id/#findComment-878803 Share on other sites More sharing options...
wildteen88 Posted July 20, 2009 Share Posted July 20, 2009 My code wont output anything. It is just the basics. You need to add the code in yourself to edit the Job The code to edit the job needs be where the comment (orange text) is. Like so if(mysql_num_rows($result) == 1) { // display form to edit job ?> Edit JobID #<?php echo $job_id; ?> here Add your form here <?php } Quote Link to comment https://forums.phpfreaks.com/topic/166653-solved-edit-an-article-by-id/#findComment-878807 Share on other sites More sharing options...
greens85 Posted July 20, 2009 Author Share Posted July 20, 2009 My code wont output anything. It is just the basics. You need to add the code in yourself to edit the Job The code to edit the job needs be where the comment (orange text) is. Like so if(mysql_num_rows($result) == 1) { // display form to edit job ?> Edit JobID #<?php echo $job_id; ?> here Add your form here <?php } I have added the following line: span class="main">*</span> Contact Name: <input type="text" name="contactname" id="contactname" value="<?php echo $row['contactname'];?>" class="bodyinput" /> however this doesnt drag in the data from the database, would you be able to tell me why? thanks Quote Link to comment https://forums.phpfreaks.com/topic/166653-solved-edit-an-article-by-id/#findComment-878821 Share on other sites More sharing options...
greens85 Posted July 20, 2009 Author Share Posted July 20, 2009 Got it sorted! Needed a while statment in there: while($row = mysql_fetch_array($result)){ Quote Link to comment https://forums.phpfreaks.com/topic/166653-solved-edit-an-article-by-id/#findComment-878823 Share on other sites More sharing options...
wildteen88 Posted July 20, 2009 Share Posted July 20, 2009 Got it sorted! Needed a while statment in there: while($row = mysql_fetch_array($result)){ You do not need a while loop as the query will only return one result. You only need to have $row = mysql_fetch_array($result); The only time you use a while loop is if the query returns more than one result. Quote Link to comment https://forums.phpfreaks.com/topic/166653-solved-edit-an-article-by-id/#findComment-878824 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.