summerpewp Posted January 9, 2008 Share Posted January 9, 2008 I ran into a problem today trying to edit part of my site. Can't seem to figure out the solution but i think i know the problem. The problem is the returned results are missing the first entry. So my assumption is the $i = 0; line ... because if i understand this correctly it is adding one after another, but its registering the line echo'<h2 class="subh2">',$row[3],'</h2>'; <?php $query2 = "SELECT * FROM help WHERE topicid = '%s'"; $sprintf = sprintf($query2,mysql_real_escape_string($_GET['topicid'])); $sql2 = mysql_query($sprintf); while($row = mysql_fetch_array($sql2)) { echo '<h2 class="subh2">',$row[3],'</h2>'; while($row = mysql_fetch_array($sql2)) { $i = 0; echo <<< EOF <div class="questions"><a id="moreinfo" onclick="javascript:show('info_{$i}');return false;" href="#">{$row['question']}</a> </div><br /> <div id="info_{$i}" style="display: none" class="answers">{$row['answer']} </div><br /> EOF; $i++; } } ?> So anyone know a quick fix to this? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/85118-solved-problem-w-mysql-php/ Share on other sites More sharing options...
mrdamien Posted January 9, 2008 Share Posted January 9, 2008 while($row = mysql_fetch_array($sql2)) // This line makes $row the first row { echo '<h2 class="subh2">',$row[3],'</h2>'; while($row = mysql_fetch_array($sql2)) // This line loops through all the other rows. (starting from #2) { $i = 0; echo <<< EOF *ommited* >>> $i++; } } This should fix it: $i = 0; while($row = mysql_fetch_array($sql2)) { if($i==0){ echo '<h2 class="subh2">' . $row[3] . '</h2>'; } echo <<< EOF *ommited* >>> $i++; } Link to comment https://forums.phpfreaks.com/topic/85118-solved-problem-w-mysql-php/#findComment-434201 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.