murli800 Posted July 8, 2011 Share Posted July 8, 2011 in my $dep array..y is this only 1 row retrieving..infact i have more than 8 rows in the deparment dabase..help me..thanx in advane... -------------------------------------- <?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ include("include/sessionStart.php"); include("include/dbConnect.php"); $query = "SELECT * FROM schoolmaster"; $result = mysql_query($query); $arr = mysql_fetch_assoc($result); $query1 = "SELECT * FROM department"; $result1 = mysql_query($query1); $dep = mysql_fetch_assoc($result1); print_r($dep); if(!empty($_GET['submit']) and $_GET['submit']=="Add" ) { $depName = $_GET['txtDepName']; $yes =mysql_query("INSERT INTO department(departmentName) VALUES( '$depName' )"); } ?>\<html> <head><style> #header{ width: inherit; height:110px; background-color:#09C; margin:auto; border-bottom:2px solid #000; position:relative; border-left:2px solid #000; border-right:2px solid #000; float:left; } h1{ position:absolute; left:205px; top:0px; margin-top:0px; } h2{ position:absolute; left:205px; top:38px; margin-top:0px; } h3{ position:absolute; left:205px; top:68px; margin-top:0px; } #container1{ width:800px; margin:auto; } label{ width:190px; font-family:"Palatino Linotype", "Book Antiqua", Palatino, serif; font-weight:bold; font-size:19px; float:left; margin:4px; } table{ position:absolute; border:none; top:0px; } td{ font-family:"Palatino Linotype", "Book Antiqua", Palatino, serif; font-weight:bold; width:138px; } </style></head> <body> <div id="container1"> <div id="header"> <img src="<?php echo $arr['schoolLogo']; ?>" width="200px" height="110px" /> <h1><?php echo $arr['schoolName']; ?></h1> <h2><?php echo $arr['schoolAddress']; ?></h2> <h3><?php echo $arr['schoolContact']; ?></h3> </div> <div style="margin-left:20px;"> <?php include("dropDown.php");?> </div> <div style="width: 620px; height:400px; position:relative; float: right; background-color: #FFDFFF;text-align:center;"> <form name="formAddDep" action="#" method="get"> <fieldset style="width:200px; float:right; border:2px solid #000; "> <legend>Update</legend> <label>New Department</label><input style="width:180px;" type="text" name="txtDepName" value="" tabindex="1"> <label>Status</label><br/> E<input type="radio" name="radioStatus" value="e" /> D<input type="radio" name="radioStatus" value="d" /><br/> <input type="submit" name="submit" value="Add"> </fieldset> </form> <table > <tr> <td>Department Id</td> <td>Department Name</td> <td>Status</td> </tr> <tr> <?php foreach($dep as $value) {?> <td><?php echo $value;?></td> <?php }?> </tr> </table> <?php // if(!empty($yes)){echo "<h4>department Added</h4>"; /// echo "<a href=\"changeDisplay.php\">BACK</a>"; // } ?> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/241424-why-i-am-retrieving-only-1-row-from-my-data-base/ Share on other sites More sharing options...
AyKay47 Posted July 8, 2011 Share Posted July 8, 2011 might be because you dont have it inside a loop...try while($dep = mysql_fetch_assoc($result1)){ print_r($dep); } honestly I am not sure about this one...however i think that since you do not have your mysqll_fetch_array inside of a loop, it is only grabbing the first row, therefore your print_r will display one row Quote Link to comment https://forums.phpfreaks.com/topic/241424-why-i-am-retrieving-only-1-row-from-my-data-base/#findComment-1240154 Share on other sites More sharing options...
wildteen88 Posted July 8, 2011 Share Posted July 8, 2011 is this only 1 row retrieving..infact i have more than 8 rows in the deparment dabase Because mysql_fetch_assoc only retrieves one row at a time. You need to use a while loop to loop through the results from your query, like how the manual demonstrates for mysql_fetch_assoc Quote Link to comment https://forums.phpfreaks.com/topic/241424-why-i-am-retrieving-only-1-row-from-my-data-base/#findComment-1240156 Share on other sites More sharing options...
TeNDoLLA Posted July 8, 2011 Share Posted July 8, 2011 Might be because you haven't used code tags in this forum... Quote Link to comment https://forums.phpfreaks.com/topic/241424-why-i-am-retrieving-only-1-row-from-my-data-base/#findComment-1240157 Share on other sites More sharing options...
KevinM1 Posted July 8, 2011 Share Posted July 8, 2011 In the future, please put all code in either or tags. Quote Link to comment https://forums.phpfreaks.com/topic/241424-why-i-am-retrieving-only-1-row-from-my-data-base/#findComment-1240158 Share on other sites More sharing options...
murli800 Posted July 8, 2011 Author Share Posted July 8, 2011 Thanx..dudes...u guys are bond... Quote Link to comment https://forums.phpfreaks.com/topic/241424-why-i-am-retrieving-only-1-row-from-my-data-base/#findComment-1240161 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.