Jump to content

i want to be able list my users ads specific to their user IDs


jeger003

Recommended Posts

i have a classifieds site where my users can post ads and sell there stuff. what i am trying to do is list the users ads right after they log in....so that they can see what ads they have live and what are expired. So i would have it display specific to the user ID. Im not really sure where to start I was hoping some one can point me in the right direction and let me know what i should be looking for.

 

 

i would appreciate any help

Link to comment
Share on other sites

yes, once a user registers they are assigned a "seller" number which is saved in mysql.

 

below is a code i was able to put together to just list all the ads live but of course i cant have this display on users accounts cause it would be displaying all the users ads.

 

seller field below would display the sellers #(user number) and then ad name next to it

 

<?
$data = mysql_query("SELECT * FROM ads_classifieds WHERE live='1' ORDER BY seller")
or die(mysql_error());
Print "<table border cellpadding=3>";
Print "<br><b>Ads Live</b><br><br>";
Print "<td>". "Title</td> ";
Print "<td>". "Seller</td>";
Print "<td>". "Views</td>";
Print "<td>"."Exp Notice</td></tr>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<td>".$info['title'] . "</td> ";
Print "<td>".$info['seller'] . " </td>";
Print "<td>".$info['viewed'] . " </td>";
Print "<td>".$info['expiration_notice'] . " </td></tr>";
}
?>

Link to comment
Share on other sites

I'm not sure how you get the id of the current user who is viewing the page, but try it like this...

(assume $current_viewing_user_id for the current viewing user's id, and `user_id` in the query is the database column of user ids)

<?
$data = mysql_query("SELECT * FROM ads_classifieds WHERE live='1' AND user_id=" . $current_viewing_user_id . " ORDER BY seller")
or die(mysql_error());
Print "<table border cellpadding=3>";
Print "<br><b>Ads Live</b><br><br>";
Print "<td>". "Title</td> ";
Print "<td>". "Seller</td>";
Print "<td>". "Views</td>";
Print "<td>"."Exp Notice</td></tr>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<td>".$info['title'] . "</td> ";
Print "<td>".$info['seller'] . " </td>";
Print "<td>".$info['viewed'] . " </td>";
Print "<td>".$info['expiration_notice'] . " </td></tr>";
}
?>

 

This query is like saying "Select the information from ads_classifieds where it is still active and the owner is the person looking at the page."

Link to comment
Share on other sites

i tried to figure it out.......but i couldnt........i cant find how its checkin user ids..........but i figured out another way we can do it........when users log in their username is displayed as <<DISPLAY_USERNAME>>

 

so it looks like this : Hello <<DISPLAY_USERNAME>> welcome back!

 

so if some how we can get it to search for the username in the db.......or have it display all the ads that match the username.......because it will all be on the same page and wouldnt have to search anywhere else.......the only catch is the username and ads are not on the same table......the ads are on ads_classified which goes by user ID's and the username is on ads_userdata for example:

 

if my user name is jeger003 and i have an ad selling a car and my user id is 23

 

the ads_classified table would say

 

ID    ad_title        date_published

23| car for sale | 12-29-08

 

and the ads_userdata would say

 

ID  username      email

23| jeger003    |  jeger003@blah.com

 

so i would need to some how match the ID from the ads_classified table to the username in the userdata table

 

 

i hope this makes.......and i thank you for all your help

 

 

 

 

 

 

Link to comment
Share on other sites

Why don't you just use sessions in the login? You should be doing that anyways... When they login set a variable $_SESSION['username'] and make it there username, so that when the page loads you automatically know their username.

 

Sessions are more secure overall -- if you have a login it would benefit you to use them.

Link to comment
Share on other sites

thats my problem I know nothing about putting it together........i am using sessions and have a sql table for it........but how would i be able to make it display it specific to usernames? like how would i put the "$_SESSION['username']" so that it displays their ads?

Link to comment
Share on other sites

can we see the login script?

 

the thing with my script is that everything is based from the index.php..........so index.php page calls all the other pages and i have no login.php.......but here is what i found on the index.php page that has to do with the login

 

if you need more or if you need me to post the entire index.php page i can

 


case 10:
	//login
	if (!$auth)
	{
		include_once("classes/authenticate_class.php");
		$auth = new Auth($db,$language_id);
		if ($auth->configuration_data->IP_BAN_CHECK) $auth->check_ip($db);
	}
	if (!$user_id)
	{
		if (($_REQUEST["b"]) && (is_array($_REQUEST["b"])))
		{
			$authorized = $auth->login($db,$_REQUEST["b"]['username'],$_REQUEST["b"]['password'],$_COOKIE["classified_session"]);
			if ($authorized)
			{
				if ($_REQUEST["c"])
				{
					$c = str_replace("*is*", "=", urldecode($_REQUEST["c"]));
					header("Location: ".$browse->configuration_data->CLASSIFIEDS_URL."?".$c);
				}
				else
				{
					if ($auth->configuration_data->POST_LOGIN_PAGE == 0)
					{
						include_once("classes/user_management_home.php");
						$user_management = new User_management_home($db,$language_id,$authorized,$classauctions);

						if (!$user_management->user_management_home_body($db))
							$user_management->site_error($db);
					}
					elseif ($auth->configuration_data->POST_LOGIN_PAGE == 1)
					{
						include_once("classes/browse_ads.php");
						$browse = new Browse_ads($db,$authorized,$language_id,0,$_REQUEST["page"],0,$filter_id,$state_filter,$zip_filter,$zip_distance_filter);
						if (!$browse->main($db))
						{
							if ($debug) echo "in no main browse<Br>\n";
							$browse->site_error($db);
						}
					}
				}
			}
			else
			{
				$auth->login_form($db,$_REQUEST["b"]['username'], $_REQUEST["b"]['password'], urldecode($_REQUEST["c"]));
			}
		}
		else
		{
			$auth->login_form($db);
		}
	}
	else
	{
		$auth->already_logged_in($db);
	}
	$db->Close();
	if ($get_execution_time) get_end_time($starttime);
	exit;
	break;



Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.