On Tuesday 11 June 2002 13:20, Bill Fleury wrote:
> Hi all.  I am very new to this, and have been reading my way through php,
> but have come accross a stumbling block that I just don't seem able to get
> past, although I'm sure it's something simple.
>
> I have a very basic mysql database set up, that contains a table with 4
> fields- type, manname, manlink, and recordno
>
> What I need to do is pull all records from the database, and provide a list
> on a page with links to the url's stored in manlink with the lable manname.
>  So far, I've come up with the script at the end of this message.  This
> script works beautifully for me- for the first record.  

The fact that it works 'beautifully' is just luck!

> Could anyone point
> out why it won't go on to any other records?

Your logic is completely messed up :)

> <?php
>     /* Connecting, selecting database */
>     $link = mysql_connect("192.168.0.112", "root", "")
>         or die("Could not connect");
>     print "Connected successfully";
>     mysql_select_db("dgdrivers") or die("Could not select database");

The above is OK. But for better error reporting you should replace the die() 
statements with something like:

  die('Could not connect. The error was: ' . mysql_error())

This will display your message along with the actual error returned by mysql.

>     /* Performing SQL query */
>
>     $getlength = "select * from man_links";
>     $length = mysql_query($getlength);
>     $idl = count($length);
>
>     for ($id = 1 ;; $id++ ) {
>                 if ($id > $idl) {
>                         break;
>                 }
>
>
>     $query = "SELECT type, manname, manlink FROM man_links WHERE
> recordno=$id"; $result = mysql_query($query) or die("Query failed");
>
>     extract(mysql_fetch_array($result));
>
>     /* Printing results in HTML */
>     print "<table>\n";
>     print "<p><a href=$manlink>$manname</a>";
>     print "</table>\n";
>
> }
>     /* Free resultset */
>     mysql_free_result($result);
>
>     /* Closing connection */
>     mysql_close($link);

Here's the standard way to retrieve a set of results from a query:

$query = "SELECT manname, manlink FROM man_links";
$resultID = mysql_query($query) 
            OR die("Error in query $query : " . mysql_error());
while ($row = mysql_fetch_array($resultID)) {
  print "Man Name : " . $row['manname'];
  print "Man Link : " . $row['manlink'] . '<br>';
}
mysql_free_result($result); # optional, as php cleans up automatically
mysql_close($link);         # at the end of the script

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *


/*
QOTD:
        I looked out my window, and saw Kyle Pettys' car upside down,
        then I thought 'One of us is in real trouble'.
                -- Davey Allison, on a 150 m.p.h. crash
*/


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

Reply via email to