PHP forums, MySQL forums, Web Development resources

Home PageHome    PHP ResourcesTopic List    FAQFAQ    SearchSearch    MemberlistMemberlist    UsergroupsUsergroups 
 RegisterRegister
    ProfileProfile    Log in to check your private messagesLog in to check your private messages    Download the RSS Reader RSS Feed Download the RSS Reader RSS for this forum Log inLog in 

PHP Forum :: MySQL Forum :: Java Script Forum



Extract values from lookup tables and display

 
Post new topic   Reply to topic    WeberForums.com Forum Index -> MySQL General
View previous topic :: View next topic  
Author Message
guoxin



Joined: 11 Feb 2008
Posts: 7

PostPosted: Mon Feb 11, 2008 10:24 am    Post subject: Extract values from lookup tables and display Reply with quote

Hi All,

I've encountered a problem which i find for answers but to no avail and i hope you all can help. I've got 4 tables namely, User_Login, Admin_Login, Projects and Mapping.

User_Login
-user_id (PK) INTEGER NOT NULL AUTO INCREMENT
-user_username VARCHAR(30) NOT NULL
-user_password VARCHAR(30) NOT NULL

Admin_Login
-admin_username VARCHAR(30) NOT NULL
-admin_password VARCHAR(30) NOT NULL

Projects
-project_id (PK) INTEGER NOT NULL AUTO INCREMENT
-project_name VARCHAR(30) NOT NULL

Mapping
-user_id (FK)
-project (FK)

Mapping is used as a lookup table when the administrator want to assign projects to the newly created user so we use the user_id from User_Login and project_id form Projects as a reference.

But here comes the problem, i execute the following command, $sql = "SELECT project_name FROM Projects, Mapping, User_Login WHERE Mapping.user_id=User_Login.user_id AND Mapping.project_id=Projects.project_id"; so the scenario is when a particular user is logged in, the projects will be displayed in a dropdown list where user can select which project he/she want to submit. But the dropdown list won't show up anything so i'm really asking you all for help. I'll be really grateful Thanks.

Smile
Back to top
View user's profile Send private message
lostboy



Joined: 02 May 2004
Posts: 5915
Location: toronto, canada

PostPosted: Tue Feb 12, 2008 2:50 am    Post subject: Reply with quote

have you run the query thru phpmyadmin or another gui tool for your db? test that the query works and brings back results , then look at your code to make sure you have not spelled a variable incorrectly
_________________
Lostboy

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
guoxin



Joined: 11 Feb 2008
Posts: 7

PostPosted: Tue Feb 12, 2008 4:22 am    Post subject: Reply with quote

I use mysql administrator to run the query and it shows the project "SL220" which i created earlier.
Back to top
View user's profile Send private message
lostboy



Joined: 02 May 2004
Posts: 5915
Location: toronto, canada

PostPosted: Tue Feb 12, 2008 4:32 am    Post subject: Reply with quote

so the query works, now show the code you are using to parse out the result and place it into the dropdown
_________________
Lostboy

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
guoxin



Joined: 11 Feb 2008
Posts: 7

PostPosted: Tue Feb 12, 2008 10:30 am    Post subject: Reply with quote

The code is as follows:

$sql = "SELECT project_name FROM Projects, Mapping, User_Login WHERE Mapping.user_id=User_Login.user_id AND Mapping.project_id=Projects.project_id";
$result = @mysql_query($sql,$dbcnx) or die(mysql_error());

while ($row = mysql_fetch_array($result))
{
$display_block .="<option value=\"$id \">$row[0]</option><br/>";
}

<b>Project:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b>
<select name="acd" size="1">
$display_block

</select>
Back to top
View user's profile Send private message
lostboy



Joined: 02 May 2004
Posts: 5915
Location: toronto, canada

PostPosted: Wed Feb 13, 2008 3:54 am    Post subject: Reply with quote

you forgot to echo the $display_block

Code:

<b>Project:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b>
<select name="acd" size="1">
<?php echo $display_block ; ?>

</select>

_________________
Lostboy

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
guoxin



Joined: 11 Feb 2008
Posts: 7

PostPosted: Fri Feb 15, 2008 3:42 am    Post subject: Reply with quote

Hi,

I got this code from another forum but there is this sql statement that i'm confused:

<?php
$sql = "SELECT p.project_name FROM Projects p JOIN Mapping m ON m.project_id = p.project_id JOIN User_Login u ON m.user_id = u.user_id WHERE u.user_id ='<user id here>'";
$result = @mysql_query($sql,$dbcnx) or die(mysql_error());
$display_block='';
while($row = mysql_fetch_array($result)){
$display_block .="<option value=\"$id \">$row[0]</option><br/>";
}
?>
<b>Project:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b>
<select name=\"acd\" size=\"1\">
<?php echo $display_block;?>
</select>

What actually must i put into the '<user id here>' ? Must i put a variable or something like this? Question
Back to top
View user's profile Send private message
lostboy



Joined: 02 May 2004
Posts: 5915
Location: toronto, canada

PostPosted: Fri Feb 15, 2008 3:46 am    Post subject: Reply with quote

$user_id or whatever you call the variable that holds the user id for that user
_________________
Lostboy

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
Display posts from previous:   
WeberTrivia Questions WeberTrivia Questions
 Think you are smart? Prove it!. Try your skills with these questions :
 WeberTrivia QuestionsRecursive arrays and multi-dimensional arrays are one and the same. (PHP and MySQL)
 WeberTrivia QuestionsThe \"cache_dir\" tag of the squid configuration has a default of /var/spool/squid. (Linux)

WeberTrivia Questions



PHP Code Examples
 Stream diffrent sizes of images from a single image to save disk space.
 JavaScript dropdown list menu to switch any page.
 Dump the contents of a PHP variable in html format with a recursive list of subfolders and files from a given root directory.
 PHP Dump in html format the contents of one array variable with a recursive list of the nested array variables inside.
 Link Extractor - This function is used to extract links from a given URL. This will convert relative path into absolute path and also remove PHPSESSID stuff.
 Building a Dynamic Form using Javascript and innerHTML. Add form elements in realtime without refreshing the page.
 A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function.
Post new topic   Reply to topic    WeberForums.com Forum Index -> MySQL General All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum






Powered by phpBB © 2001, 2005 phpBB Group
PHP Forum :: MySQL Forum :: Java Script Forum