Jump to content

Recommended Posts

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

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++;
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.