Re: [PHP-DB] Selct & show certain num records ?
$order="time desc"; $sql="SELECT * from $table ORDER BY $order LIMIT 0,5" or die ("Cant do sql $sql");; that would get the latest news sorted on the time. Neil - Original Message - From: Dave Carrera <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, January 31, 2002 5:54 PM Subject: [PHP-DB] Selct & show certain num records ? > Hi All > > I know this has been covered here before but can someone please remind > me how to selct just the 5 latest records in my db and show them in list > form. > > Just like phpbuilder.com dose > > I thank you in advance for repeating this information. > > Dave C :-) > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] >
[PHP-DB] Selct & show certain num records ?
Hi All I know this has been covered here before but can someone please remind me how to selct just the 5 latest records in my db and show them in list form. Just like phpbuilder.com dose I thank you in advance for repeating this information. Dave C :-) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] MSSQL Query - Unicode data in a Unicode-only collation or ntext data cannot be sent
Getting this error: Warning: MS SQL message: Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier. (severity 16) in C:\webroot\test.php on line 13 Warning: MS SQL: Query failed in C:\webroot\test.php on line 13 Warning: Supplied argument is not a valid MS SQL-result resource in C:\webroot\test.php on line 15 --- Using Windows 2000 Server with Apache 1.3.23 and PHP4.0 with SQL Server 2000. Any ideas? PHP's site didn't mention anything about SQL Server 2000. Thanks! will -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] re: newbie question: request & response
No (not out of the box anyway) BUT the beauty of PHP is its much simpler than JSP or ASP's server.response() server.request() methods (sorry if thats not the exact syntax - I haven't done huge amounts of ASP/JSP work lately), in most cases you simply output the data (i.e. print / echo "something";) for the response (maybe in conjuction with an optional http header - the default is text/html but you could send pretty much any MIME type - jpegs, pdfs etc). This means knocking up simple scripts is much easier quicker... The request object is taken care in most cases by just being there as a php variable with the same name as html / http element - i.e. if your html form has an element called "bob" then when this form is (via http post / get) sent back to a PHP script the variable is available as $bob. How simple! Sometimes you might want to use HTTP_GET_VARS['bob'] but I haven't encountered a time where thats necessary apart from when retrieving server info - auth_user, server_name etc (perhaps someone else could explain other situations when that is required?) Of course you could create request and response classes in PHP if you wanted to but that would remove the simplicity, beauty and speed of the langauge (IMHO). After all when I look at a JSP script I just think "what a waste of code - server.response(thismethod(anothermethod(x))) just to output something!!" Don't get me wrong I am not bad mouthing Java (in fact I use it too - just not for web programming) its features are there for security (ideal for e-banking), object orientated reasons and J2EE stuff, but with PHP you can really just get to the core of 90% of what web scripts need to do - you just need to return some data in HTML / XML back to the browser as efficiently and quickly as possible. I am bad mouthing ASP though! I think its over-complicated for no good reasons when compared to PHP! In addition you have a severe lack of libary functions (image manipulation, database access (other than the terribly slow ODBC option or the ADO option) XML etc). I presume VB.NET and C# will try to make up for these things by offering the windows forms interfaces and other new stuff. In my view echo "something"; (interpreted by PHP machine code cgi / isapi module) would appear on the face of things to be a lot quicker than: servlet.response("something"); (in java byte code (hmm slow!) interpreted by jsp/servlet/library engine then into machine code) or server.response("something"); (code interpreted by class / library in asp.dll or suchlike then into asp engine / windows service then machine code) obviously the string "something" would be something dynamic like a database result or such like but you get the idea. But I could be wrong! What really impresses me about PHP is that it offer a version of their scripting engine that will run on any almost any platform. This is machine code complied and so in theory outperforms the cross platform Java (byte-code), and maybe asp (visual basic - interpreted) which is also know to be a bit sluggish compared with PHP, but of course only really runs on Win32 (i know there's chillisoft - asp for unix) - but thats not exactly a realistic option. As you can see I have bathered on a bit (opps I have just realised this was a newbie question!), the reason being that I had to make this comparision for a company a while back - they said whats the best web/ intranet servers side technology - I said (after careful consideration of various factors, including such things as how easily existing staff could pick up the technlogy, and value for money) PHP running on Win32/IIS (offers the best solution - in my particular client's case - using a Windows Domain / MS-SQL Databases). What does everyone else think - or I am completely barking up the wrong tree? I expect a lot of "Linux rocks use Linux and MYSQL/Postgres" responses, but for those coming from a ASP background with IT managers wanting to use MS products whereever possible using PHP on Win32 makes sense. "Luke Crouch" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > Does PHP have built-in support for using request and response objects? > Thanks, > > -L > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Problem in editing a record
Hi ... I´m writing a code in order to update daily activities, these activities are going to be saved in 3 daily records (depending of the schedule of workers and their session id´s). I´ve already got records registered in my DB ,but the problem comes when i´m trying to edit these records to add a new activity, it displays all records ok but when i choose one in order to edit it ,it displays and edit only the last one. Can somebody help me?? Thanks ... This is the script i´m trying for : Usuario:"> Fecha:"> Actividades: Bitacora:"> %s %s\n", $PHP_SELF, $myrow["nombrebit"], $myrow["usuario"], $myrow["nombrebit"]); } } ?> -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] drop down list
apologies for answering such an already-over-answered question, but i feel that no-one has given a particularly *good* answer, so i'll add mine to the list. I use this function (as well as a couple others which do similar things for all form elements; // Creates an HTML select box of values. // $options can be one or two dimensional, if one then indexes 0+ are used as values // $misc contains any key/value pairs you want added to the tag as attributes, such // as class, style or "multiple" attributes. function display_select($name, $options, $value = 0, $misc = "unset") { $select = ""; } } $select .= "\n"; return $select; } // -Original Message- // From: B.J.Rumsey [mailto:[EMAIL PROTECTED]] // Sent: Wednesday, 30 January 2002 2:30 PM // To: php-db // Subject: [PHP-DB] drop down list // // // I have two fields artist_id, artist. How do I put the // contents of "artist" into a dropdown list. // // // -- // PHP Database Mailing List (http://www.php.net/) // To unsubscribe, e-mail: [EMAIL PROTECTED] // For additional commands, e-mail: [EMAIL PROTECTED] // To contact the list administrators, e-mail: // [EMAIL PROTECTED] // -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] request and response objects?
At 12:30 -0600 1/30/02, Matthew Crouch wrote: >basically a yes or no question my brother wants me to ask: >Does PHP support these objects? If not, Can they be faked? What, like in Java servlets/JSP pages? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] storing and retrieving arrays in mysql
Hi, thanks for the suggestions. Peter, I definitely think your second solution, the one you said you are probably going to upgrade to, is very clean: adding another table "between" categories and subcategories that defines relationships between the two. it seems like it will be much easier to code and query with this extra relationship table, rather than storing a comma-delimited list of category ids in the subcat table. Many thanks again for taking the time to explain your solution to me. Corey Eiseman Infinite Orange Incorporated http://infiniteorange.com/ "Peter Adams )" <[EMAIL PROTECTED]> wrote in message 002201c1a846$80eff0b0$[EMAIL PROTECTED]">news:002201c1a846$80eff0b0$[EMAIL PROTECTED]... > I've been working on something like this since about September/October. > It's not too hard, but it did take more coding than I thought it would. > Now, there's a couple of ways you could do this. I chose the cheap (in > terms of the number of DB tables) way out. > > The way I have it set up is this. You have certain categories ("Main" > categories) that have a parent category of ',0,' (I found I had to > enclose the categoryIDs in commas to prevent accidentally selecting a > category that matched any of the digits of any other categoryID in the > same order) then I have the subcategories which have multiple parents. > > The form to add a new product gathers all the information I need -- > category name/title, description, whether it should be displayed and the > parent category(s), with the parent categorys being displayed in the > form of checkboxes. This lets the admin select multiple categories for > the parent (we have a similar set up for the products since a product > can belong in multiple categories). > > The checkboxes themselves are named p_id (I think) and are an array, > thus I print the name value as NAME='p_id[" . $cid . "]', where $cid is > the variable containing the category ID (I actually have it in a > recordset array, of course). Then, it just prints a p_id checkbox for > each possible parent (obviously when editing the category ID of the one > being edited isn't printed). When editing, those categories to which > the category has as parents are checked. > > When the form is submitted, it puts the posted variable values (the > array of checkboxes) into a comma-delimited string. Whenever I query > the database for subcategories, unfortunately, I have to make sure I > remember to check for parent LIKE '%,ID,%' so I don't pick up one I > don't want (i.e. if I were to say LIKE '%ID%' and I was looking for ID = > 20 and had that and ID =200, subcategories with parents of category 20 > and 200 would end up returned). That's how I handled it. I'm probably > going to upgrade to this next option later on, though. > > Create a table for the categories and then a table that determines a > category's children. Basically, it's just two fields: categoryID and > parent -- with both fields making up the primary key. Then, for each > parent category they checked on the form, insert the new category's ID > in the categoryID field and the parent's ID into the parent field. > > That's probably the best way since it would probably cut down on space > (I use a TEXT field currently, whereas the second option could be done > with two MEDIUMINT fields). > > If you want some code samples, e-mail me privately. If you want to see > the script (version 1.5.23 -- we've got 2.0 almost finished up now) in > action, we've got one of our clients playing guinea pig at > www.4dacres.com. > > __ > Peter Adams[EMAIL PROTECTED] > Web Developer http://www.interkan.net > InterKan.Net, Inc. (785) 565-0991 > > > -Original Message- > > From: Corey Eiseman [mailto:[EMAIL PROTECTED]] > > Sent: Monday, January 28, 2002 2:56 PM > > To: [EMAIL PROTECTED] > > Subject: [PHP-DB] storing and retrieving arrays in mysql > > > > > > Hi folks, I've got a question hopefully someone can shed some > > light on for me. > > > > I'm building an online store for a client, and one of the > > things he wants is to organize his products into categories > > and subcategories.. not so unusual, but the kicker is he > > wants to be able to associate a subcategory with more than > > one category. > > > > I was thinking that I should be able to easily serialize an > > array of cat_IDs and store it, but my concern is that this > > will sacrifice a great deal of flexibility when retrieving > > the data. For instance when I want to get the subcategories > > in a single category, I would pretty much have to select ALL > > the rows in the subcategory table, unserialize the category > > array for each row, and then check each to see if the cat_ID > > is in the array..? > > > > That just feels inefficient to me, and I'm almost certain I > > must be overlooking something simpler.. > > > > Also, I don't think I can use a SET data type because I want > > to be able to add values
Re: [PHP-DB] how to reverse a hudge multidimensional array?
Bonsoir chef;o) thx again for helping me In fact i think the solution you gave me isn t not much faster as the while loop i use for the moment... and the execution speed is my only problem... well in fact i think i haven t be very clear with the goal i need to get. let me detail this to you frm the beginning to the end... i ve a table as follows: naffaire | ncpte 1| 3 2| 5 7| 9 5| 6 2| 5 6| 9 4| 2 1| 3 4| 2 7| 9 4| 2 9| 7 7| 9 4| 2 5| 6 4| 2 ... and 1 million lines like that... naffaire and ncpte are linked : there can only be one ncpte for a naffaire, if you find a 7 as naffaire with 9 as ncpte all the lines containing 7 as naffaire will have 9 as ncpte. BUT the opposite of this relation is not true : a ncpte can be associated with different naffaire. (as you can see in the previous example at the lines 3, 6, 10... what i do with this table is a count on the number of couple of naffaire/ncpte and the only parameter return with my query is the count (not the naffaire or the ncpte...), no matter the datas, i juste need to work with their occurences... well, now for the examle detail previously the query gives me RESULT OF TABLE WHERE THE QUERY THE QUERY IS DONE count(*) naffaire | ncpte 2 1 | 3 2 2 | 5 3 7 | 9 2 5 | 6 2 2 | 5 1 6 | 9 5 4 | 2 2 1 | 3 5 4 | 2 3 7 | 9 5 4 | 2 1 9 | 7 3 7 | 9 5 4 | 2 2 5 | 6 5 4 | 2 ... and 1 million lines like that... So i get a 2 dimension array with only one column and 1 million rows... the fact is what i need is to count the occurrences for each result in this array. So for the same example we would get : occurrence of 1 : 2 occurrence of 2 : 6 occurrence of 3 : 3 occurrence of 4 : null occurrence of 5 : 5 ... to do this in an array there's an easy and light way : array_count_values. the problem is that this function only works on the first dimension of the array. That s why i have to return my column of result into a line I did it with this loop: while($row = mysql_fetch_array($result)) { array_push($suite, $row["count(*)"]); } It works fine... of course and then i make the array count values on $suite and i get $suite[1] : 2 $suite[2] : 6 $suite[3] : 3 $suite[4] : unset $suite[5] : 5 (max length with a 1 million row table about 25 indexes, so this array should be quite small) Just to go to the very end of my need, even if its not useful: then i divide the values by their index (i gonna tell you what for) so the final result is : $suite[1] : 2 /1 > 2 $suite[2] : 6 /2 > 3 $suite[3] : 3 /3 > 1 $suite[4] : unset / $suite[5] : 5 /5 > 1 (as the previous array was small this one is too ;o)) Well you know everything : now it will be easier for me to tell you what i want to calculate : THE NUMBER OF COUPLES of naffaire/ncpte that have an occurence of 1, that have an occurrence of 2, of 3, of 4 so thereare only 2 long processes : the while loop (it won t be much shorter if i use a "for" loop) and the array_count_values (this one is a single instruction so i trust php developpers for the optimization of their code ;o) ) You will have understand my prob now : the very very big loss of time in my algorythm is the while loop... That s why i would like to do the same whithout using any kind of loop before the array_count_values, before this instruction, the arr
Re: [PHP-DB] how to reverse a hudge multidimensional array?
Bon soir Etienne, Like I say, "Inverting" an array is a chore, it's far easier to invert the pointers... but if you must do it:- For loop to control the first dimension using $i For loop to control the second dimension using $j $temp = $array[ $i ][ $j ]; $array[ $i ][ $j ] = $array[ $j ][ $i ]; $array[ $j ][ $i ] = $temp; Ok? =dn > thx a lot for your answer, > > in fact i only have to return one of the 15 datas, so it makes one column... > anyway, i already coded a solution with a while. My question was just to > know if it was possible to do it without repeating 100 times the same > processing. > > In fact i begin to believe that it is not possible to reverse the 2 > dimensions of an array... > > If you have a solution for me i m interested, even if it takes a lot of > processor ressources because i will have a dedicated server and there wont > be more than 30 users, not at the same time (that s for a stat intranet)... > just to correct my unprecision again, there will be 1M datas to process not > 15 because the array i ve to process is the result of my mysql query and > that this query will only return a single column of datas (count(*) ) > > Helll :) > > Etienne > > > - Original Message - > From: "DL Neil" <[EMAIL PROTECTED]> > To: "Etienne Durand" <[EMAIL PROTECTED]> > Cc: <[EMAIL PROTECTED]> > Sent: Thursday, January 31, 2002 10:44 AM > Subject: Re: [PHP-DB] how to reverse a hudge multidimensional array? > > > > Etienne, > > > > > Well i hope someone will be able to give me a solution... > > > Here s my problem: > > > I'm working with a hudge mysql table (about 15 columns and 100 > rows...) > > > > > > in fact i ve got to count the number of couples `ncompte`/`naffaire` in > the > > > table and finaly calculate the number of couples that appear once, > twice > > > > > > here is the query i do: > > > $result = mysql_query("SELECT count(*) FROM datas GROUP BY `ncompte`, > > > `naffaire`"); > > > > > > its result like something like this: > > > count(*) naffaire ncompte > > > 4 affaire1 compte1 > > > 4 affaire2 compte2 > > > 1 affaire3 compte3 > > > 2 affaire4 compte4 > > > 1 affaire5 compte5 > > > > > > (plus many more) > > > > > > > > > my final result should be: > > > $result[1] :2 > > > $result[2] :1 > > > $result[4] :2 > > > > > > I manage to do this quite easily but i use a while instruction... > > > > > > while($row = mysql_fetch_array($result)) { > > > array_push($suite, $row["count(*)"]); > > > } > > > > > > As my table is very long the while takes a lot of time to complete... > > > So my question is : Is there a solution to return my array as follow : > > > > > > 1 2 3 1 4 7 > > > 4 5 6 ===>>2 5 8 ??? > > > 7 8 9 3 6 9 > > > > > > It would allow me to not have to use this long long while > > > So if someone could telle me how to modify my query or what instructions > to > > > use to do that... > > > > > > =there are various functions in PHP to 'reverse' arrays, but I must > confess that I have never used them. > > Regardless, if there is one to suit your purpose, it will surely consume > CPU time to achieve the swap-over of > > 15M items. > > > > =your example "my final result should be:" talks of enumerated arrays, so > I shall assume this is the way you > > always use them. > > > > =you want to somehow achieve: > > array[1][1] = array [1][1]; > > array[1][2] = array [2][1]; > > array[1][3] = array [3][1]; > > etc > > (you know that you can't do the above, right!?) > > > > =thereafter the array would be processed by using a mechanism such as two > nested FOR loops to iterate through > > the row/column elements of the array, eg > > > > for ( i=1; i<15; i++ ); > > for ( j=1; j<100; j++ ); > > process( array[i][j] ); > > etc > > > > =can you leave the array where it is, and adjust the way the iterations > are managed? Instead of proceeding > > methodically by counting 'up', count 'down', eg > > > > for ( i=15; i>0; i-- ); > > for ( j=100; j>0; j-- ); > > process( array[i][j] ); > > etc > > > > =Regards, > > =dn > > > > > > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] how to reverse a hudge multidimensional array?
thx a lot for your answer, in fact i only have to return one of the 15 datas, so it makes one column... anyway, i already coded a solution with a while. My question was just to know if it was possible to do it without repeating 100 times the same processing. In fact i begin to believe that it is not possible to reverse the 2 dimensions of an array... If you have a solution for me i m interested, even if it takes a lot of processor ressources because i will have a dedicated server and there wont be more than 30 users, not at the same time (that s for a stat intranet)... just to correct my unprecision again, there will be 1M datas to process not 15 because the array i ve to process is the result of my mysql query and that this query will only return a single column of datas (count(*) ) Helll :) Etienne - Original Message - From: "DL Neil" <[EMAIL PROTECTED]> To: "Etienne Durand" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Thursday, January 31, 2002 10:44 AM Subject: Re: [PHP-DB] how to reverse a hudge multidimensional array? > Etienne, > > > Well i hope someone will be able to give me a solution... > > Here s my problem: > > I'm working with a hudge mysql table (about 15 columns and 100 rows...) > > > > in fact i ve got to count the number of couples `ncompte`/`naffaire` in the > > table and finaly calculate the number of couples that appear once, twice > > > > here is the query i do: > > $result = mysql_query("SELECT count(*) FROM datas GROUP BY `ncompte`, > > `naffaire`"); > > > > its result like something like this: > > count(*) naffaire ncompte > > 4 affaire1 compte1 > > 4 affaire2 compte2 > > 1 affaire3 compte3 > > 2 affaire4 compte4 > > 1 affaire5 compte5 > > > > (plus many more) > > > > > > my final result should be: > > $result[1] :2 > > $result[2] :1 > > $result[4] :2 > > > > I manage to do this quite easily but i use a while instruction... > > > > while($row = mysql_fetch_array($result)) { > > array_push($suite, $row["count(*)"]); > > } > > > > As my table is very long the while takes a lot of time to complete... > > So my question is : Is there a solution to return my array as follow : > > > > 1 2 3 1 4 7 > > 4 5 6 ===>>2 5 8 ??? > > 7 8 9 3 6 9 > > > > It would allow me to not have to use this long long while > > So if someone could telle me how to modify my query or what instructions to > > use to do that... > > > =there are various functions in PHP to 'reverse' arrays, but I must confess that I have never used them. > Regardless, if there is one to suit your purpose, it will surely consume CPU time to achieve the swap-over of > 15M items. > > =your example "my final result should be:" talks of enumerated arrays, so I shall assume this is the way you > always use them. > > =you want to somehow achieve: > array[1][1] = array [1][1]; > array[1][2] = array [2][1]; > array[1][3] = array [3][1]; > etc > (you know that you can't do the above, right!?) > > =thereafter the array would be processed by using a mechanism such as two nested FOR loops to iterate through > the row/column elements of the array, eg > > for ( i=1; i<15; i++ ); > for ( j=1; j<100; j++ ); > process( array[i][j] ); > etc > > =can you leave the array where it is, and adjust the way the iterations are managed? Instead of proceeding > methodically by counting 'up', count 'down', eg > > for ( i=15; i>0; i-- ); > for ( j=100; j>0; j-- ); > process( array[i][j] ); > etc > > =Regards, > =dn > > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Select statement only returns 1 record
It's worked for me. You'll note that I added a new column "id". Did you put that in your table?? What error did you get -Original Message- From: Todd Williamsen [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 30, 2002 2:18 PM To: 'Rick Emery'; [EMAIL PROTECTED] Subject: RE: [PHP-DB] Select statement only returns 1 record Nope, that doesn't work -Original Message- From: Rick Emery [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 30, 2002 1:01 PM To: 'Todd Williamsen'; [EMAIL PROTECTED] Subject: RE: [PHP-DB] Select statement only returns 1 record "; while( $row = mysql_fetch_array($result) ) { $FirstName = $row['FirstName']; $LastName = $row['LastName']; $id=$row['id']; print "$LastName, $FirstName"; } ?> print ""; -Original Message- From: Todd Williamsen [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 30, 2002 12:45 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Select statement only returns 1 record I am trying to get data from two columns, FirstName and Last name and displaying all the records LastName, FirstName in a drop down menu. The weird thing is that it only displays one record. I thought the table was hosed, but its not. I tried it through another database and still doesn't work. Here is the code: I would list the whole page but its long! There is another SQL statement at the top of the page: -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Select statement only returns 1 record
Nope, that doesn't work -Original Message- From: Rick Emery [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 30, 2002 1:01 PM To: 'Todd Williamsen'; [EMAIL PROTECTED] Subject: RE: [PHP-DB] Select statement only returns 1 record "; while( $row = mysql_fetch_array($result) ) { $FirstName = $row['FirstName']; $LastName = $row['LastName']; $id=$row['id']; print "$LastName, $FirstName"; } ?> print ""; -Original Message- From: Todd Williamsen [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 30, 2002 12:45 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Select statement only returns 1 record I am trying to get data from two columns, FirstName and Last name and displaying all the records LastName, FirstName in a drop down menu. The weird thing is that it only displays one record. I thought the table was hosed, but its not. I tried it through another database and still doesn't work. Here is the code: I would list the whole page but its long! There is another SQL statement at the top of the page: -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Help needed with php and db2
Good day all, I am new to php and lucky me my boss has asked me to do a 'proof of concept' with php against IBM DB2. Our DB2 database resides on an OS/390 system. I'm just trying to figure out at this point if php can actually connect to our database on the OS/390. I've read about ODBC connectivity to db2, but it was on an apache/linux system...not a mainframe or enterprise system. Any thoughts anyone might have as to where I should start or even if this can truely be done I would greatly appreciate. Thanks in advance! Stephanie Workman Sr. Programmer/Analyst The University of Tennessee (865)-974-8108
Re: [PHP-DB] Select statement only returns 1 record
You will need to put the option tag in a loop to get all of the records in the table. (this can go anywhere but in while loop) "; $i++; } ?> Also, without the value in the option tag, you will not be passing anything to the form. HTH Maureen Biorn Todd Williamsen <[EMAIL PROTECTED]> said: > I am trying to get data from two columns, FirstName and Last name and > displaying all the records LastName, FirstName in a drop down menu. > > The weird thing is that it only displays one record. I thought the table > was hosed, but its not. I tried it through another database and still > doesn't work. > > Here is the code: > > $db = mysql_connect($dbserver, $dbuser, $dbpass); > mysql_select_db($dbname,$db); > $sortby = "name ASC"; > $sql="SELECT * FROM webl_players ORDER BY $sortby"; > $result=mysql_query($sql,$db); > $row = mysql_fetch_array($result); > $FirstName = $row["FirstName"]; > $LastName = $row["LastName"]; > ?> > > > > > > > I would list the whole page but its long! There is another SQL statement at > the top of the page: > > > $db = mysql_connect($dbserver, $dbuser, $$dbpass); > mysql_select_db($dbname, $db); > $sql = "SELECT * FROM Canidate SORT BY 'LastName'"; > $result = mysql_query($sql); > ?> > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Select statement only returns 1 record
"; while( $row = mysql_fetch_array($result) ) { $FirstName = $row['FirstName']; $LastName = $row['LastName']; $id=$row['id']; print "$LastName, $FirstName"; } ?> print ""; -Original Message- From: Todd Williamsen [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 30, 2002 12:45 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Select statement only returns 1 record I am trying to get data from two columns, FirstName and Last name and displaying all the records LastName, FirstName in a drop down menu. The weird thing is that it only displays one record. I thought the table was hosed, but its not. I tried it through another database and still doesn't work. Here is the code: I would list the whole page but its long! There is another SQL statement at the top of the page: -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Select statement only returns 1 record
Check the manual for the mysql_fetch_array() function, it shows you how to extract data from $result. You will use the while loop (as shown in the manual's example) to fill your combo box / selct list /drop down menu, whatever we're calling that creature today. Miles At 12:45 PM 1/30/2002 -0600, Todd Williamsen wrote: >I am trying to get data from two columns, FirstName and Last name and >displaying all the records LastName, FirstName in a drop down menu. > >The weird thing is that it only displays one record. I thought the table >was hosed, but its not. I tried it through another database and still >doesn't work. > >Here is the code: > >$db = mysql_connect($dbserver, $dbuser, $dbpass); >mysql_select_db($dbname,$db); >$sortby = "name ASC"; >$sql="SELECT * FROM webl_players ORDER BY $sortby"; >$result=mysql_query($sql,$db); >$row = mysql_fetch_array($result); >$FirstName = $row["FirstName"]; >$LastName = $row["LastName"]; >?> > > > > > > >I would list the whole page but its long! There is another SQL statement at >the top of the page: > > >$db = mysql_connect($dbserver, $dbuser, $$dbpass); >mysql_select_db($dbname, $db); >$sql = "SELECT * FROM Canidate SORT BY 'LastName'"; >$result = mysql_query($sql); >?> > > > >-- >PHP Database Mailing List (http://www.php.net/) >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] >To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Select statement only returns 1 record
I am trying to get data from two columns, FirstName and Last name and displaying all the records LastName, FirstName in a drop down menu. The weird thing is that it only displays one record. I thought the table was hosed, but its not. I tried it through another database and still doesn't work. Here is the code: I would list the whole page but its long! There is another SQL statement at the top of the page: -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] newbie question: request & response
Does PHP have built-in support for using request and response objects? Thanks, -L -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] request and response objects?
see PHP's support of cURL / libcurl. it's do-able. > basically a yes or no question my brother wants me to ask: > Does PHP support these objects? If not, Can they be faked? > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: > [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] request and response objects?
basically a yes or no question my brother wants me to ask: Does PHP support these objects? If not, Can they be faked? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] MySQL Connection Class
Yes it does, thanks... now that I have a better understanding of classes now I just need to write one. Thanks again. jas "Gurhan Ozen" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Jas, > I can't know whether or not that's right for you. It all depends on what you > need to do.. If you only have one database connection with one userid/pass > combination, then yes it might be the solution you are looking for. But if > you want to be able to reuse your code for different types of databases, > userids, then you can write a class with different functions and variables > to do so. > For example you can something like > class myDBConnClass { > var $user; > var $pass; > var $host; > var $database; > >function setUser($username) >{ >$this -> user = $username; >} >function setPass($password) >{ >$this -> pass = $password; >} >function setHost($hostname) >{ > $this -> host = $hostname) >} >function setDatabasename($databasename) >{ > $this -> database= $databasename; >} > >function mySQLconn($username, $password, $hostname, $databasename) >{ > mysql_pconnect("$username", "$password", "$hostname"); > mysql_select_db($databasename); > } > function mySQL() > { > mysql_pconnect("($this -> host).", ".($this -> user).", > ".($this -> pass)." ); > mysql_select_db($this -> database); > } > . > . > . > . >} // end of class myDBConnClass > >Say you have saved this into myDBConnClass.php .. Then in your php pages > you would first require this file with require("myDBConnClass.php"); > statement, and then you would create another class extending this or just an > instance of this class (depending upon what you actually have in your class > and pages. > Keep in mind that this is a very primitive and kind of useless class.. You > can always have more properties of the class and more functions.. > If you prefer you can hardcode the login, databasename info to the class > and call the connection fucntions without arguments, or you can set the > variables of the class and use it so, you can also have more functions to > connect to the different databases (PostGreSQL, Oracle, etc.) . >Does this help??? > > Gurhan > -Original Message- > From: jas [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, January 30, 2002 12:33 AM > To: [EMAIL PROTECTED] > Subject: Re: [PHP-DB] MySQL Connection Class > > > So all I would need to do is create a file named db_connection.php3 and put > in the functions $db = mysql_connection("localhost","username","password") > or die("could not connect"); > and then put an include statement on the top of each page that needs the db > connectiong? Please correct me if I am wrong, I have never really used > class files for my own scripts before. > Thanks again. > "Gurhan Ozen" <[EMAIL PROTECTED]> wrote in message > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > Are you trying to write classes to connect to the database using PHP's > > native DB connection functions?? If yes, you should only check those > > database functions' tutorials and just use them inside your class.. > > > > Gurhan > > > > > > -Original Message- > > From: jas [mailto:[EMAIL PROTECTED]] > > Sent: Wednesday, January 30, 2002 12:09 AM > > To: [EMAIL PROTECTED] > > Subject: [PHP-DB] MySQL Connection Class > > > > > > I know this may seem a little vague but I would like to know where a good > > tutorial on creating database connection class files would be. I have > been > > looking and as of yet I have not found one that deals specifically with > this > > question. Thanks in advance. > > Jas > > > > > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] MySQL Connection Class
Jas, I can't know whether or not that's right for you. It all depends on what you need to do.. If you only have one database connection with one userid/pass combination, then yes it might be the solution you are looking for. But if you want to be able to reuse your code for different types of databases, userids, then you can write a class with different functions and variables to do so. For example you can something like class myDBConnClass { var $user; var $pass; var $host; var $database; function setUser($username) { $this -> user = $username; } function setPass($password) { $this -> pass = $password; } function setHost($hostname) { $this -> host = $hostname) } function setDatabasename($databasename) { $this -> database= $databasename; } function mySQLconn($username, $password, $hostname, $databasename) { mysql_pconnect("$username", "$password", "$hostname"); mysql_select_db($databasename); } function mySQL() { mysql_pconnect("($this -> host).", ".($this -> user).", ".($this -> pass)." ); mysql_select_db($this -> database); } . . . . } // end of class myDBConnClass Say you have saved this into myDBConnClass.php .. Then in your php pages you would first require this file with require("myDBConnClass.php"); statement, and then you would create another class extending this or just an instance of this class (depending upon what you actually have in your class and pages. Keep in mind that this is a very primitive and kind of useless class.. You can always have more properties of the class and more functions.. If you prefer you can hardcode the login, databasename info to the class and call the connection fucntions without arguments, or you can set the variables of the class and use it so, you can also have more functions to connect to the different databases (PostGreSQL, Oracle, etc.) . Does this help??? Gurhan -Original Message- From: jas [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 30, 2002 12:33 AM To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] MySQL Connection Class So all I would need to do is create a file named db_connection.php3 and put in the functions $db = mysql_connection("localhost","username","password") or die("could not connect"); and then put an include statement on the top of each page that needs the db connectiong? Please correct me if I am wrong, I have never really used class files for my own scripts before. Thanks again. "Gurhan Ozen" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Are you trying to write classes to connect to the database using PHP's > native DB connection functions?? If yes, you should only check those > database functions' tutorials and just use them inside your class.. > > Gurhan > > > -Original Message- > From: jas [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, January 30, 2002 12:09 AM > To: [EMAIL PROTECTED] > Subject: [PHP-DB] MySQL Connection Class > > > I know this may seem a little vague but I would like to know where a good > tutorial on creating database connection class files would be. I have been > looking and as of yet I have not found one that deals specifically with this > question. Thanks in advance. > Jas > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] MySQL Connection Class
Ok just to clear it up... our server is not running php4 unfortunately. =) "Dave Richardson" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > A number of connection classes and abstraction toolkits already exist. Your > PHP 4.x install probably came with PEAR's DB.php abstraction layer. Save > yourself the trouble perhaps? > > jas said: > > So all I would need to do is create a file named db_connection.php3 and > > put in the functions $db = > > mysql_connection("localhost","username","password") or die("could not > > connect"); > > and then put an include statement on the top of each page that needs > > the db connectiong? Please correct me if I am wrong, I have never > > really used class files for my own scripts before. > > Thanks again. > > "Gurhan Ozen" <[EMAIL PROTECTED]> wrote in message > > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > >> Are you trying to write classes to connect to the database using PHP's > >> native DB connection functions?? If yes, you should only check those > >> database functions' tutorials and just use them inside your class.. > >> > >> Gurhan > >> > >> > >> -Original Message- > >> From: jas [mailto:[EMAIL PROTECTED]] > >> Sent: Wednesday, January 30, 2002 12:09 AM > >> To: [EMAIL PROTECTED] > >> Subject: [PHP-DB] MySQL Connection Class > >> > >> > >> I know this may seem a little vague but I would like to know where a > >> good tutorial on creating database connection class files would be. I > >> have > > been > >> looking and as of yet I have not found one that deals specifically > >> with > > this > >> question. Thanks in advance. > >> Jas > >> > >> > >> > >> -- > >> PHP Database Mailing List (http://www.php.net/) > >> To unsubscribe, e-mail: [EMAIL PROTECTED] > >> For additional commands, e-mail: [EMAIL PROTECTED] > >> To contact the list administrators, e-mail: > >> [EMAIL PROTECTED] > >> > > > > > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: > > [EMAIL PROTECTED] > > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] MySQL Connection Class
A number of connection classes and abstraction toolkits already exist. Your PHP 4.x install probably came with PEAR's DB.php abstraction layer. Save yourself the trouble perhaps? jas said: > So all I would need to do is create a file named db_connection.php3 and > put in the functions $db = > mysql_connection("localhost","username","password") or die("could not > connect"); > and then put an include statement on the top of each page that needs > the db connectiong? Please correct me if I am wrong, I have never > really used class files for my own scripts before. > Thanks again. > "Gurhan Ozen" <[EMAIL PROTECTED]> wrote in message > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... >> Are you trying to write classes to connect to the database using PHP's >> native DB connection functions?? If yes, you should only check those >> database functions' tutorials and just use them inside your class.. >> >> Gurhan >> >> >> -Original Message- >> From: jas [mailto:[EMAIL PROTECTED]] >> Sent: Wednesday, January 30, 2002 12:09 AM >> To: [EMAIL PROTECTED] >> Subject: [PHP-DB] MySQL Connection Class >> >> >> I know this may seem a little vague but I would like to know where a >> good tutorial on creating database connection class files would be. I >> have > been >> looking and as of yet I have not found one that deals specifically >> with > this >> question. Thanks in advance. >> Jas >> >> >> >> -- >> PHP Database Mailing List (http://www.php.net/) >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> To contact the list administrators, e-mail: >> [EMAIL PROTECTED] >> > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: > [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] MySQL Connection Class
So all I would need to do is create a file named db_connection.php3 and put in the functions $db = mysql_connection("localhost","username","password") or die("could not connect"); and then put an include statement on the top of each page that needs the db connectiong? Please correct me if I am wrong, I have never really used class files for my own scripts before. Thanks again. "Gurhan Ozen" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Are you trying to write classes to connect to the database using PHP's > native DB connection functions?? If yes, you should only check those > database functions' tutorials and just use them inside your class.. > > Gurhan > > > -Original Message- > From: jas [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, January 30, 2002 12:09 AM > To: [EMAIL PROTECTED] > Subject: [PHP-DB] MySQL Connection Class > > > I know this may seem a little vague but I would like to know where a good > tutorial on creating database connection class files would be. I have been > looking and as of yet I have not found one that deals specifically with this > question. Thanks in advance. > Jas > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] MySQL Connection Class
Are you trying to write classes to connect to the database using PHP's native DB connection functions?? If yes, you should only check those database functions' tutorials and just use them inside your class.. Gurhan -Original Message- From: jas [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 30, 2002 12:09 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] MySQL Connection Class I know this may seem a little vague but I would like to know where a good tutorial on creating database connection class files would be. I have been looking and as of yet I have not found one that deals specifically with this question. Thanks in advance. Jas -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Date operations.
Gary, You have a right to be confused - this problem is short but it is about as complex as they get. Still I have a solution for you, also short and you'll (hopefully) find it elegant. I found it interesting... The thing is we will create a Cartesian product on purpose - this is something they tell people learning SQL to avoid (and usually they are not helpful) but here it is the only to get a daily average since you don't have daily records of your pairs just a start and stop date. I was looking at the problem from the child point of view in my first post (easier since children only have a single birthday). I'll use your problem now. We will keep the DateTable and use your 'breeding' table but I will change the 'paired' and 'split' columns to int (you don't need to do this but it will make thing easier - some DBMS's will always put a time stamp in a Date field and this does screw thing up - it makes it harder to join on them). So we have: breeding --- rec SMALLINT PRIMARY KEY sire SMALLINT dam SMALLINT pairedINT split INT num_offspring INT And DateTable dayID INT PRIMARY KEY myDate DATE month INT yearINT quarter INT /* and as discussed any other date related columns */ > I need to count how many pairs were breeding > on a given day, and then average over the month. OK - fasten you seat belt :-0 SELECT count(*), myDate FROM breeding, DateTable WHERE paired >= dayID AND split <= dayID AND month = 2 AND year = 2001 GROUP BY myDay ORDER BY myDay /* you could have just as easily used a start and stop date */ /* myDay >= "2/1/2001" and myDate < "3/1/2001" */ This will give you output something like this (the total per day): 5 Feb 1, 2001 5 Feb 2, 2001 5 Feb 3, 2001 5 Feb 4, 2001 5 Feb 5, 2001 6 Feb 6, 2001 6 Feb 7, 2001 6 Feb 8, 2001 6 Feb 9, 2001 6 Feb 10, 2001 6 Feb 11, 2001 ... And so on ... To get the average per month I'd use a temporary table (a table you create just for this report or that is always there but empty except during this report) /* start with an empty table */ CREATE TABLE TotalByDay ( total INT, dayID INT) /* --- or --- */ TRUNCATE TABLE TotalByDay /* now fill it... */ /* notice it the same SQL but I've gone back to */ /* dayID (the INT) not the full date and I've done */ /* the whole year so we can average per month */ INSERT INTO TotalByDay SELECT count(*), dayID FROM breeding, DateTable WHERE paired >= dayID AND split <= dayID AND year = 2001 GROUP BY dayID ORDER BY dayID /* OK almost there ... Now to average by month */ SELECT ave(total), month, year FROM TotalByDay, DateTable WHERE TotalByDay.dayID = DateTable.dayID GROUP BY month ORDER BY month Now you've got output like 5 1 2001 6 2 2001 6 3 2001 7 4 2001 12 5 2001 11 6 2001 11 7 2001 7 8 2001 7 9 2001 9 10 2001 9 11 2001 9 12 2001 >From here you convert the month INT back into a name. Feel free to writ back with any questions (it's headdy stuff) also I don't have a mySQL db handy to check the syntax against - hopefully I've remembered everything correctly. The concept is sound, we do this all the time. The "got ya's" are the DateTable must be full (don't fill it to the end of this year and forget about it - next year your reports will be wrong) Frank > > Ouch, I'm getting a bit lost. I need to count how many pairs were breeding > on a given day, and then average over the month. Playing with mysql I get > for say the 1st day of the year: > > select count(*) from breeding > where TO_DAYS(paired) <= TO_DAYS('2002-1-1') > AND TO_DAYS('2002-1-1') <= TO_DAYS(split); > > That will give me the number of pairs breeding that day. Then I would have > to loop through the year and keep track of number of pairs, days of months > etc to get the monthly averages. > > Can you suggest a DateTable format that could help me? The start and end > dates for the query would be input via a form. The granularity would be > one month, but the details need to be averaged on a daily basis. > > Regards, > Garry. > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] MySQL Connection Class
I know this may seem a little vague but I would like to know where a good tutorial on creating database connection class files would be. I have been looking and as of yet I have not found one that deals specifically with this question. Thanks in advance. Jas -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] same connection to access two different database?
Vincent, If you need to use just one connection against multiple databases, you should check out Virtuoso. Among other features it can act as a "virtual database", where you link multiple heterogenous database tables through it and then can treat them as one transparent schema from a single ODBC connection. The databases you link can be on different platforms as well. You can combine remote data with data in Virtuoso's own tables, and do some interesting things like create XML documents on the fly from any combination of your relational data. http://www.openlinksw.com/virtuoso/whatis.htm Best regards, Andrew Hill Director of Technology Evangelism OpenLink Software http://www.openlinksw.com Universal Data Access & Data Integration Technology Providers > -Original Message- > From: Vincent Ma [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, January 29, 2002 8:46 PM > To: [EMAIL PROTECTED] > Subject: [PHP-DB] same connection to access two different database? > > > Hi everyone: > > is it possible to use one connect to access two database in postgreq, > because i would like to use subquery to do same search. on the fly in > postgreq must faster a lot than evaluate in php code... > > A, B belong to different database... > sql : select * from A in ( select * B) > > Vincent Ma > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Drop down list
First conect to DB $result=mysql($DBname,"SELECT * FROM table"; print ""; while( list($artist_id,$name) = mysql_fetch_array($result) ) { print "$name\n"; } print ""; -Original Message- From: Julius Dlugolinsky [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 30, 2002 8:48 AM Cc: Php-DB Subject: RE: [PHP-DB] Drop down list First conect to DB $result=mysql($DBname,"SELECT * FROM table where 1"); $no=mysql_numrows($result); $i=0; $string=""; while ($i<$no){ $string.="".mysql_result($result,$i,"arti st").""; $i++;} $string="$string"; and in string is drop down menu. EXO (www.exo.sk) > > -Original Message- > > From: B.J.Rumsey [mailto:[EMAIL PROTECTED]] > > Sent: 30. tammikuuta 2002 10:18 > > To: php-db > > Subject: [PHP-DB] Drop down list > > > > > > I have two fields artist_id, artist. How do I put the contents of > > "artist" into a dropdown list. > > > > > > > > IncrediMail - Email has finally evolved - Click Here > > > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: > > [EMAIL PROTECTED] > > > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] odbc_columns()
Scott, odbc_columns can take a lot of arguments, but the only one you need to pass is a connection id. It'll return a result identifier containing lots of info on your field names: $conn_id = odbc_connect($dsn, $usr, $pwd) or die (odbc_error()); $result_id = odbc_columns($conn_id) or die (odbc_error()); odbc_result_all($result_id); Best regards, Andrew Hill Director of Technology Evangelism OpenLink Software http://www.openlinksw.com Universal Data Access & Data Integration Technology Providers > -Original Message- > From: Scott Teglasi [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, January 29, 2002 9:01 PM > To: [EMAIL PROTECTED] > Subject: [PHP-DB] odbc_columns() > > > Hi. Have a question: > > I've tried using the odbc_columns() function to get a list of > columns in an > access database connected via an ODBC System DSN.. However, I haven't had > much luck in trying to use it. The manual page doesn't really cover much > about it, and I noticed a few comments posted there (on www.php.net) > mentioning that it was a pretty badly documented function. > > In any case, there were notes on how to use it with MS SQL 7, but none on > just plain access databases. > > All I want to get is a list of field names in a table. What would the > proper syntax be to do that? > > Any help would be appreciated. > > Thanks, > > Scotty > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Drop down list
First conect to DB $result=mysql($DBname,"SELECT * FROM table where 1"); $no=mysql_numrows($result); $i=0; $string=""; while ($i<$no){ $string.="".mysql_result($result,$i,"artist").""; $i++;} $string="$string"; and in string is drop down menu. EXO (www.exo.sk) > > -Original Message- > > From: B.J.Rumsey [mailto:[EMAIL PROTECTED]] > > Sent: 30. tammikuuta 2002 10:18 > > To: php-db > > Subject: [PHP-DB] Drop down list > > > > > > I have two fields artist_id, artist. How do I put the contents of > > "artist" into a dropdown list. > > > > > > > > IncrediMail - Email has finally evolved - Click Here > > > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: > > [EMAIL PROTECTED] > > > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Connect to DB2-win2k through PHP4-Linux
Hi, I have a windows 2000 Database Server with IBM DB2 V7.2 on it. I have a Web Server with Linux-Apache-PHP 4 on it (but not XWindow or any graphical interface...). On the web server, I want to run a PHP page to connect to the IBM DB2 Database on the win2k server. 1.> Do I need to install DB2 Client / DB2 Administration Client / DB2 Development Client on the Linux server ? I currently only installed DB2 Client. 2.> After compiling PHP with option --with-ibm-db2=/usr/IBMdb2/V7.1 (I know it's V7.2, but my colleague who did the install believed it was 7.1), can use the PHP command odbc_connect ? When I tried I received the error: "Fatal error: Call to undefined function: odbc_connect()"... 3.> I didn't have any directory sqllib (like on windows platform) after IBM DB2 Client installation, is it normal ? 3.> Do I need to install another software like iODBC ? Thanks. Jerry -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Drop down list
I'm not allowed to answer arguments pointed to me? This is my way of dealing with newbies, and this is what I've learned to be the most powerfull way to really learn how to do things. If you don't like it - fine - handle them how you like. Niklas -Original Message- From: Piotrek [mailto:[EMAIL PROTECTED]] Sent: 30. tammikuuta 2002 14:36 To: [EMAIL PROTECTED]; Php-DB Subject: Re: [PHP-DB] Drop down list OK. Someone else has already answered the question, so you could shut up and stop teaching us all how to deal with newbies. This way you'll help "in a way" - Original Message - From: "Niklas Lampén" <[EMAIL PROTECTED]> To: "Php-DB" <[EMAIL PROTECTED]> Sent: Wednesday, January 30, 2002 12:52 PM Subject: RE: [PHP-DB] Drop down list Well, true. :) There is a but: I think it's stupid to try to get the solution from others while the information is very easy to find by reading the manual. This issue is about _very_ basic stuff. If you do not know how to loop your query result, what in earth can you do with it? This is my point, I don't expect anyone to know everything about SQL, I don't. And I do think that I did help in a way, I told this guy what he should do in case he didn't have any idea where to begin. So he only had to take the manual and read about query, how to loop it and HTML he should know. Or again, read some tutorial about it. Niklas -Original Message- From: George Lioumis [mailto:[EMAIL PROTECTED]] Sent: 30. tammikuuta 2002 11:50 To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Drop down list I think you should be more polite with newbies. If you don't want to help someone, just don't answer. - Original Message - From: "Niklas Lampén" <[EMAIL PROTECTED]> To: "Php-DB" <[EMAIL PROTECTED]> Sent: Wednesday, January 30, 2002 10:33 AM Subject: RE: [PHP-DB] Drop down list > 1. Do query > 2. Loop thru query results and write HTML for dropdown > > I think you should know atleast the basics of SQL + HTML before asking > stuff here. There are whole lot of tutorials around the net. > > > Niklas > > > -Original Message- > From: B.J.Rumsey [mailto:[EMAIL PROTECTED]] > Sent: 30. tammikuuta 2002 10:18 > To: php-db > Subject: [PHP-DB] Drop down list > > > I have two fields artist_id, artist. How do I put the contents of > "artist" into a dropdown list. > > > > IncrediMail - Email has finally evolved - Click Here > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: > [EMAIL PROTECTED] > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Drop down list
OK. Someone else has already answered the question, so you could shut up and stop teaching us all how to deal with newbies. This way you'll help "in a way" - Original Message - From: "Niklas Lampén" <[EMAIL PROTECTED]> To: "Php-DB" <[EMAIL PROTECTED]> Sent: Wednesday, January 30, 2002 12:52 PM Subject: RE: [PHP-DB] Drop down list Well, true. :) There is a but: I think it's stupid to try to get the solution from others while the information is very easy to find by reading the manual. This issue is about _very_ basic stuff. If you do not know how to loop your query result, what in earth can you do with it? This is my point, I don't expect anyone to know everything about SQL, I don't. And I do think that I did help in a way, I told this guy what he should do in case he didn't have any idea where to begin. So he only had to take the manual and read about query, how to loop it and HTML he should know. Or again, read some tutorial about it. Niklas -Original Message- From: George Lioumis [mailto:[EMAIL PROTECTED]] Sent: 30. tammikuuta 2002 11:50 To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Drop down list I think you should be more polite with newbies. If you don't want to help someone, just don't answer. - Original Message - From: "Niklas Lampén" <[EMAIL PROTECTED]> To: "Php-DB" <[EMAIL PROTECTED]> Sent: Wednesday, January 30, 2002 10:33 AM Subject: RE: [PHP-DB] Drop down list > 1. Do query > 2. Loop thru query results and write HTML for dropdown > > I think you should know atleast the basics of SQL + HTML before asking > stuff here. There are whole lot of tutorials around the net. > > > Niklas > > > -Original Message- > From: B.J.Rumsey [mailto:[EMAIL PROTECTED]] > Sent: 30. tammikuuta 2002 10:18 > To: php-db > Subject: [PHP-DB] Drop down list > > > I have two fields artist_id, artist. How do I put the contents of > "artist" into a dropdown list. > > > > IncrediMail - Email has finally evolved - Click Here > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: > [EMAIL PROTECTED] > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Drop down list
Well, true. :) There is a but: I think it's stupid to try to get the solution from others while the information is very easy to find by reading the manual. This issue is about _very_ basic stuff. If you do not know how to loop your query result, what in earth can you do with it? This is my point, I don't expect anyone to know everything about SQL, I don't. And I do think that I did help in a way, I told this guy what he should do in case he didn't have any idea where to begin. So he only had to take the manual and read about query, how to loop it and HTML he should know. Or again, read some tutorial about it. Niklas -Original Message- From: George Lioumis [mailto:[EMAIL PROTECTED]] Sent: 30. tammikuuta 2002 11:50 To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Drop down list I think you should be more polite with newbies. If you don't want to help someone, just don't answer. - Original Message - From: "Niklas Lampén" <[EMAIL PROTECTED]> To: "Php-DB" <[EMAIL PROTECTED]> Sent: Wednesday, January 30, 2002 10:33 AM Subject: RE: [PHP-DB] Drop down list > 1. Do query > 2. Loop thru query results and write HTML for dropdown > > I think you should know atleast the basics of SQL + HTML before asking > stuff here. There are whole lot of tutorials around the net. > > > Niklas > > > -Original Message- > From: B.J.Rumsey [mailto:[EMAIL PROTECTED]] > Sent: 30. tammikuuta 2002 10:18 > To: php-db > Subject: [PHP-DB] Drop down list > > > I have two fields artist_id, artist. How do I put the contents of > "artist" into a dropdown list. > > > > IncrediMail - Email has finally evolved - Click Here > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: > [EMAIL PROTECTED] > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Date operations.
Garry, > > > CREATE TABLE breeding ( > > > rec SMALLINT(4) UNSIGNED AUTO_INCREMENT, > > > sire SMALLINT(4) UNSIGNED, > > > dam SMALLINT(4) UNSIGNED, > > > paired DATE, > > > split DATE, > > > num_offspring TINYINT(1) ZEROFILL, > > > PRIMARY KEY (rec) > > > ); > > > > > > First, we define if a pair was breeding for a given date by seeing if that > > > date lies between the paired date and the split date. In mysql: > > > SELECT FROM breeding WHERE TO_DAYS(paired) <= TO_DAYS('$given_date') AND > > > TO_DAYS('$given_date') <= TO_DAYS(split); =This seems part of the problem (as well as part of the solution). Procedural logic suggests that we should iterate through the days of the month, taking note of the facts, and then perform the statistical calculation at the end. Relational logic doesn't work like this, it requires us to process through the data in the table(s). This table is not organised by date, indeed it notes periods of time, which are notoriously problematic to sort into a 'date order'! However all is not lost... > > There is no need to use TO_DAYS() because paired and split are both > > dates so you can operate on them directly. I recommend that you take a > > look at the manual's section on Time and Date Functions. > You are right. I works without the TO_DAYS(). But I did get them from the > manual :-) =thanks for the note. It's difficult to know whether to risk insulting someone by saying "RTFM"! =ironically I think you're going to end up right back there, but other functions of interest may include Month, MonthName, Extract, Date_Sub, and even Timestamp. =general advice would be to define the dates in PHP (with MySQL in mind), but keep all the date processing in MySQL (if at all possible). > > > Where it gets messy is this has to be put into a loop, between the given > > > start and end dates (year and month only). For each day in the loop, I > > > have to do a query and count the number returned to php. Then average that > > > figure for the month. > > So if I understand correctly, you are thinking in terms of a 'result > > table' which would (ideally) have the days 1-28/29/30/31 in the > > left-hand column, and the number of pairs who were put together on > > that day (paired <= day/date <= split). Then at the bottom you want to > > sum the right-hand column and divide it by the number of days in the > > month to give some sort of average mating possibilities per day. Does > > that sound right? > Basically for statistical reasons I need average pairs per month, just a > single number. But the months/years to be queried on would be input via a > form. I was thinking of generating the data on-the-fly, but as you suggest > above and from something Frank Flynn suggested, I would be better off > having a separate table with monthly results. They could all be > pre-calculated except the current month. =I noted Frank's suggestion. Obviously no one wants to duplicate 'the calendar' unnecessarily, but by having a calendar table, it does open up the possibility of processing through that table (from start-date to end-date) and using relational logic to extract (date) 'related' rows from the breeding tbl. In many ways, when I have finished, you will recognise that there is some attraction to that approach! =You may have missed one of the points that I was making: what is the math behind this calculation? I'm going to set up some sample data/an approach, but only talk about a 'week' rather than a 'month' for brevity/ease of comprehension... So if we have breeding pairs A through E, the breeding tbl (representative) looks like: sire dam paired split Am Af Mon Fri Bm Bf Tue Thu Cm Cf Tue Fri Dm Df history Sun Em Ef Sat future where m=male, f=female, and we're only interested in the period Mon-Fri, so rows D and E are included only to show exclusion (yes, that last clause does make logical sense...I think - they're included only so that they can be excluded!) =Our first thought is to think in terms of say "Monday", and to scan the breeding tbl to count how many pairs were breeding that day, and make a note of the count; then move to "Tuesday" and do the same; finally summing and averaging. =Thus 'temporal logic' (working one day at a time) says: Mon = 1 pair Tue = 3 pairs Wed = 3 pairs Thu = 3 pairs Fri = 2 pairs Sum = 12 nDays = 5 Avg = 2.5 =Now, crucial question: have I understood the logic of the computation correctly? I shall blythly carry on regardless... =Ok, so now we're in a quandry because constructing a SQL statement to look at Monday, the Tuesday, ... is not possible - enter Frank (trumpet calls offstage, left). =However there's more than one way to skin a cat, and according to my (admittedly not fantastic) math ability, we could arrive at the same numbers by coming at things the other way around! Let's count the number of days for which a pair were breeding: A = 5 B = 3 C = 4 D = ? E =
Fw: [PHP-DB] Drop down list
- Original Message - From: George Lioumis To: B.J.Rumsey Sent: Wednesday, January 30, 2002 11:47 AM Subject: Re: [PHP-DB] Drop down list Try the following: "; $res = mysql_query($get_list) or die (mysql_error()); while ($row = mysql_fetch_array($res)) { $artid= $row["artist_id"]; $art = $row["artist"]; $option_block .= "$art"; } ?> - Original Message - From: B.J.Rumsey To: php-db Sent: Wednesday, January 30, 2002 10:17 AM Subject: [PHP-DB] Drop down list I have two fields artist_id, artist. How do I put the contents of "artist" into a dropdown list. IncrediMail - Email has finally evolved - Click Here
Re: [PHP-DB] RE: ensuring unique field value in MySQL using PHP
Dl Neil wrote: > > Janet, > > MySQL (and indeed all multi-user databases) has a feature called "Locking". What >this means is that whilst many > users/clients may access a database, apparently simultaneously, when one (or more) >is updating the data in some > way, everyone else is kept locked-out for the duration. Hopefully the period of time >required is so short that > other users don't particularly notice. > > For example, let's say we have a joint bank account. The bank db will maintain a >balance figure (say 100). If > I'm at one branch of the bank and ask for the balance, it will be given. If at the >exact same moment in time, > you are at another branch, the SAME number will also be given to you. Now let's get >complicated. Having worked > out that there is some money, let's say I raid the piggy-bank and ask for 75. The >bank computer will say 100 > less 75 leaves a balance of 25 and the teller will give me my loot. However if >again, at exactly the same point > in time) you try to withdraw (a more modest, caring and sharing) 50. If your >teller's computer reported a > balance of 100, and you got the 50, and the balance was updated to 50, what would >happen? I don't know about > you, but I don't often get the better of banks... Strangely enough, in database >theory this is called the > "banker's problem". > > So, when two tellers ask to update an account balance, only one will be given the >'lock' - the other will be > momentarily 'locked out'. MySQL is responsible for this timing/choice. (it's one of >the "management" parts of > "DBMS") The other user/computer is locked out, and in certain situations can figure >that out. So what happens > next is that your teller does not subtract 50 from 100, but subtracts 50 from the >remaining balance, eg > UPDATE...SET balance = balance - 50 WHERE a/c nr=... (not SET balance = 100 - 50 ) >at which point in time you > get embarrassed by the teller, and I get into REALLY hot water! > > I have really quick reactions: at the first sign of trouble I run away! > > So yes it is possible that two of your clients will press 'submit' at the same >moment in time, but when the > processing scripts hit the database, the RDBMS will using a 'lock' to prioritise >(even inventing a priority if > necessary) one over the other without any intervention from you. You have nothing to >worry about (until you let > me operate your bank account). > > Incidentally the 'level' at which a lock is applied varies from DBMS to DBMS. MySQL >'only' has table-level > locking. This means no one else can use a table whilst one user is updating. >Depending upon transaction > rates/response time requirements, the mix of transactions in the system, and the >size of the table(s); this > might be a problem (eg for our mythical bank). Other DBMS' allow locking right down >to the row level. However > locking takes time, and so imposes a speed penalty. MySQL is built for speed, >doesn't pay a high 'penalty', and > in this way gets away with higher level/more widely imposed locking. There is no one >'correct' answer to this > conundrum despite the widespread criticism/fear (or even FUD) - everybody's mileage >may vary! > Don't mean to be picky just to make it a little clearer. Not all database systems lock others from reading a row when updating occurs. Eg. Postgresql, Interbase, Oracle won't stop you from reading a row while it is being updated. Even Sybase and SAPdb can bet set to not to lock readers in certain situations.(Isolation level 0) I understand even Innodb 's MYsql tables allow reading when a row is locked and being updated. MYsql's big lack of features makes it easy to use I suppose. With other databases you would need to carefully choose the correct Isolation Level for the situation. > Does that help to clear things up? > =dn > snip > > -Original Message- > > From: Janet Valade [mailto:[EMAIL PROTECTED]] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] how to reverse a hudge multidimensional array?
Etienne, > Well i hope someone will be able to give me a solution... > Here s my problem: > I'm working with a hudge mysql table (about 15 columns and 100 rows...) > > in fact i ve got to count the number of couples `ncompte`/`naffaire` in the > table and finaly calculate the number of couples that appear once, twice > > here is the query i do: > $result = mysql_query("SELECT count(*) FROM datas GROUP BY `ncompte`, > `naffaire`"); > > its result like something like this: > count(*) naffaire ncompte > 4 affaire1 compte1 > 4 affaire2 compte2 > 1 affaire3 compte3 > 2 affaire4 compte4 > 1 affaire5 compte5 > > (plus many more) > > > my final result should be: > $result[1] :2 > $result[2] :1 > $result[4] :2 > > I manage to do this quite easily but i use a while instruction... > > while($row = mysql_fetch_array($result)) { > array_push($suite, $row["count(*)"]); > } > > As my table is very long the while takes a lot of time to complete... > So my question is : Is there a solution to return my array as follow : > > 1 2 3 1 4 7 > 4 5 6 ===>>2 5 8 ??? > 7 8 9 3 6 9 > > It would allow me to not have to use this long long while > So if someone could telle me how to modify my query or what instructions to > use to do that... =there are various functions in PHP to 'reverse' arrays, but I must confess that I have never used them. Regardless, if there is one to suit your purpose, it will surely consume CPU time to achieve the swap-over of 15M items. =your example "my final result should be:" talks of enumerated arrays, so I shall assume this is the way you always use them. =you want to somehow achieve: array[1][1] = array [1][1]; array[1][2] = array [2][1]; array[1][3] = array [3][1]; etc (you know that you can't do the above, right!?) =thereafter the array would be processed by using a mechanism such as two nested FOR loops to iterate through the row/column elements of the array, eg for ( i=1; i<15; i++ ); for ( j=1; j<100; j++ ); process( array[i][j] ); etc =can you leave the array where it is, and adjust the way the iterations are managed? Instead of proceeding methodically by counting 'up', count 'down', eg for ( i=15; i>0; i-- ); for ( j=100; j>0; j-- ); process( array[i][j] ); etc =Regards, =dn -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Drop down list
1. Do query 2. Loop thru query results and write HTML for dropdown I think you should know atleast the basics of SQL + HTML before asking stuff here. There are whole lot of tutorials around the net. Niklas -Original Message- From: B.J.Rumsey [mailto:[EMAIL PROTECTED]] Sent: 30. tammikuuta 2002 10:18 To: php-db Subject: [PHP-DB] Drop down list I have two fields artist_id, artist. How do I put the contents of "artist" into a dropdown list. IncrediMail - Email has finally evolved - Click Here -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Drop down list
I have two fields artist_id, artist. How do I put the contents of "artist" into a dropdown list. IncrediMail - Email has finally evolved - Click Here