acmbar Posted March 28, 2010 Share Posted March 28, 2010 Hi all, I am building a jobsearch website and wish to display all the previous ad posted by a user when they login. I have all the data staored in a table and the loop works fine when i use an echo, but i need to store the results in a variable to echo in the html, i have managed to do this for the last result but not loop through all of their results, any help is appreciated... Link to comment https://forums.phpfreaks.com/topic/196821-how-to-display-all-entries-by-a-user/ Share on other sites More sharing options...
GetPutDelete Posted March 28, 2010 Share Posted March 28, 2010 You could transfer all the variables outside of the loop. For example $first_name = $row['first_name']; That way you can use them in the future outside of the loop. Link to comment https://forums.phpfreaks.com/topic/196821-how-to-display-all-entries-by-a-user/#findComment-1033229 Share on other sites More sharing options...
acmbar Posted March 28, 2010 Author Share Posted March 28, 2010 Thanks for the reply. This might help put the picture together: mysql_connect("localhost.baristajob.com.au","baristaj_Admin","baristajob01"); mysql_select_db ("baristaj_employment"); $getuser= mysql_query ( "SELECT email FROM users WHERE username ='$user'") or die (mysql_error()); $row= mysql_fetch_assoc($getuser); $useremail =$row['email']; //find users previous ads mysql_connect("localhost.baristajob.com.au","baristaj_Admin","baristajob01"); mysql_select_db ("baristaj_employment"); $data = mysql_query ("SELECT * FROM JOBS WHERE CONTACT_EMAIL = '$useremail'"); $count =mysql_num_rows($data); while ($row=mysql_fetch_assoc($data)){ $role = $row['ROLE']; $position =$row['POSITION_TYPE']; $location = $row['LOCATION']; $area = $row['AREA']; $date = $row['DATE']; $title= $row['TITLE']; $pay =$row['PAY']; $describe =$row['DESCRIPTION']; $business= $row['BUSINESS_NAME']; $contacttype=$row['CONTACT_TYPE']; $contact=$row['CONTACT_NAME']; $contactphone=$row['CONTACT_PHONE']; $contactemail =$row['CONTACT_NAME']; } if ($count >=1) { $prevdate = "<strong>$date</strong><br/>"; $prevpay ="$pay<br/>"; $prevdetails ="$position, $describe<br/>"; } else $msg= "You have not posted any jobs, please <a href='placeanad.php'> Place An Ad</a>"; this returns the last entries. however i need it to retrieve and then display all the results? Link to comment https://forums.phpfreaks.com/topic/196821-how-to-display-all-entries-by-a-user/#findComment-1033233 Share on other sites More sharing options...
GetPutDelete Posted March 28, 2010 Share Posted March 28, 2010 You may want to remove the database login details at the top. Link to comment https://forums.phpfreaks.com/topic/196821-how-to-display-all-entries-by-a-user/#findComment-1033235 Share on other sites More sharing options...
GetPutDelete Posted March 28, 2010 Share Posted March 28, 2010 It's displaying the last result because the query is overwriting the variables each time, to get around this you could turn the variables into an array, for example $role[1] = bla, $position[1] = bla ect, then for the next row $role[2] = bla... ect. That way after the loop is finished you will have each row and its data assigned to an array. Link to comment https://forums.phpfreaks.com/topic/196821-how-to-display-all-entries-by-a-user/#findComment-1033237 Share on other sites More sharing options...
acmbar Posted March 29, 2010 Author Share Posted March 29, 2010 thanks for that. How do i remove that info from the post? Link to comment https://forums.phpfreaks.com/topic/196821-how-to-display-all-entries-by-a-user/#findComment-1033277 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.