[PHP-DB] Paging
Hi everybody, I have a paging question. I have a page where you can view a persons 'profile'. And I have a list taken from the db of there books. I can get all the books on one page but I can't figure out the WHERE from the get. This is what I tried but it didn't work. $query = "SELECT COUNT(*) AS numrows FROM tabs WHERE user_name='".$_GET ['user_name']."'; $data = mysqli_query($dbc, $query) or die('Error, query failed'); $row = mysqli_fetch_array($data); $numrows = $row['numrows']; When I do this it shows a second page but when I click on the next page It goes to my profile or the user who is logged in, not the users profile I was looking at on page 1. Thanks every one for all your help!!
Re: [PHP-DB] PHP & Postgres - query not writing to database.
Glad that you found the problem :) Carol Walter napsal(a): To all who helped. Thank you very much. I found the problem. There is a leading blank on the last name field that I couldn't see. It was coming from my program code. Thanks for all your help. Carol On May 11, 2009, at 4:23 PM, Carol Walter wrote: I have copied the queries into psql and wrapped them in a BEGIN and COMMIT. Even from psql the queries appear to work but don't store the information. There don't appear to be errors in the log either. Thanks for your help, Carol km_tezt=# begin; BEGIN km_tezt=# INSERT INTO "tblPeople"("fName","mName","lName", ivlweb, cnsweb) VALU ES ('Frank', 'D',' Oz', 't', 't'); INSERT 0 1 km_tezt=# INSERT INTO "tblContactInformation"("contactItem","contactType") VALU ES ('f...@indiana.edu','0010'); INSERT 0 1 km_tezt=# INSERT INTO "brdgPeopleContactInformation" ("peopleId","contactInform ationId",rank, type) VALUES (currval('"tblPeople_peopleId_seq"'),currval('"tblC ontactInformation_contactInformationId_seq"'), '1', '100'); INSERT 0 1 km_tezt=# commit; COMMIT km_tezt=# select * from "tblPeople" where "lName" like 'O%'; peopleId | fName | mName | lName | ivlweb | cnsweb --+-+---+++ 404 | Ilka| | Ott| t | t 410 | Elinor | | Ostrom | t | t 374 | Gregory | | O'Hare | t | t 33 | Terry | J.| Ord| t | t (4 rows) On May 10, 2009, at 4:41 AM, danaketh wrote: I'd suggest you to copy the echoed queries and run them directly in terminal (if you have access). Also if you have remote access to the database and can use tools like pgAdmin or Navicat, that could help you with testing. Or send me the table structure and I'll try them myself ;) Carol Walter napsal(a): Hello, I have a PHP program that contains a number of postgres queries. At the end of the program, it needs to write data to a database. You can see the code that I'm using below. I have "die" clauses on all the queries and I have the program echoing the queries that it runs to the screen. The "die" clause does not execute. The queries are echoed to the screen, but nothing is being written to the database. There don't appear to be any errors in the postgres log or the php log. Is there a function that I can use that will tell me exactly what is going on here? If there is, can you give me the syntax? Thanks in advance for your time. Carol P.S. This PHP 5 and PostgreSQL 8.3.6 on Solaris 10. ++ I've written a query that needs to insert data into two base tables and a bridge table. The code looks like... /* Echo data for database to the screen */ echo" Contact Locator: $cont_loc"; echo" Contact Type Rank: $cont_rank"; echo" Contact Info Type: $contact_type"; echo" New name string: $f_name_new"; echo" New name string: $m_name_new"; echo" New name string: $l_name_new"; echo" New ivl web string: $ivl_web_peop"; echo" New cns_web string: $cns_web_peop"; echo" New contact rank string: $cont_rank"; echo" New contact locator string: $cont_loc"; echo" New contact item string: $contact_info1"; echo" New contact type string: $contact_type"; /* Connect to database*/ include "connect_km_tezt.php"; /* Run queries*/ $query = "INSERT INTO \"tblPeople\"(\"fName\",\"mName\",\"lName\", ivlweb, cnsweb) VALUES ('$f_name_new', '$m_name_new',' $l_name_new', '$ivl_web_peop', '$cns_web_peop')"; echo "First query: " . $query . ""; $pg_peop_ins = pg_query($query) or die("Can't execute first query"); // echo pg_last_error("Last Error " . $pg_peop_ins); //echo pg_result_error($pg_peop_ins); $query = "INSERT INTO \"tblContactInformation\"(\"contactItem\",\"contactType\") VALUES ('$contact_info1','$contact_type')"; echo "Second query: " . $query . ""; $pg_contact_ins = pg_query($query) or die("Can't execute 2nd query"); $query = "INSERT INTO \"brdgPeopleContactInformation\" (\"peopleId\",\"contactInformationId\",rank, type) VALUES (currval('\"tblPeople_peopleId_seq\"'),currval('\"tblContactInformation_contactInformationId_seq\"'), '$cont_rank', '$cont_loc')"; echo "Third query: " . $query . ""; $pg_peop_cont_ins = pg_query($query) or die("Can't execute 3rd query"); + The postgres log looks like this ... [km_app_admin:km_tezt:2009-05-08 10:34:49 EDT
Re: [PHP-DB] PHP & Postgres - query not writing to database.
To all who helped. Thank you very much. I found the problem. There is a leading blank on the last name field that I couldn't see. It was coming from my program code. Thanks for all your help. Carol On May 11, 2009, at 4:23 PM, Carol Walter wrote: I have copied the queries into psql and wrapped them in a BEGIN and COMMIT. Even from psql the queries appear to work but don't store the information. There don't appear to be errors in the log either. Thanks for your help, Carol km_tezt=# begin; BEGIN km_tezt=# INSERT INTO "tblPeople"("fName","mName","lName", ivlweb, cnsweb) VALU ES ('Frank', 'D',' Oz', 't', 't'); INSERT 0 1 km_tezt=# INSERT INTO "tblContactInformation"("contactItem","contactType") VALU ES ('f...@indiana.edu','0010'); INSERT 0 1 km_tezt=# INSERT INTO "brdgPeopleContactInformation" ("peopleId","contactInform ationId",rank, type) VALUES (currval('"tblPeople_peopleId_seq"'),currval('"tblC ontactInformation_contactInformationId_seq"'), '1', '100'); INSERT 0 1 km_tezt=# commit; COMMIT km_tezt=# select * from "tblPeople" where "lName" like 'O%'; peopleId | fName | mName | lName | ivlweb | cnsweb --+-+---+++ 404 | Ilka| | Ott| t | t 410 | Elinor | | Ostrom | t | t 374 | Gregory | | O'Hare | t | t 33 | Terry | J.| Ord| t | t (4 rows) On May 10, 2009, at 4:41 AM, danaketh wrote: I'd suggest you to copy the echoed queries and run them directly in terminal (if you have access). Also if you have remote access to the database and can use tools like pgAdmin or Navicat, that could help you with testing. Or send me the table structure and I'll try them myself ;) Carol Walter napsal(a): Hello, I have a PHP program that contains a number of postgres queries. At the end of the program, it needs to write data to a database. You can see the code that I'm using below. I have "die" clauses on all the queries and I have the program echoing the queries that it runs to the screen. The "die" clause does not execute. The queries are echoed to the screen, but nothing is being written to the database. There don't appear to be any errors in the postgres log or the php log. Is there a function that I can use that will tell me exactly what is going on here? If there is, can you give me the syntax? Thanks in advance for your time. Carol P.S. This PHP 5 and PostgreSQL 8.3.6 on Solaris 10. +++ +++ I've written a query that needs to insert data into two base tables and a bridge table. The code looks like... /* Echo data for database to the screen */ echo" Contact Locator: $cont_loc"; echo" Contact Type Rank: $cont_rank"; echo" Contact Info Type: $contact_type"; echo" New name string: $f_name_new"; echo" New name string: $m_name_new"; echo" New name string: $l_name_new"; echo" New ivl web string: $ivl_web_peop"; echo" New cns_web string: $cns_web_peop"; echo" New contact rank string: $cont_rank"; echo" New contact locator string: $cont_loc"; echo" New contact item string: $contact_info1"; echo" New contact type string: $contact_type"; /* Connect to database*/ include "connect_km_tezt.php"; /* Run queries*/ $query = "INSERT INTO \"tblPeople\"(\"fName\",\"mName\", \"lName\", ivlweb, cnsweb) VALUES ('$f_name_new', '$m_name_new',' $l_name_new', '$ivl_web_peop', '$cns_web_peop')"; echo "First query: " . $query . ""; $pg_peop_ins = pg_query($query) or die("Can't execute first query"); // echo pg_last_error("Last Error " . $pg_peop_ins); //echo pg_result_error($pg_peop_ins); $query = "INSERT INTO \"tblContactInformation \"(\"contactItem\",\"contactType\") VALUES ('$contact_info1','$contact_type')"; echo "Second query: " . $query . ""; $pg_contact_ins = pg_query($query) or die("Can't execute 2nd query"); $query = "INSERT INTO \"brdgPeopleContactInformation\" (\"peopleId\", \"contactInformationId\",rank, type) VALUES (currval('\"tblPeople_peopleId_seq \"'),currval('\"tblContactInformation_contactInformationId_seq \"'), '$cont_rank', '$cont_loc')"; echo "Third query: " . $query . ""; $pg_peop_cont_ins = pg_query($query) or die("Can't execute 3rd query"); +++ ++ The postgres log looks like this ... [km_app_admin:km_tezt:2009-05-08 10:34:49 EDT]STATEMENT: INSERT INT
Re: [PHP-DB] PHP & Postgres - query not writing to database.
I have copied the queries into psql and wrapped them in a BEGIN and COMMIT. Even from psql the queries appear to work but don't store the information. There don't appear to be errors in the log either. Thanks for your help, Carol km_tezt=# begin; BEGIN km_tezt=# INSERT INTO "tblPeople"("fName","mName","lName", ivlweb, cnsweb) VALU ES ('Frank', 'D',' Oz', 't', 't'); INSERT 0 1 km_tezt=# INSERT INTO "tblContactInformation"("contactItem","contactType") VALU ES ('f...@indiana.edu','0010'); INSERT 0 1 km_tezt=# INSERT INTO "brdgPeopleContactInformation" ("peopleId","contactInform ationId",rank, type) VALUES (currval('"tblPeople_peopleId_seq"'),currval('"tblC ontactInformation_contactInformationId_seq"'), '1', '100'); INSERT 0 1 km_tezt=# commit; COMMIT km_tezt=# select * from "tblPeople" where "lName" like 'O%'; peopleId | fName | mName | lName | ivlweb | cnsweb --+-+---+++ 404 | Ilka| | Ott| t | t 410 | Elinor | | Ostrom | t | t 374 | Gregory | | O'Hare | t | t 33 | Terry | J.| Ord| t | t (4 rows) On May 10, 2009, at 4:41 AM, danaketh wrote: I'd suggest you to copy the echoed queries and run them directly in terminal (if you have access). Also if you have remote access to the database and can use tools like pgAdmin or Navicat, that could help you with testing. Or send me the table structure and I'll try them myself ;) Carol Walter napsal(a): Hello, I have a PHP program that contains a number of postgres queries. At the end of the program, it needs to write data to a database. You can see the code that I'm using below. I have "die" clauses on all the queries and I have the program echoing the queries that it runs to the screen. The "die" clause does not execute. The queries are echoed to the screen, but nothing is being written to the database. There don't appear to be any errors in the postgres log or the php log. Is there a function that I can use that will tell me exactly what is going on here? If there is, can you give me the syntax? Thanks in advance for your time. Carol P.S. This PHP 5 and PostgreSQL 8.3.6 on Solaris 10. ++ I've written a query that needs to insert data into two base tables and a bridge table. The code looks like... /* Echo data for database to the screen */ echo" Contact Locator: $cont_loc"; echo" Contact Type Rank: $cont_rank"; echo" Contact Info Type: $contact_type"; echo" New name string: $f_name_new"; echo" New name string: $m_name_new"; echo" New name string: $l_name_new"; echo" New ivl web string: $ivl_web_peop"; echo" New cns_web string: $cns_web_peop"; echo" New contact rank string: $cont_rank"; echo" New contact locator string: $cont_loc"; echo" New contact item string: $contact_info1"; echo" New contact type string: $contact_type"; /* Connect to database*/ include "connect_km_tezt.php"; /* Run queries*/ $query = "INSERT INTO \"tblPeople\"(\"fName\",\"mName\", \"lName\", ivlweb, cnsweb) VALUES ('$f_name_new', '$m_name_new',' $l_name_new', '$ivl_web_peop', '$cns_web_peop')"; echo "First query: " . $query . ""; $pg_peop_ins = pg_query($query) or die("Can't execute first query"); // echo pg_last_error("Last Error " . $pg_peop_ins); //echo pg_result_error($pg_peop_ins); $query = "INSERT INTO \"tblContactInformation \"(\"contactItem\",\"contactType\") VALUES ('$contact_info1','$contact_type')"; echo "Second query: " . $query . ""; $pg_contact_ins = pg_query($query) or die("Can't execute 2nd query"); $query = "INSERT INTO \"brdgPeopleContactInformation\" (\"peopleId\", \"contactInformationId\",rank, type) VALUES (currval('\"tblPeople_peopleId_seq \"'),currval('\"tblContactInformation_contactInformationId_seq\"'), '$cont_rank', '$cont_loc')"; echo "Third query: " . $query . ""; $pg_peop_cont_ins = pg_query($query) or die("Can't execute 3rd query"); + The postgres log looks like this ... [km_app_admin:km_tezt:2009-05-08 10:34:49 EDT]STATEMENT: INSERT INTO "tblPeople"("fName","mName","lName", ivlweb, cnsweb) VALUES ('Frank', 'D',' Oz', 't', 't') [km_app_admin:km_tezt:2009-05-08 10:34:49 EDT]LOG: duration: 105.005 ms [km_ap
Re: [PHP-DB] MySQL: did anyone start a transaction?
On Fri, May 8, 2009 at 6:23 PM, Bogdan Stancescu wrote: > Hello all, > > I asked this question on php-general last month > (http://marc.info/?t=12404923034&r=1&w=2), and received some answers > -- but I was directed to this list, so here. > > My question is: can I tell programatically whether the next query I'm > going to execute is already part of a transaction, using MySQL? > > The context is thus: I'm writing a PHP library which attempts to > seamlessly merge database objects and PHP objects. Architecture > discussion aside (which I'm more than open to, if anyone cares enough to > talk), I need to know whether the code outside the library has already > started a transaction or not. I need to know that because I need to > execute both PHP and SQL from a single external call -- if either one of > my internal PHP or SQL calls fail, I need to revert to the original > state before the external call. And since transactions can't be nested, > I can't unconditionally start a new transaction when the external call > is being initiated -- therefore I need to know whether the programmer > has already started a transaction or not. > > Thank you, > Bogdan > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > What about creating a global variable or singleton class to hold the start of the transaction? This is something worth reading, as it indicates that the application should manage it ( http://stackoverflow.com/questions/319788/how-do-detect-that-transaction-has-already-been-started) and that transaction fall outside of OO scope. -- Bastien Cat, the other other white meat