nrsh_ram Posted February 2, 2009 Share Posted February 2, 2009 hi...good morning, in my table, have "name, id " and "major" name and id is from same table from database, major is from another table.. $cur_login = $_SESSION["username"]; $conn= db_connect(); $aa=0; $query = "select mentee, username_mentee from mentormentee where username_mentor = '$cur_login'"; $result = $conn->query($query); <?php while ($row = mysqli_fetch_assoc($result)){ $aa = $aa + 1; ?> <td><?php echo $aa; ?> </td> <td><?php echo $row['mentee']; ?> </td> <td><?php echo $row['username_mentee']; ?> </td> <td> </td> </tr><?php } ?> its show data for name and id, for major how to call it for specific name and id? Quote Link to comment https://forums.phpfreaks.com/topic/143511-call-another-table-from-database/ Share on other sites More sharing options...
Maq Posted February 2, 2009 Share Posted February 2, 2009 its show data for name and id, for major how to call it for specific name and id? What common fields do they both have? You're going to have to LEFT JOIN on those fields... Have you tried any queries yet? The one you have looks like it has nothing to do with your question... Quote Link to comment https://forums.phpfreaks.com/topic/143511-call-another-table-from-database/#findComment-752844 Share on other sites More sharing options...
nrsh_ram Posted February 2, 2009 Author Share Posted February 2, 2009 i have tried like this...but no error, for major its not showing the output. $cur_login = $_SESSION["username"]; $conn= db_connect(); $aa=0; $query = "select mentee, username_mentee from mentormentee where username_mentor = '$cur_login'"; $result = $conn->query($query); $row1 = $username_mentee; $query1 = "select major from mentee_personal_details where mentee_id = '$row1'"; <?php while ($row = mysqli_fetch_assoc($result)){ $aa = $aa + 1; ?> <td><?php echo $aa; ?> </td> <td><?php echo $row['mentee']; ?> </td> <td><?php echo $row['username_mentee']; ?> </td> <td><?php echo $row1['major']; ?> </td> </tr><?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/143511-call-another-table-from-database/#findComment-752857 Share on other sites More sharing options...
Maq Posted February 2, 2009 Share Posted February 2, 2009 You need to replace common_field with whatever is common both tables to eliminate duplicates. If you don't know, how please dump both table structures and I will show you. Your query should look something like: $query = "SELECT mm.mentee, mm.username_mentee, mp.major ". "FROM mentormentee mm LEFT JOIN mentee_personal mp ". "ON mm.common_field = mp.common_field". "WHERE mm.username_mentor = '$cur_login' AND mp.mentee_id = '$row1'"; *** If username_mentor AND mentee_id are both unique to the same thing then you only need to use one of them, which is probably the case. Quote Link to comment https://forums.phpfreaks.com/topic/143511-call-another-table-from-database/#findComment-752870 Share on other sites More sharing options...
nrsh_ram Posted February 2, 2009 Author Share Posted February 2, 2009 table name mentor_personal_details mentee_id | major | 012000000 | engineering | 012000001 | science | table name mentormentee username_mentor|mentee |username_mentee | hod2 |mentee2 |012000000 | hod2 |mentee2 |012000001 | temp1 |mentee5 |012000003 | Quote Link to comment https://forums.phpfreaks.com/topic/143511-call-another-table-from-database/#findComment-752936 Share on other sites More sharing options...
Maq Posted February 2, 2009 Share Posted February 2, 2009 Okay, I think you need to do ON mp.menteeid = mm.username_menteee Quote Link to comment https://forums.phpfreaks.com/topic/143511-call-another-table-from-database/#findComment-752940 Share on other sites More sharing options...
nrsh_ram Posted February 2, 2009 Author Share Posted February 2, 2009 <?php while ($row = mysqli_fetch_assoc($result)){ $aa = $aa + 1; ?> its show error for this line..i have to change it? Quote Link to comment https://forums.phpfreaks.com/topic/143511-call-another-table-from-database/#findComment-752953 Share on other sites More sharing options...
Maq Posted February 2, 2009 Share Posted February 2, 2009 What's the error say? Post all of the code as well. If the error is not specific please put this as your first PHP code: ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/143511-call-another-table-from-database/#findComment-752968 Share on other sites More sharing options...
nrsh_ram Posted February 3, 2009 Author Share Posted February 3, 2009 Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\Program Files\xampp\htdocs\nrsh\all.php on line 154 Quote Link to comment https://forums.phpfreaks.com/topic/143511-call-another-table-from-database/#findComment-753319 Share on other sites More sharing options...
nrsh_ram Posted February 3, 2009 Author Share Posted February 3, 2009 $cur_login = $_SESSION["username"]; $conn= db_connect(); $aa=0; $query1 = "SELECT mm.mentee, mm.username_mentee, mp.major ". "FROM mentormentee mm LEFT JOIN mentee_personal_details mp ". "ON mp.mentee_id = mm.username_mentee". "WHERE mm.username_mentor = '$cur_login' AND mp.mentee_id = mm.username_mentee"; $result = $conn->query($query1); <?php while ($row = mysqli_fetch_assoc($result)){ $aa = $aa + 1; ?> <td><?php echo $aa; ?> </td> <td><?php echo $row['mentee']; ?> </td> <td><?php echo $row['username_mentee']; ?> </td> <td><?php echo $row['major']; ?> </td> </tr><?php } ?> the error is: Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\Program Files\xampp\htdocs\nrsh\all.php on line 153 Quote Link to comment https://forums.phpfreaks.com/topic/143511-call-another-table-from-database/#findComment-753350 Share on other sites More sharing options...
killah Posted February 3, 2009 Share Posted February 3, 2009 Is both the code on the same .php page? and in the same function? If not then it will not work. Quote Link to comment https://forums.phpfreaks.com/topic/143511-call-another-table-from-database/#findComment-753352 Share on other sites More sharing options...
nrsh_ram Posted February 3, 2009 Author Share Posted February 3, 2009 yes..both is on same page. Quote Link to comment https://forums.phpfreaks.com/topic/143511-call-another-table-from-database/#findComment-753580 Share on other sites More sharing options...
Maq Posted February 3, 2009 Share Posted February 3, 2009 $result = $conn->query($query1); $result is not the correct type to pass to your mysqli_fetch_array(). Can you post your db_connect class? Quote Link to comment https://forums.phpfreaks.com/topic/143511-call-another-table-from-database/#findComment-753589 Share on other sites More sharing options...
nrsh_ram Posted February 3, 2009 Author Share Posted February 3, 2009 db_connect? whic one ? <?php function db_connect() { $result = new mysqli('localhost', 'root', '', 'rama1'); if (!$result) throw new Exception('Could not connect to database server'); else return $result; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/143511-call-another-table-from-database/#findComment-753732 Share on other sites More sharing options...
Maq Posted February 3, 2009 Share Posted February 3, 2009 Sorry didn't mean to say class, even though it should be. What does the query function look like? You're calling: $result = $conn->query($query1); which doesn't make sense. Can you show us more of your code? Preferably all of it if it's not too long ( Quote Link to comment https://forums.phpfreaks.com/topic/143511-call-another-table-from-database/#findComment-753739 Share on other sites More sharing options...
nrsh_ram Posted February 3, 2009 Author Share Posted February 3, 2009 <?php require_once('include/session.php'); require_once('include/user_auth_fns.php'); $cur_login = $_SESSION["username"]; $conn= db_connect(); $aa=0; $query1 = "SELECT mm.mentee, mm.username_mentee, mp.major ". "FROM mentormentee mm LEFT JOIN mentee_personal_details mp ". "ON mp.mentee_id = mm.username_mentee". "WHERE mm.username_mentor = '$cur_login' AND mp.mentee_id = mm.username_mentee"; $result = $conn->query($query1); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <script LANGUAGE="JavaScript"> <!-- // Nannette Thacker http://www.shiningstar.net function confirmSubmit() { var agree=confirm("Are you sure you wish to continue?"); if (agree) return true ; else return false ; } // --> </script> <script type="text/javascript" src="calendarDateInput.js"> /*********************************************** * Jason's Date Input Calendar- By Jason Moon http://calendar.moonscript.com/dateinput.cfm * Script featured on and available at http://www.dynamicdrive.com * Keep this notice intact for use. ***********************************************/ </script> <script type="text/javascript" src="jquery-1.2.6.pack.js"></script> <script type="text/javascript" src="ddaccordion.js"> /*********************************************** * Accordion Content script- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com) * Visit http://www.dynamicDrive.com for hundreds of DHTML scripts * This notice must stay intact for legal use ***********************************************/ </script> <script type="text/javascript"> <!-- ddaccordion.init({ headerclass: "submenuheader", //Shared CSS class name of headers group contentclass: "submenu", //Shared CSS class name of contents group revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover collapseprev: true, //Collapse previous content (so only one open at any time)? true/false defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed) animatedefault: false, //Should contents open by default be animated into view? persiststate: true, //persist state of opened contents within browser session? toggleclass: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"] togglehtml: ["suffix", "<img src='image/images/plus_n.gif' class='statusicon' />", "<img src='image/images/minus_n.gif' class='statusicon' />"], //Additional HTML added to the header when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs) animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow" oninit:function(headers, expandedindices){ //custom code to run when headers have initalized //do nothing }, onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed //do nothing } }) //--> </script> <link href= "2col_leftNav1.css" rel="stylesheet" type="text/css" /> <link href= "pink_menu_left.css" rel="stylesheet" type="text/css" /> <link href="dropdowntabfiles/ddcolortabs.css" rel="stylesheet" type="text/css" /> <link href="dropdowntabfiles/dropdowntabs.js" rel="stylesheet" type="text/css" /> </head> <body> <div id="masthead"> <div align="left"></div> </div> <div id="masthead_1"> <table width="300" border="0" align="right"> <tr> <td><font class=label face="Verdana" size="2"><?php echo $_SESSION["name"]; ?> | time | Date |<a href="nlogout.php"> Logout</a> </font></td> </tr> </table> <div id="colortab_1"> <div id="colortab" class="ddcolortabs"> <ul> <li><a href="nprofile1.php" title="profile" ><span>PROFILE</span></a></li> <li><a href="nforms.php" title="froms" ><span>FORMS</span></a></li> <li><a href="view_report_menu.php" title="mentor" ><span>MENTOR</span></a></li> <li><a href="nmanagementee.php" title="mentee" ><span>MENTEE</span></a></li> <li><a href="mentor_setting.php" title="mysetting" ><span>MY SETTING</span></a></li> </ul> </div> </div> <div class="ddcolortabsline"> </div> </div> <div id="content"> <div class="story">this features for own mentee -> all </div> <div id="breadCrumb_1"> <table width="567" border="0" align="center"> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td width="109" bgcolor="#FFD9D9"><div align="center">No</div></td> <td width="111" bgcolor="#FFD9D9">Name</td> <td bgcolor="#FFD9D9" width="149"><div align="center">Id</div></td> <td bgcolor="#FFD9D9" width="182"><div align="center">Major</div></td> </tr> <tr> <?php while ($row = mysqli_fetch_assoc($result)){ $aa = $aa + 1; ?> <td><?php echo $aa; ?> </td> <td><?php echo $row['mentee']; ?> </td> <td><?php echo $row['username_mentee']; ?> </td> <td><?php echo $row['major']; ?> </td> </tr><?php } ?> </table> </div> </div> <div id="navBar"> <div id="search"></div> <div class="relatedLinks"> <h3> <div class="glossymenu"> <a href="nmanagementee_assign.php" class="menuitem">Manage Mentee</a> <a class="menuitem submenuheader" href="#" >Own Mentee</a> <div class="submenu"> <ul> <li><a href="#">All</a></li> <li><a href="#">Name</a></li> <li><a href="#">Id</a></li> <li><a href="#">Cohort</a></li> <li><a href="#">Course</a></li> </ul> </div> <a href="#" class="menuitem">Status</a> </div> </h3> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/143511-call-another-table-from-database/#findComment-753743 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.