karenn1 Posted April 4, 2007 Share Posted April 4, 2007 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 Quote Link to comment Share on other sites More sharing options...
joquius Posted April 4, 2007 Share Posted April 4, 2007 you may want to use mysql_fetch_array, what errors, problems are you having with the code? Quote Link to comment Share on other sites More sharing options...
karenn1 Posted April 4, 2007 Author Share Posted April 4, 2007 I've tried fetch_array but that didn't work either. In either case it returns the MySQL error message 'Error, query failed'. Quote Link to comment Share on other sites More sharing options...
monk.e.boy Posted April 4, 2007 Share Posted April 4, 2007 What is the problem? PHP is telling you that the 'query failed'. Your query is invalid SQL. I expect $_SESSION['area'] is either empty or is not a number. monk.e.boy Quote Link to comment Share on other sites More sharing options...
karenn1 Posted April 5, 2007 Author Share Posted April 5, 2007 $_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? Quote Link to comment Share on other sites More sharing options...
AndyB Posted April 5, 2007 Share Posted April 5, 2007 $query = "SELECT id, name, description, area FROM files WHERE area= '". $_SESSION['area']. "'"; Quote Link to comment Share on other sites More sharing options...
karenn1 Posted April 10, 2007 Author Share Posted April 10, 2007 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. Quote Link to comment Share on other sites More sharing options...
karenn1 Posted April 12, 2007 Author Share Posted April 12, 2007 Is there anybody who can still help me with this? Thanks, Karen Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted April 12, 2007 Share Posted April 12, 2007 how/where is $_SESSION['area'] being set? Quote Link to comment Share on other sites More sharing options...
karenn1 Posted April 13, 2007 Author Share Posted April 13, 2007 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? Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted April 13, 2007 Share Posted April 13, 2007 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? Quote Link to comment Share on other sites More sharing options...
karenn1 Posted April 14, 2007 Author Share Posted April 14, 2007 I must apologize. I know this is not well put out. I've actually managed to sort this out using $_REQUEST[area] and some work-arounds. Thanks for the help anyway! Karen Quote Link to comment 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.