RE: MySQL: How to properly extract fields from retrieved single record ???

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,


I think this is what you are trying to do. You get a record back that
has seveal fields and you want to reference those fields indiviually.

This is what I do in this example (which shows people information) and
present in HTML table

********************************EXAMPLE********************************

$result = mysql_query("select * from ledenlijst order by naam",$db);
if ($myrow = mysql_fetch_row($result))
{
        print("<table border=\"0\" >\n");
        print("<tr><td bgcolor=\"#990066\"><a
href=all.php?insert=yes>Toevoegen<<a></td>\n");
        print("<td bgcolor=\"#990066\"><b>Naam</b></td>\n");
        print("<td bgcolor=\"#990066\"><b>Voornaam</b></td>\n");
        print("<td bgcolor=\"#990066\"><b>Straat</b></td>\n");
        print("<td bgcolor=\"#990066\"><b>Postcode</b></td>\n");
        print("<td bgcolor=\"#990066\"><b>Woonplaats</b></td>\n");
        print("<td bgcolor=\"#990066\"><b>Telefoon</b></td>\n");
        print("<td bgcolor=\"#990066\"><b>Gsm</b></td>\n");
        print("<td bgcolor=\"#990066\"><b>E-Mail</b></td>\n");
        print("<td bgcolor=\"#990066\"><b>Brevet</b></td></tr>\n");
do
{
        print("<tr><td bgcolor=\"#0000cc\">");
        print("<a href=all.php?id=$myrow[0]&update=yes>update</a> / <a
href=all.php?id=$myrow[0]&delete=yes>delete</a>");
        print("\n");
        print("</td><td bgcolor=\"#0000cc\">");
        print($myrow[1]);
        print("\n");
        print("</td><td bgcolor=\"#0000cc\">");
        print($myrow[2]);
        print("\n");
        print("</td><td bgcolor=\"#0000cc\">");
        print($myrow[3]);
        print("\n");
        print("</td><td bgcolor=\"#0000cc\">");
        print($myrow[4]);
        print("\n");
        print("</td><td bgcolor=\"#0000cc\">");
        print($myrow[5]);
        print("\n");
        print("</td><td bgcolor=\"#0000cc\">");
        print($myrow[6]);
        print("\n");
        print("</td><td bgcolor=\"#0000cc\">");
        print($myrow[9]);
        print("\n");
        print("</td><td bgcolor=\"#0000cc\">");
        print($myrow[7]);
        print("\n");
        print("</td><td bgcolor=\"#0000cc\">");
        print($myrow[8]);
        print("\n");
        print("</td></tr>\n");
}
while ($myrow = mysql_fetch_row($result));
print("</table>\n");
}
else
{
print("<b>Sorry, no Records were found!</b>");
}
********************************EXAMPLE********************************


-----Original Message-----
From: -{ Rene Brehmer }- [mailto:metalbunny@metalbunny.net] 
Sent: Monday, September 22, 2003 1:57 PM
To: php-db@lists.php.net
Subject:  MySQL: How to properly extract fields from retrieved
single record ???


Hi gang

Still working on this DB for my gameclan.... not that it's essential
what 
it's for... and be warned: Never worked with any form of DB in PHP
before I 
began this project, so I'm a total n00b at these MySQL commands (and the

manual for MySQL is by far nowhere near as good as the PHP one).

Anyways, I'm retrieving a single record from the DB table, and then, 
because of the way the data needs to be displayed and manipulated, need
to 
extract every single field from that record as a seperate value.

I tried this:

     $num2edit = $_POST['edit'];
     $link = mysql_connect($host,$username,$password)
       or die('Could not connect : '.mysql_error());
     mysql_select_db($database) or die('Could not select database');

     $query = "SELECT 
countryNum,country,nw,gov,strat,spy,troops,jets,turrets,tanks,ally,owner

FROM a2a WHERE countryNum=$num2edit";
     $result = mysql_query($query);

     $countryNum = mysql_result($result,1,'countryNum');
     $country = mysql_result($result,1,'country');
     $nw = mysql_result($result,1,'nw');
     $gov = mysql_result($result,1,'gov');
     $strat = mysql_result($result,1,'strat');
     $spy = mysql_result($result,1,'spy');
     $troops = mysql_result($result,1,'troops');
     $jets = mysql_result($result,1,'jets');
     $turrets = mysql_result($result,1,'turrets');
     $tanks = mysql_result($result,1,'tanks');
     $ally = mysql_result($result,1,'ally');
     $owner = mysql_result($result,1,'owner');

     /* Free resultset */
     mysql_free_result($result);
     /* Closing connection */
     mysql_close($link);

But all it gives me are errors like this:

Warning: mysql_result(): supplied argument is not a valid MySQL result 
resource in E:\web\mpe\a2aedit.php on line 350
Warning: mysql_result(): supplied argument is not a valid MySQL result 
resource in E:\web\mpe\a2aedit.php on line 351
Warning: mysql_result(): supplied argument is not a valid MySQL result 
resource in E:\web\mpe\a2aedit.php on line 352
Warning: mysql_result(): supplied argument is not a valid MySQL result 
resource in E:\web\mpe\a2aedit.php on line 353
Warning: mysql_result(): supplied argument is not a valid MySQL result 
resource in E:\web\mpe\a2aedit.php on line 354
Warning: mysql_result(): supplied argument is not a valid MySQL result 
resource in E:\web\mpe\a2aedit.php on line 355
Warning: mysql_result(): supplied argument is not a valid MySQL result 
resource in E:\web\mpe\a2aedit.php on line 356
Warning: mysql_result(): supplied argument is not a valid MySQL result 
resource in E:\web\mpe\a2aedit.php on line 357
Warning: mysql_result(): supplied argument is not a valid MySQL result 
resource in E:\web\mpe\a2aedit.php on line 358
Warning: mysql_result(): supplied argument is not a valid MySQL result 
resource in E:\web\mpe\a2aedit.php on line 359
Warning: mysql_result(): supplied argument is not a valid MySQL result 
resource in E:\web\mpe\a2aedit.php on line 360
Warning: mysql_result(): supplied argument is not a valid MySQL result 
resource in E:\web\mpe\a2aedit.php on line 361

Obviously, the first mysql_result line is line 350 in the full code.
I've 
also tried changing the row number to 0, but results in the same errors.

I can't find any decent reference on the web that shows how to do this -

field extraction - when there's only the single record. So I've been
mixing 
code from various places. And I don't even know if it retrieves the
right 
record, or any record at all (how do I test that?).

Any help is highly appreciated :)

TIA

Rene
-- 
Rene Brehmer
aka Metalbunny

http://metalbunny.net/
References, tools, and other useful stuff...

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

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux