Jump to content

How to display all entries by a user?


acmbar

Recommended Posts

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

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.