Jump to content

[SOLVED] Filtering a list of data


karenn1

Recommended Posts

Hi there!

 

Can someone please help a damsel in distress. I have a database system set up where the administrator can upload articles relevant to specific areas in the country. Members can then log in and go to the downloads page to download these articles. My problem is this: I can get it to display the complete list of articles but not those specific to the members' area. I have two tables in my MySQL database: files and members. Both tables have a field called areas. I used this code to select the info from the database:

 

<?php
		$query = "SELECT id, name, description, area FROM files WHERE area= ".$_SESSION['area'];
		$result = mysql_query($query) or die('Error, query failed');
			if(mysql_num_rows($result) == 0)
				{
				echo "Database is empty <br>";
				}
			else
				{

			while(list($id, $name, $description, $area) = mysql_fetch_row($result)) {
	?>
              <tr <?php if (is_int($i/2)) print "bgcolor=\"#C6E4FD\""; ?>>
                <td height="27" class="body-text-np" style="padding-left:5px; padding-right:2px;"><img src="../images/icon_update.gif" width="16" height="16"></td>
                <td class="db_list_text" style="padding-left:5px; padding-right:2px;"><?= $name;?>
                   </td>
                <td class="db_list_text" style="padding-left:5px; padding-right:2px;"><!--DWLayoutEmptyCell--> </td>
                <td class="db_list_text" style="padding-left:5px; padding-right:2px;">
                  <?= $description;?></td>
                <td class="db_list_text" style="padding-left:5px; padding-right:2px;"><!--DWLayoutEmptyCell--> </td>
                <td class="db_list_text" style="padding-left:5px; padding-right:2px;"><a href="downloads.php?id=<?= $id; ?>">Click Here</a></td>
                <td class="db_list_text" style="padding-left:5px; padding-right:2px;"><!--DWLayoutEmptyCell--> </td>
                <td class="db_list_text" style="padding-left:5px; padding-right:2px;"><span class="db_list_text" style="padding-left:5px; padding-right:2px;">
                  <?= $area;?>
                </span></td>
              </tr>
              <?php $i++; } ?>
              <tr align="right">
                <td height="24" colspan="8" valign="top" class="db_list_text"><!--DWLayoutEmptyCell--> </td>
              </tr>
              <tr>
                <td height="24" colspan="8" valign="top">                          </tr>
            </table></td>
          </tr>
    </table>
        </td>
    <?php } ?></td>

 

 

It looks right to me. I basically want the code to compare the area of the logged in member, ie the session area (the username and password is also in the members table), to the article area and only display those. How do I do this?

 

Anyone please help!! It's quite urgent that I get this sorted out.

 

Many Thanks!

 

Karen

Link to comment
Share on other sites

$_SESSION['area'] isn't a number. It's an area name. I want to compare that name to the area names attached to the uploaded files and then filter it. Does $_SESSION['area'] have to be a number. If so, how do I get around that?

Link to comment
Share on other sites

Hi AndyB,

 

Thanks for your reply. This is how I have it now:

 

$query = "SELECT id, name, description, area FROM files WHERE area= '". $_SESSION['area']. "'";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
            else
{

while(list($id, $name, $description, $area) = mysql_fetch_row($result)) {

 

Now it returns the "Database is empty" bit above. I know that I definitely added an article in the area (FILES table) that is the same as the area of the members' session (MEMBERS table).

 

How can this be? It all looks logical and correct to me but it still doesn't work.

Link to comment
Share on other sites

When you log in, it takes the username and password from the members table. The area I want to pull in is in that table. I've managed to pull in the ID of the session so the user can edit their profile. It works but not always. It's a bit temperamental. Does this make sense?

Link to comment
Share on other sites

When you log in, it takes the username and password from the members table. The area I want to pull in is in that table. I've managed to pull in the ID of the session so the user can edit their profile. It works but not always. It's a bit temperamental. Does this make sense?

 

i'm sorry, but what do you mean it works but not always. is the session_id part of session area? what is the purpose of area?

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.