Re: [PHP-DB] MySQL: How to properly extract fields from retrieved single record ???
On Mon, 22 Sep 2003, -{ Rene Brehmer }- wrote: $result = mysql_query($query); replace with: $result = mysql_query($query) or die(MySQL Error: .mysql_error().\nbr/SQL: .$query); If the query fails, you will see why the query failed, and be able to view the query itself. Maybe $_POST['edit'] isn't set. Maybe you have a problem in your SQL. Maybe the DB you are connecting to doesn't exist. I would check your connection as well. Beckman --- Peter Beckman Internet Guy [EMAIL PROTECTED] http://www.purplecow.com/ --- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] MySQL: How to properly extract fields from retrieved single record ???
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(trtd bgcolor=\#990066\a href=all.php?insert=yesToevoegena/td\n); print(td bgcolor=\#990066\bNaam/b/td\n); print(td bgcolor=\#990066\bVoornaam/b/td\n); print(td bgcolor=\#990066\bStraat/b/td\n); print(td bgcolor=\#990066\bPostcode/b/td\n); print(td bgcolor=\#990066\bWoonplaats/b/td\n); print(td bgcolor=\#990066\bTelefoon/b/td\n); print(td bgcolor=\#990066\bGsm/b/td\n); print(td bgcolor=\#990066\bE-Mail/b/td\n); print(td bgcolor=\#990066\bBrevet/b/td/tr\n); do { print(trtd bgcolor=\#cc\); print(a href=all.php?id=$myrow[0]update=yesupdate/a / a href=all.php?id=$myrow[0]delete=yesdelete/a); print(\n); print(/tdtd bgcolor=\#cc\); print($myrow[1]); print(\n); print(/tdtd bgcolor=\#cc\); print($myrow[2]); print(\n); print(/tdtd bgcolor=\#cc\); print($myrow[3]); print(\n); print(/tdtd bgcolor=\#cc\); print($myrow[4]); print(\n); print(/tdtd bgcolor=\#cc\); print($myrow[5]); print(\n); print(/tdtd bgcolor=\#cc\); print($myrow[6]); print(\n); print(/tdtd bgcolor=\#cc\); print($myrow[9]); print(\n); print(/tdtd bgcolor=\#cc\); print($myrow[7]); print(\n); print(/tdtd bgcolor=\#cc\); print($myrow[8]); print(\n); print(/td/tr\n); } while ($myrow = mysql_fetch_row($result)); print(/table\n); } else { print(bSorry, no Records were found!/b); } EXAMPLE -Original Message- From: -{ Rene Brehmer }- [mailto:[EMAIL PROTECTED] Sent: Monday, September 22, 2003 1:57 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] 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():
Re: [PHP-DB] MySQL: How to properly extract fields from retrieved single record ???
read the PHP manual and examples under the function mysql_fetch_array(). I find the MySQL manual is very well done and helpful. I've been using it as a reference for 2 years. Take a harder look! Ignatius _ - Original Message - From: -{ Rene Brehmer }- [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, September 22, 2003 1:57 PM Subject: [PHP-DB] 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
Re: [PHP-DB] MySQL: How to properly extract fields from retrieved single record ???
On Mon, 22 Sep 2003 13:06:37 +0200 Ignatius Reilly [EMAIL PROTECTED] wrote: read the PHP manual and examples under the function mysql_fetch_array(). I find the MySQL manual is very well done and helpful. I've been using it as a reference for 2 years. Take a harder look! I think Ignatius meant the PHP manual... It is rather terse, but the functions have been categorised to make it easier to find. See code alteration below. George Patterson Ignatius Hi gang -snipped-- 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 Duplicate error message delete... 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. This ain't microsoft anymore... $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; echo This is for test only: Print Query- $querybr\n; $result = mysql_query($query); $row=mysql_fetch_assoc($result); #$row is an array. #display the row retrived from the database. For you information only. echo pre\n; print_r($row); echo /pre\n; $countryNum = $row['countryNum']; $country = $row['country']; $nw = $row['nw']; #then close the database connection... As you had it... 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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php