Re: [PHP4BETA] PHP with mysql
| From: | David Robley | Date: | Thu, 09 Dec 1999 23:35:57 +0000 |
| Subject: | Re: [PHP4BETA] PHP with mysql | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-7743@lists.php.net to get a copy of this message | ||
On 9 Dec, Matt Greene wrote:
> What is the command that I would use to display a row from a mysql table?
> Here is what I am using now:
>
>
> // -----------------------------------------------Start
> function show() {
> global $mysqlconn, $sqluserdb, $sqlmaindb, $sqldb, $PHP_SELF, $id;
> $query = "SELECT * FROM $sqlmaindb";
> $result = mysql_db_query( "$sqldb", $query, $mysqlconn);
>
> if ($result) {
> mysql_data_seek( $result, $id );
> $row=mysql_fetch_array($result);
> $name = $row["name"];
> $email = $row["email"];
> $topic = $row["topic"];
> $body = $row["body"];
> echo "<table border='1' width='100%'
> bgcolor='#003973' cellspacing='1'
> bordercolor='#000000'>";
> echo "<tr><td><font size=1 color=white><b>$topic</b> -
> ";
> echo "Posted by $name | ";
> echo "<a
> href='mailto:$email'>$email</a></td></tr>";
> echo "<tr><td>$body</td></tr></table>";
>
> } else {
> echo "No data.";
> }
>
> }
> // -----------------------------------------------End
>
> all of the variables are defined that are in global, currently this will
> show only the first row and nothing else, the $id is what it is getting the
> number of the row from but it only displays the first in the table and
> nothing else.
>
> Please help...
You are getting just what you ask for - the record whose id is id. Have
a look at the sample code snippet in the docs for mysql_fetch_array;
you'll notice there is a while loop that cycles through all the records
returned.
--
David Robley
WEBMASTER | Phone +61 8 8374 0970
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA
Visit the PHP mirror at http://au.php.net:81/
<<<<<<<<<<<<< WARNING * END OF TEXT * STOP READING HERE
>>>>>>>>>>>>>>