[PHP-DB] Next, prev, records in MySql. Handler Function
Dear all: I have been exploring about this issue quite a lot, and find no solution: Platform: Debian, MySql 4.1.11, PHP 4.3.10-2, Apache. Is there any way I can retrieve a set of values depending in a where clause: For example: from a set of values in one field: 1,2,5,8,9,11,13 I'd like to retrieve a record (8) and also the previous one (5) and the next one (9) (so the record set would be: 5,8,9) I have found the Handler function in the Manual, but it and keeps giving me errors (I have also checked in the manual and it seems to work with MySql 4.1.x) /* --Start example - HANDLER tbl_sm04_indicador READ PK_indicador_id { FIRST | NEXT | PREV | LAST } WHERE PK_indicador_id=8 LIMIT 0, 3 -- --End example (I know, I am completely lost)*/ Does anybody has tried this function before?. Is it useful for the result I would like to accomplish? Could anybody could share an example of how to use this function? Thanks and best regards. Alvaro Cobo -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Multiple query execution
Hi guys: I need to execute two insert/update queries within a single statement string from a PHP application, but it keeps giving me an error. For example, I have a listbox which has to insert or update two tables whithin the same submit action: INSERT INTO tbl_ISperson(NamePerson, Country) VALUES('John Smith', '{var_country}'); INSERT INTO tbl_pais_src(name_country) VALUES('{var_country}'); /*Where {var_country}is a variable which stores the value of a country*/ I have found this page (http://dev.mysql.com/doc/mysql/en/c-api-multiple-queries.html), but I don´t know how to implement it: From version 4.1, MySQL supports the execution of multiple statements specified in a single query string. To use this capability with a given connection, you must specify the CLIENT_MULTI_STATEMENTS option in the flags parameter of mysql_real_connect() when opening the connection. You can also set this for an existing connection by calling MySQL Reference Manual :: 23.2.9 C API Handling of Multiple Query Execution mysql_set_server_option MYSQL_OPTION_MULTI_STATEMENTS_ON) By default, mysql_query() and mysql_real_query() return only the first query status and the subsequent queries status can be processed using mysql_more_results() and mysql_next_result() Does anybody has tried it in php?. Does anyone could share an example? Thanks in advance and best regards. Alvaro. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Function to create bar chart problem
Hi guys. I am a newbie triying to do grown-up people stuff :) I am trying to write a function to create a bar chart using JPGraph where I have to pass two variables (query name, and x axis column name) and the function creates the graphic. It is because I have several queries with diferent length, so I would like to have a function to create lots of graphics without to much coding. I have two questions: a) How could I create an array which collects the result of a mysql_fetch_array() function (excluding only the first column). b) How can I execute the string from a variable as if it where part of the script: For example I have the following variable var1 = '$y_'.$row_query[$org_field_name].' = new BarPlot('.($row_query).');'; which creates a string like this: $y_org1=new BarPlot(array); /* $y_org1 is the result of the query $row_query[$org_field_name] and $row_query is the array which contains the result of $row_query=mysql_fetch_assoc($sql)*/ Any clue will be very, very, very appreciated. Best regards, Alvaro Following is the whole code. 1. The sample table is as follows +--++++ | org_name | field1 | field2 | field3 | +--++++ | org1 | 1 | 5 | 10 | | org2 | 12 | 4 | 8 | | org3 | 45 | 12 | 20 | | org4 | 40 | 30 | 4 | +--++++ 2. The script as far as I've got it is: FILE: functions.inc.php ?php include ( ../../addons/jpgraph/src/jpgraph.php); include (../../addons/jpgraph/src/jpgraph_bar.php); function fnc_y_name($query_name, $org_field_name) { $row_query=mysql_fetch_assoc($query_name);//Array que recoge los datos de las filas de la consulta. $total_rows=mysql_num_rows($query_name); //Nmero total de filas que devuelve la consulta $total_fields=mysql_num_fields($query_name);//Nmero total de campos en la consulta for($i=1; $i$total_fields; $i++) { $fieldname = mysql_field_name($query_name,$i); $array_fieldname[] = $fieldname; }; do { for($i=0; $i$total_fields-1; $i++) { $y_data[] = $row_query[$array_fieldname[$i]]; //Here is my bigger problem. } } while ($row_query=mysql_fetch_assoc($query_name)); //STARTS THE GRAPHIC CREATION //Creates the graphic $graph = new Graph(900,400,auto); $graph-SetScale(textlin); $graph-SetShadow(); $graph-img-SetMargin(40,30,20,40); //I will try to build this calls with a do..while loop from the data collected from the y_data array. This is why I need to pass the variable or array contents directly to the script. $b1plot = new BarPlot($y_data); $b1plot-SetFillColor(olivedrab3); $b2plot = new BarPlot($y_data); $b2plot-SetFillColor(orange); // Joins the plots $gbplot = new GroupBarPlot(array($b1plot, $b2plot)); // Executes the graphic $graph-Add($gbplot); $graph-title-Set(Graphic Title); $graph-subtitle-Set(Sales); $graph-xaxis-title-Set(Organization); $graph-yaxis-title-Set(Sales amount in thousands); $graph-img-SetMargin(75,30,80,80); $graph-title-SetFont(FF_FONT1,FS_BOLD); $graph-yaxis-title-SetFont(FF_FONT1,FS_BOLD); $graph-xaxis-title-SetFont(FF_FONT1,FS_BOLD); // Displays the graph $graph-Stroke(); }; //End of the function ? FILE: function_test.php (executes the function) ?php require_once('../Connections/sis_mon_conn.php'); include('../Connections/my_connection.php'); include (functions.inc.php); ? ?php mysql_select_db($database_sis_mon_conn, $sis_mon_conn); $query_rec_sql = SELECT * FROM test; $rec_sql = mysql_query($query_rec_sql, $sis_mon_conn) or die(mysql_error()); $row_rec_sql = mysql_fetch_assoc($rec_sql); $totalRows_rec_sql = mysql_num_rows($rec_sql); mysql_data_seek($rec_sql, 0); fnc_y_name($rec_sql, org_name); ? ?php mysql_free_result($rec_sql); ? //I know, the code is awful, but is the best I have got with my poor experience
[PHP-DB] mysql_data_seek problem
Hi all: I am having problems with the function mysql_data_seek when it refers to an array with an empty recordset (for example when the query does not returns data), so I keep receiving the following message in the browser: Warning: mysql_data_seek(): Offset 0 is invalid for MySQL result index 9 (or the query data is unbuffered) in /var/www/intranet/inform/view.php on line 146 I need this function to reset an array to use the same query several times in the same page. Does anybody knows how to avoid this message to be printed? Thanks a lot. Alvaro
[PHP-DB] Managing Many2Many with PHP/JS
Hi guys: Thanks in advance for your help. I am newby in this PHP stuff and I've got quite a problem here, and Ive spent several days (and nights) trying to solve this problem. I am trying to manage a many to many relationship in a web database application. I have three tables: tbl_project (which contains the name of a development project), tbl_Contraparte(which contains the name of the organisations which manage the project) and tbl_ProyOrg (which contains two fields: proy_id and OrgSigla) and is the join table for the many2many relationship. I have created a form for the tbl_project table with all the data referring to the project. Into this form I´ve personalized some code (I have fetched from internet) to create a table which dynamically creates new rows into the tbl_ProyOrg table (in the client side using JavaScript) with a drop down box, so the page do not needs to reload every time the new row is created. As you will see my problem stands in populate the select box with a query from a MySql database made using PHP into the JavaScript function. You can find the code following: Thanks a lot Best regards, Alvaro. OS: Linux Debian Sarge Apache: 2.0 PHP: 4.3.10-2 Mysql: 4.1.8 !--Here starts the code-- ?php $hostname_monitoreo_conn = host; $database_monitoreo_conn = database_name; $username_monitoreo_conn = username; $password_monitoreo_conn = password; $monitoreo_conn = mysql_pconnect($hostname_monitoreo_conn, $username_monitoreo_conn, $password_monitoreo_conn) or trigger_error(mysql_error(),E_USER_ERROR); ? ?php mysql_select_db($database_monitoreo_conn, $monitoreo_conn); $query_rs_contraparte = SELECT orgSigla FROM tbl_02Contraparte ORDER BY orgSigla ASC; $rs_contraparte = mysql_query($query_rs_contraparte, $monitoreo_conn) or die(mysql_error()); $row_rs_contraparte = mysql_fetch_assoc($rs_contraparte); $totalRows_rs_contraparte = mysql_num_rows($rs_contraparte); ? !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd; html head link rel=stylesheet href=monitoreo.css type=text/css / titleProjects by organisation/title /head body h4Projects by organisation/h4 form action=./ins_ProyOrg.php method=post enctype=multipart/form-data Project_Id: input name=tf_proyId type=text id=tf_proyId / pa href=javascript:add_row()Add an organisation/a/p !-- Here begins the function to create a new row for a new organisation-- script type=text/javascript var rows = 1; function add_row() { var counter; var ptable = document.getElementById('tbl_ProyOrg'); var trow = document.createElement('tr'); //creates the tag for a a new table row trow.setAttribute('id', 'r' + rows); //Here IE 6.0 reports an error, but it works in Firefox1.0 and Opera var ptd = new Array(4); var arKind = Array('input', 'select', 'input'); //defines the kind of control var arNames = Array('proyId[]','orgSigla[]','none'); //defines the name of the control var arTypes = Array('hidden','text','button'); //defines de type of the control for (counter = 0; counter arTypes.length; counter++) //Loop wchich creates one by one the elements of the table { ptd[counter] = document.createElement('td'); var p = document.createElement('span') var pinput = document.createElement(arKind[counter]); pinput.setAttribute('name', arNames[counter]); pinput.setAttribute('type', arTypes[counter]); pinput.setAttribute('id', arNames[counter]); /* THE MAIN PROBLEM IS HERE (at least I guess so :) ). I am trying to give the option values to the select control, from the query listed at the beginning of the file. I suposse the big problem is in the array definition but I have no idea of how to build a proper array. if (arKind[counter] == 'select') { var num_rec = ?php echo $totalRows_rs_contraparte; ?; var list_rec = ?php echo $row_rs_contraparte; ?; var source_combo = new Array(num_rec); for (i=0, i num_rec, i++) { source_combo[i]= list_rec[i]; } pinput.options(source_combo[i]); } */ if (arTypes[counter] == 'button') { pinput.setAttribute('value', 'x'); pinput.onclick = removeNode; pinput.rId = 'r' + rows; } //This is the part which actually creates the table row p.appendChild(pinput); ptd[counter].appendChild(p); trow.appendChild(ptd[counter]); } ptable.appendChild(trow);
[PHP-DB] Nested forms in php (subform)
Hi guys: I am a very newby in this php stuff and I need a huge help from you: I am looking for the way to make a kind of nested form (in the sense of the access subforms), to insert information of a one to many relationaship. For example, I have to tables: tblProjects: with information about especific projects. tblDevelopers: with the information of all the developers of each project. Any project can be developed by one or more developer. So I need to design a form in which I have a textfield for the project and many textfield for the developers. So when I send the information it inserts the register of the project into the tblProject table and the registers of the developers into tblDeveloper. I have researched and tried a lot about this stuff and it has been very difficult to find it. Thanks a lot, Alvaro. ___ Moving house? Beach bar in Thailand? New Wardrobe? Win £10k with Yahoo! Mail to make your dream a reality. Get Yahoo! Mail www.yahoo.co.uk/10k -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php