nishmgopal Posted March 24, 2009 Share Posted March 24, 2009 Hi This is my code: $sql= "SELECT Person_Skill . * , ID_Table . * , Job_ID.Job_Name FROM Person_Skill, ID_Table JOIN Job_ID USING ( Job_ID ) WHERE Job_Name='Manager'"; $result1 = mysql_query($sql) or die ("Couldn't execute query."); while ($row=mysql_fetch_array($result1)) { echo "Job Name: ".$row['Manager'] . " "; } ?> But the out put is Job Name:ManagerManagerManagerManagerManagerManagerManagerManager I was expecting: Job Name: Manager... What do i need to change?? Link to comment https://forums.phpfreaks.com/topic/150865-while-loop/ Share on other sites More sharing options...
Yesideez Posted March 24, 2009 Share Posted March 24, 2009 I think you might find this a little easier if you restructure your tables a little. I remember yesterday your question had a few of us going because you're accessing more than one table and you don't have anything in either table to link the two. You might find that having something in both tables that is common will make this a little easier. Link to comment https://forums.phpfreaks.com/topic/150865-while-loop/#findComment-792511 Share on other sites More sharing options...
nishmgopal Posted March 24, 2009 Author Share Posted March 24, 2009 Should I create a different table called Skill_ID, which stores the Skill_Names that way the Job and the Person Table can both have Skill_ID.... Link to comment https://forums.phpfreaks.com/topic/150865-while-loop/#findComment-792514 Share on other sites More sharing options...
Yesideez Posted March 24, 2009 Share Posted March 24, 2009 Not sure tbh as I don't know your table structure or how you're using them - hopefully one of the mods/admin will be able to give the best advice here on this one. All tables I've played with in the past have one common field somewhere in each table that allows me to easily join tables together in some way. Link to comment https://forums.phpfreaks.com/topic/150865-while-loop/#findComment-792524 Share on other sites More sharing options...
kittrellbj Posted March 24, 2009 Share Posted March 24, 2009 Most tables I've made have a common id reference. For instance, I have 5 tables (users_master, users_profile, users_forum, users_pm, and forum_content). users_master has id, username, password, and email as columns. users_profile has id, nickname, first name, and last name as columns. users_forum has id, signature, and avatar as columns. users_pm has id, from_id, to_id, subject, and message as columns. forum_content has id, poster, subject, and message as columns. Just a few basic tables with some basic columns in them. users_master, users_profile, and users_forum each have id fields to identify whose record is there. Users_master is created on signup, then that id number is copied to the other two tables to create a link reference. If a user's id is 1 in the master table, it is 1 in profile and 1 in forum so that the id is uniform across the whole thing. I threw in users_pm and forum_content as a curve ball, though. There, id is not copied from the master table or any other source. Private messages and forum posts generate their own id's so that each one can be found by a unique key in the database. In the users_pm table, the column from_id and to_id contain user id's (who wrote it and who it was written to), which are both links to the users_master table to determine who is allowed access and who it says it is from. Likewise, in the forum_content table, id is a unique id for the posted content, not from the user. The poster column is used for the author, and links back to the users_master table to show, for instance, username of the author in the post. Of course, the above posters are correct in saying that we would need to know a little more of your table structure to be of a whole heap of help, but, in short: When using mysql_fetch_array(), it has been my experience that this assigns the values to a keyed array in the numeric sense, i.e. $row(0), $row(1), $row(2), instead of the actual column names. To see what your array looks like, do print_r($row); in your while statement to see what's being assigned where. If this is the case, you may want to use mysql_fetch_assoc($resultl); to make it an associative array, where it turns into $row(username), $row(password), and etc. Also, your column name is Job_Name, not Manager, so using mysql_fetch_assoc($resultl) would yield $row(Job_Name), not $row(Manager). So, it would look like this (and not guaranteeing it will fix it, but it might help you get there): while ($row = mysql_fetch_assoc($resultl)) { echo "Job Name: ".$row['Job_Name'] . " "; } Link to comment https://forums.phpfreaks.com/topic/150865-while-loop/#findComment-792546 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.