stijn0713 Posted July 24, 2012 Share Posted July 24, 2012 hello, It seems that i can't use the mysql_fetch_assoc twice. I found that it i use the mysql_fetch assoc on the result twice the second time it will be empty. I guess because the internal pointer has moved. How i can avoid this or put the internal point back with 1? Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 24, 2012 Share Posted July 24, 2012 You don't, if you've already fetched it once you don't need to fetch it again. Quote Link to comment Share on other sites More sharing options...
stijn0713 Posted July 24, 2012 Author Share Posted July 24, 2012 I need it in the following code: f($pad == 1){ $query = "SELECT * FROM groepen WHERE groep_id = $groep_ID"; $rs = mysql_query($query); $row_groep = mysql_fetch_array($rs); mysql_free_result($rs); } if($pad == 2) { $query = "SELECT * FROM groepen WHERE onderzoek_id = $onderzoek_ID"; $rs = mysql_query($query); $aantal_groepen = mysql_num_rows($rs); } if ($pad == 2){ /// bepaal extra kenmerken van de groep: foreach ($_SESSION as $key => $value){ if(is_array($value)) { foreach($value as $k => $v){ if($_SESSION['gekozen_groep'] == $k) { $groep_locatie = $_SESSION['groep_locatie'][$k]; $groep_onderwerp = $_SESSION['groep_onderwerp'][$k]; $groep_afloop = $_SESSION['groep_afloop'][$k]; }}}}} if ($pad == 1){ $groep_locatie = $row_groep['groep_locatie_id']; $groep_onderwerp = $row_groep['groep_name']; $groep_afloop = $row_groep['groep_tijdstip']; } <select name="selecteerGroep" id="selecteerGroep" size ="<?php ($pad == 2) ? $aantal_groepen : '1' ?>" /> <?php while ($row = mysql_fetch_assoc($rs)) { echo '<option value="'.$row['groep_id'].'">'.$row['groep_name'].'</option>'; } ?> </select> . So what am i trying to do: -one can create an examination -one can create several groups that belong to an examination - one can add respondants to an examination Either the admin create and add respondants in an sequencial way :: 1) create examination 2) create group(s) 3) add respondants.. --> parameters are passed via $_SESSION. OR the admin selects an examination from the list and adds people --> parameters are passed via querystring. The above code with the selector echoes either the groups created with the sequencial way or it echoes the group (only one) passed via the querystring. Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 24, 2012 Share Posted July 24, 2012 As I said, if you've already fetched it, you don't NEED to fetch it again. Your third block of code is the only part using mysql_fetch_assoc. Is that where you're having trouble? Quote Link to comment Share on other sites More sharing options...
stijn0713 Posted July 24, 2012 Author Share Posted July 24, 2012 Ok, i can maybe split my third block with if($pad ==1) elseif ($pad ==2) and then show the already fetched row. still, i could be usefull the move back the pointer. Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 24, 2012 Share Posted July 24, 2012 Why would you want to add extra database calls? You realize you'd be making your program use twice the resources by doing that, right? Quote Link to comment Share on other sites More sharing options...
stijn0713 Posted July 24, 2012 Author Share Posted July 24, 2012 Sorry, btw. My 'euro felt later'. But you've opened my eyes. Thanks 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.