Ok, here is the question:

I have a sql query, nothing special. It has 3 variables. I have created the
php code to display the variables in context with the html code. I need it
to loop a select number of times, most likely twice, and therefore display
the first two rows of the query.

In other words, querying the database for a set of rows, it needs to display
the first two of the rows on the page.

Here is the code I have tried so far, which has either looped continuosly or
displayed the top row twice (edited for security):

<?php


 $sql  = "SELECT * FROM [database] ORDER BY [collumn] LIMIT 2";
 $result = mysql_query($sql) or die("problem with $sql");
 // list($title) = mysql_fetch_array($result);
?>

<td width=48% align=left valign=top>

<h3>What's New?</h3>

<?php

/* It tried this: */ while(list($link, $title, $content) =
mysql_fetch_array($result)){

/* And this: */ while($row = mysql_fetch_array($result) and (($count++)<2)){

// The first kept looping infinitely, the second displayed the top row
twice. Grr... >_<

?>

<h4>
<a href="<?php echo mysql_result($result,0,"link"); ?>"><?php echo
mysql_result($result,0,"title"); ?></a>
</h4>
<p>
<?php echo mysql_result($result,0,"content"); ?>
</p>

<?php
}
?>

</td>

Thanks for any help you can provide.

-Keith Posehn



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to