Forum Moderators: coopster

Message Too Old, No Replies

How to get more than 1 result in a table

         

johnnydequino

4:02 pm on Dec 27, 2003 (gmt 0)

10+ Year Member



Someday I hope to contribute to this thread instead of asking questions. =)

I have wrote a PHP script, with MYSQL, that reads a database based on users input. When the criteria only matches one result in the database, everythings fine. But when the data has two results I need to display, I only show one. Do I need to write some kind of loop?

jd

andrewB

4:59 pm on Dec 27, 2003 (gmt 0)

10+ Year Member



Check the php manual theres an example of exactly what you want in the mysql_fetch_assoc() and mysql_fetch_array() function information. You would reduce the amount of questions you ask by reading more especially the manuals! :)

travelbuff

5:54 pm on Dec 27, 2003 (gmt 0)

10+ Year Member



Johnny:

The sequence is something like this:

1. build a query to select the data you want to display:
$query = "SELECT * FROM dbtable WHERE fieldname = 'match'";

2. run the query
$result = @MYSQL_QUERY($query);

3. put the result in a useable array
$while ($row = mysql_fetch_array($result)) {
$match = $row[match] ;

4. display the match, still inside the while loop
$display .= "<li>$match</li>" ;

5. close the loop and display your matches
}
echo "$display";

This should give you an idea of the sequence, but it is not meant to teach you the syntax. As AndrewB pointed out, the manuals are really helpful and there are some great tutorials on the web:
php-mysql tutorials
[google.com].

Mark