On Saturday 22 June 2002 06:27, Jonathan wrote:
> Hello everyone,
>     I am brand new to php, so any replies I get are very much appreciated.
> My goal is to retrieve one entire table from my database and post the
> information on the web.  My query seems successful, but I am having trouble
> getting the information out from the variable $result.  

Saying exactly what the trouble is would help!

> My table has 4
> fields, the primary key, "location," "organization," and "charge."   Any
> suggestions?   A million thanks.  Here is the code:
>
> <html>
> <body>
> <?
>    /* Connectiong*/
> @ $db = mysql_connect("localhost", "NAME","PASS");
>
>    if (!$db)
> {
>       echo "Error, please try again.";
>       exit;
> }
> /* Selecting database*/
> $db2 = mysql_select_db ("DATABASE");
> if (!$db2)
> {
>   echo "error again";
>   exit;
> }
>      /*sending query */
>         $query = "select * from `$mytable` where $i";
>         $result = mysql_query($query);
>
>         /*testing to see if result has the data */
>         if (!$result){echo "result is empty";}
>
> for ($a=0;$a<4;$a++)
> {
>      for($i=0;$i<4;$i++)
> {
>           $row = mysql_fetch_array($result);
>         echo $row[i]["organization"]."<br>";
>         echo $row[i["location"]."<br>";
>          echo $row[i]["charge"];
>   }
> }

The standard way to retrieve results from a query would be:

while ($row = mysql_fetch_array($result)) {
  echo $row['organization'];
  ...
  ...
}

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

/*
        "What did you do when the ship sank?"
        "I grabbed a cake of soap and washed myself ashore."
*/


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

Reply via email to