RE: [PHP-DB] preg_math vs preg_match_all
For those perl fans out there, preg_match_all adds the g (global) flag to the expression. So this: preg_match('/foo/', $str, $match); would be like $str =~ /foo/; preg_match_all('/foo/', $str, $match); like $str =~ /foo/g; - Russ p.s. - anyone coming from Perl to PHP can get a little hung up on the preg_* functions... -Mensaje original- De: Gerard Samuel [mailto:[EMAIL PROTECTED] Enviado el: Tuesday, November 23, 2004 2:37 PM Para: Yemi Obembe CC: [EMAIL PROTECTED] Asunto: Re: [PHP-DB] preg_math vs preg_match_all Yemi Obembe wrote: Just want to know the difference between preg_match and preg_match_all. preg_match stops after the first match. preg_match_all gets *all* the matches. E.g. If you have a string - $str = foofoo; preg_match('/foo/', $str, $match); - $match will have an array with one foo. preg_match_all('/foo/', $str, $match); - $match will have an array with two foo. Thats basically it. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: array messing up
Rainer Bendig Aka Ny wrote: I want to build an array containing two arrays $navm[] and $navs[], $navs[] should go to $navm[items]. - -sourcecode:start8-- $resultm = $db-query(SELECT * FROM .$p._cats WHERE ms='m' \ ORDER BY sortorder ASC); while($work_res_navm = $db-fetch_array($resultm)) { $results = $db-query(SELECT * FROM .$p._cats \ WHERE master='.$work_res_navm['catid'].' \ ORDER BY sortorder ASC); $navs = array(); while($work_res_navs = $db-fetch_array($results)) { $navs[]=array('link'=$work_res_navs['link'], \ 'text'= $work_res_navs['name'], \ 'id'= $work_res_navs['catid'], \ 'master'=$work_res_navs['master'] ); } $navm[] =array('link'=$work_res_navm['link'], \ 'text'= $work_res_navm['name'], \ 'id'= $work_res_navm['catid'], \ 'items'=$navs); }; - -sourcecode:stop-8-- the array now looks like this: $navm1-0 $navs1-1 $navs1-2 $navm2-0 $navs1-1 $navs1-2 $navs2-1 $navm3-0 $navs1-1 $navs1-2 $navs2-1 $navs3-1 and the same procedure a lot more often... but it should look like this: $navm1-0 $navs1-1 $navs1-2 $navm2-0 $navs2-1 $navm3-0 $navs3-1 and so on what is my error? you forget to empty the array $navs! -- Sebastian Mendel www.sebastianmendel.de www.warzonez.de www.tekkno4u.de www.nofetish.com www.sf.net/projects/phpdatetimewww.sf.net/projects/phptimesheet -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Using a loop on a result destroys array??
On Wednesday 24 November 2004 20:31, Mark Benson wrote: From the above code, Actually the above code would result in a parse error. There are no where-loops in PHP but there are while-loops. This is not being pedantic. If you're going to post code, make sure it's verbatim by using copy and paste your actual code. You want people to focus on your real problem and not on the mistakes you made in transcribing your actual code into your post. loop 2 returns a blank array, the output is simply Array (). If I remove the loop (by commentiung it out) that extracts $crab the mysql $result array is suddenly full of the correct values. It seems to me that loop 1 is destroying or somehow not resetting $result. Very odd... mysql_data_seek() is what you need. Or you can consider storing the results into an array the first time round then you can read results from the array whenever next you need it. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-db -- /* Business is a good game -- lots of competition and minimum of rules. You keep score with money. -- Nolan Bushnell, founder of Atari */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Using a loop on a result destroys array??
The real problem you're having is the statement says while there are results in this query, grab them - once you reach the end of the first while loop, there are no more results, so the second one is skipped right over - it's condition *never* evaluates true. If the query isn't changing, and there aren't other conditions/etc. - then just grab all the data the first time through and put it where it needs to go. $array_stuff = array(); $line = 0; while (mysql_fetch_array($result) as $row1) { // data for first set of operation(s) $crab = $row1[bar]; // data for second set of operation(s) $array_stuff[$line] = array() $array_stuff[$line][foo] = $row1[foo]; $array_stuff[$line][bar] = print $row1[bar]; $array_stuff[$line][steak] = print $row1[steak]; // increment $line? // $line++; } ... You'll want to be incrementing $line somewhere though, unless you just want to keep overwriting $array_stuff[0] Another solution to this type of problem is to just read all the information into an array, then loop through that when you need it. E.G. $resultset = array(); while (mysql_fetch_array($result) as $row) { $resultset[] = $row; } Then just foreach ($resultset as $row) { // or ($resultset as $rownum = $row) // ... do stuff } Happy hunting. - Martin Norland, Database / Web Developer, International Outreach x3257 The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Using a loop on a result destroys array??
On Wednesday 24 November 2004 20:31, Mark Benson wrote: From the above code, Actually the above code would result in a parse error. There are no where-loops in PHP but there are while-loops. This is not being pedantic. If you're going to post code, make sure it's verbatim by using copy and paste your actual code. I cannot possibly do this as I am working on a commercially sensitive project and am instructed by my managing bodies not to quote actual code in case it contains sensetive data. Sorry if that is not how you like it but that is how I have to work. I can understand it must be frustrating for experienced members but alas I'm tied, I try my best... You want people to focus on your real problem and not on the mistakes you made in transcribing your actual code into your post. I actually write (rather badly it would seem!) theoretical examples that would (or in this case wouldn't!!) end in the same situation as the problem in my code (as I see it). loop 2 returns a blank array, the output is simply Array (). If I remove the loop (by commentiung it out) that extracts $crab the mysql $result array is suddenly full of the correct values. It seems to me that loop 1 is destroying or somehow not resetting $result. Very odd... mysql_data_seek() is what you need. Or you can consider storing the results into an array the first time round then you can read results from the array whenever next you need it. Thanks I'll try that. -- Mark Benson http://homepage.mac.com/markbenson -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Using a loop on a result destroys array??
On Wednesday, November 24, 2004, at 02:40PM, Norland, Martin [EMAIL PROTECTED] wrote: The real problem you're having is the statement says while there are results in this query, grab them - once you reach the end of the first while loop, there are no more results, so the second one is skipped right over - it's condition *never* evaluates true. So by running a while (mysql_fetch_array($result) loop over a fetch array you effectively empty it? If the query isn't changing, and there aren't other conditions/etc. - then just grab all the data the first time through and put it where it needs to go. OK, sounds like a plan... Sorry (again) about the code gaffs :-S -- Mark Benson http://homepage.mac.com/markbenson -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Using a loop on a result destroys array??
-Original Message- From: Mark Benson [mailto:[EMAIL PROTECTED] The real problem you're having is the statement says while there are results in this query, grab them - once you reach the end of the first while loop, there are no more results, so the second one is skipped right over - it's condition *never* evaluates true. So by running a while (mysql_fetch_array($result) loop over a fetch array you effectively empty it? snip Well, not really - although in the end, yes, it will be 'empty' - mysql_fetch_array actually fetches a single row (the next one, if available) returned from the mysql query into an associative array. You're being handed the data from mysql, one row at a time as requested, and sticking it into an array. $result is actually the resource id that you give mysql so it knows what query to give you the information back from. - Martin Norland, Database / Web Developer, International Outreach x3257 The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Using a loop on a result destroys array??
On Wednesday 24 November 2004 23:02, Mark Benson wrote: You want people to focus on your real problem and not on the mistakes you made in transcribing your actual code into your post. I actually write (rather badly it would seem!) theoretical examples Please don't construct theoretical examples. that would (or in this case wouldn't!!) end in the same situation as the problem in my code (as I see it). It's hard enough writing code that works without having to mess around with writing theorectical code that: doesn't work in the exactly the same fashion as another piece of code Construct a stripped-down, bare-bones, *working* example that illustrates your problem. (Working in the sense that it is free from syntax and other errors that are not the focus of the problem). -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-db -- /* Teachers have class. */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] how to implement pages of results
Hi, I'm sure this is a common question, so please forgive if it's been posted before. I have a select statement that selects records from a table: select * from $table where host='$somename' I then propagate a table with the returned data. My goal is to only display 30 records per page, with links on each page that take the user to the next and previous 30 records. I have played around with using limit, but this seems to only get me the next 30. How to achieve the previous 30? It would be easy if the records returned were sequentially numbered...but, since I'm being selective in which records I return (host=$somename), this is not the case. The first row may be 1, and the second row may be 10, etc. Anyone have any ideas on how to solve this? Thanks! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] how to implement pages of results
Basic example: (handwritten in email client, syntax errors may exist) if (!isset($pagenum) || $pagenum 0) { $pagenum = 0; } $range = 30; $start = $range*$pagenum; $end = $start + $range; $limit = limit $start, $end; $query = select * from $table where host='$somename'$limit; Then just pass the pagenum around. You'll probably want to pull another query that just gets the count(), and use that and some basic math to make the page range(s) to create hyperlinks. Cheers. - Martin Norland, Database / Web Developer, International Outreach x3257 The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Wednesday, November 24, 2004 2:20 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] how to implement pages of results Hi, I'm sure this is a common question, so please forgive if it's been posted before. I have a select statement that selects records from a table: select * from $table where host='$somename' I then propagate a table with the returned data. My goal is to only display 30 records per page, with links on each page that take the user to the next and previous 30 records. I have played around with using limit, but this seems to only get me the next 30. How to achieve the previous 30? It would be easy if the records returned were sequentially numbered...but, since I'm being selective in which records I return (host=$somename), this is not the case. The first row may be 1, and the second row may be 10, etc. Anyone have any ideas on how to solve this? Thanks! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] how to implement pages of results
Off the top of my head, doesn't LIMIT accept two paramters? Can't you do: LIMIT 30,2 That'd give you page 2 of a 30+ record result set, right? Using that, you can pass a page # when you click next page so previous page ends up being current page - 1 (and if that is less than 1, then it equals 1... And if it's recordcount / 30 + 1, then it equals recordcount / 30 + 1) Try working checking into that. -TG -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Wednesday, November 24, 2004 3:20 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] how to implement pages of results Hi, I'm sure this is a common question, so please forgive if it's been posted before. I have a select statement that selects records from a table: select * from $table where host='$somename' I then propagate a table with the returned data. My goal is to only display 30 records per page, with links on each page that take the user to the next and previous 30 records. I have played around with using limit, but this seems to only get me the next 30. How to achieve the previous 30? It would be easy if the records returned were sequentially numbered...but, since I'm being selective in which records I return (host=$somename), this is not the case. The first row may be 1, and the second row may be 10, etc. Anyone have any ideas on how to solve this? Thanks! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] how to implement pages of results
Correct - LIMIT 30,2 would show 2 records starting with the thirtieth. thirty-first. Sheesh, I should get outta here too - ^airhead^ - Martin Norland, Database / Web Developer, International Outreach x3257 The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Update Query with special conditions.
I am curious about doing something simular to this... does anyone have an idea On Wed, 24 Nov 2004 00:43:32 -0500, list 123. list wrote: Using mySQL 4.0, I would like to know how I can code a query that will change the value of Participants.Active from Y to N is for three or more CONSECUTIVE sessions they have Attendance.Present = 'No'? The Attendance Table has Attendance.Session which coresponds to Sessions.SessionID and Attendance.Participant coresponds to Participants.Part_ID; To assist, I have shown you the data of the Sessions and the descriptions of Attendance, Participants, Attendance Thanks G mysql describe Participants; +---+---+--+-+-++ | Field | Type | Null | Key | Default | Extra | +---+---+--+-+-++ | Part_ID | smallint(10) unsigned | | PRI | NULL| auto_increment | | LastName | varchar(30) | | PRI | || | FirstName | varchar(30) | | PRI | || | DOB | date | YES | | NULL|| | Sex | enum('M','F') | | | M || | Phone1| varchar(12) | | MUL | || | Phone2| varchar(12) | YES | | NULL|| | Notes | text | | | || | Facesheet | enum('Have','Need') | | | Need|| | Active| set('Y','N') | | | Y || +---+---+--+-+-++ 10 rows in set (0.00 sec) mysql describe Attendance; +-+--+--+-+-++ | Field | Type | Null | Key | Default | Extra | +-+--+--+-+-++ | AttID | int(4) | | PRI | NULL| auto_increment | | Session | int(2) | | MUL | 0 || | Participant | int(2) | | | 0 || | Present | enum('Yes','No') | | | Yes || +-+--+--+-+-++ 4 rows in set (0.00 sec) mysql describe Sessions; +-+-+--+-+++ | Field | Type| Null | Key | Default| Extra | +-+-+--+-+++ | SessionID | int(2) unsigned | | PRI | NULL | auto_increment | | SessionDate | date| | PRI | -00-00 || +-+-+--+-+++ 2 rows in set (0.03 sec) mysql select * from Sessions; +---+-+ | SessionID | SessionDate | +---+-+ | 1 | 2004-10-30 | | 2 | 2004-11-06 | | 3 | 2004-11-13 | | 4 | 2004-11-20 | | 5 | 2004-12-04 | | 6 | 2004-12-11 | | 7 | 2005-01-08 | | 8 | -00-00 | | 9 | 2005-01-29 | |10 | 2005-02-05 | |11 | 2005-02-12 | |12 | 2005-02-26 | |13 | 2005-03-05 | |14 | 2005-03-12 | |15 | 2005-03-19 | |16 | 2005-04-02 | |17 | 2005-04-09 | |18 | 2005-04-16 | |19 | 2005-04-23 | |20 | 2005-05-07 | |21 | 2005-05-14 | |22 | 2005-05-21 | +---+-+ 22 rows in set (0.05 sec) +-+ | Tables_in_AHRC | +-+ | Attendance | | Participants| | ProgressNotes | | Sessions| | Staff | | StaffAttendance | +-+ 6 rows in set (0.00 sec) -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Using a loop on a result destroys array??
On Thu, 25 Nov 2004 01:36, Mark Benson wrote: On Wednesday, November 24, 2004, at 02:40PM, Norland, Martin [EMAIL PROTECTED] wrote: The real problem you're having is the statement says while there are results in this query, grab them - once you reach the end of the first while loop, there are no more results, so the second one is skipped right over - it's condition *never* evaluates true. So by running a while (mysql_fetch_array($result) loop over a fetch array you effectively empty it? Not really. What is happening is that each time you get a row from the result set, an internal pointer is advanced to the next row; if the final row has been requested, the pointer points to 'nowhere' and can't be further advanced without resetting it to the first row. Cheers -- David Robley I won't finish in fifth place, Tom held forth. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Cisco UBR interface with PHP
On Friday 19 November 2004 07:53, Doug Finch wrote: I have an idea that I wanted to throw out there. I have a cable ISP plant that I am trying to help with a project. They are using Cisco 7114 UBRs to connect their cable modems with their Internet backbone - this device assigns it a dhcp address and associates it with the modems MAC address. It does a lot more than that but that is all I am concerned with. I want to see if I can write a script that will constantly execute the command show ip arp which will return the current routing table with the MAC and IP address (dhcp). I can foresee two problems so far, one is that you have to have enable mode access to run this function and two, I would fear creating a security loophole by running an enabled function all of the time. Can I get your thoughts on this? wouldn't something like Perl Expect work wonders here?? you could combine it with a mysql db if the details are to be stored for later viewing. -Z thanks, Doug -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php