[PHP] Searching a file
Hi, I have a file that looks like this: #gc: Ian eth0,1000,1100,1200,1300,1400 eth1,10,100,200 eth2,3000,3100,3200,3300 Okay, the numbers after the ethx are not static, there can be more and there can be less depending on what the user selects. Now my problem, I have a list of numbers that they can choose using checkboxes, and I now want the checkboxes to be ticked if the number+ethx appear in the file. How would I go about reading the file and then finding out if the number+ethx are there ? I have tried something like this: [code] $file=file("/ian/testing.file");//Load the file into array unset($file[0]);//Remove the first #gc line foreach($file as $line){// Run through each array line $array[]=explode(",", $line); //Separate each line in key/variable. } [/code] This gives me an output something like this (Dont take note of numbers, they change per user: Array ( [0] => Array ( [0] => eth0 [1] => 1100 [2] => 1200 [3] => 1300 ) [1] => Array ( [0] => eth1 [1] => 1100 [2] => 1200 [3] => 1300 ) [2] => Array ( [0] => eth2 [1] => 40 [2] => 50 [3] => 60 ) ) Okay, now for the difficult part. I run a global foreach($eth as $whatever) to run through each eth and then another foreach loop within that to determine the numbers for each eth. Great, that works no problem. Now when it comes to the part of comparing that the eth+number are in the same array (to determine wether the checkbox must be ticked or not) I cant figure out how todo it. I have tried various options like. [code] foreach($file as $line){ if((in_array("1100", $line)) and (in_array("eth0", $line))){ echo "Found eth0 and 1100 in array. Checkbox can be checked"; }else{ echo "Not found"; } } [/code] Now obviously, the first line should be returned as true, as eth0 and 1000 are in the same array. But it doesnt. It returns false the whole time. The problem is that the ethx+number must be in the SAME array not only in the whole global array, otherwise checkboxes that show up ticked are actually not going to be in the file. Oh the page where you select is layed out something like the diagram below. (Note there can be more numbers per ethx these are just examples. eth0 1000[] 1100[] 1200[] 1300[] 1400[] 6000[] 6500[] 2300[] eth1 40 [] 50 [] 60 [] 1000[] eth2 1100[] 1200[] 1300[] I hope I have not confused you now, please ask if something isnt clear. Thanks a million for the help. Ian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Mysql Problem
Hi, I am generating a mysql statement and then printing it to a formatted field. Here is my code: $sql="SELECT * from tablename where name in ('Web','HTML','PHP') group by name; $mysql_rslt1 = mysql_query($sql, $mysql_bconn) or die ("Could not get data"); while ($rec1 = mysql_fetch_array ($mysql_rslt1)) { echo "some stuff here"; } Now the problem is it will leave out the last line of the reply. So it would leave out the 'PHP' line for the query above. Always the last line, and if for some reason i only have 1 in my query, it displays nothing, although if I do it manually using the mysql prompt, it works fine, and i get back the info I want. All the other lines format properly and the info is correct, just the last line doesnt display. Any ideas ? Ian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Mysql Problem
Hi, Yes that was my mistake. But even with the code, it still doesnt display the last one. If i didnt put a " it wouldnt work at all. Thanks, Ian -Original Message- From: Torsten Roehr [mailto:[EMAIL PROTECTED] Sent: 28 May 2004 13:56 To: [EMAIL PROTECTED] Subject: [PHP] Re: Mysql Problem "Ian Barnes" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > > I am generating a mysql statement and then printing it to a formatted field. > Here is my code: > > $sql="SELECT * from tablename where name in ('Web','HTML','PHP') group by > name; You are missing the closing quote here! Please set your error reporting to E_ALL while developing: ini_set('error_reporting', E_ALL); Regards, Torsten Roehr > $mysql_rslt1 = mysql_query($sql, $mysql_bconn) > or die ("Could not get data"); > while ($rec1 = mysql_fetch_array ($mysql_rslt1)) { > echo "some stuff here"; > } > > Now the problem is it will leave out the last line of the reply. So it would > leave out the 'PHP' line for the query above. Always the last line, and if > for some reason i only have 1 in my query, it displays nothing, although if > I do it manually using the mysql prompt, it works fine, and i get back the > info I want. All the other lines format properly and the info is correct, > just the last line doesnt display. > > Any ideas ? > > Ian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Odd error after upgrading from Php4 to Php5
Hi, We recently upgraded our primary webserver to php 5 from php4 and we are now getting the following errors on the site: *Catchable fatal error*: Object of class stdClass could not be converted to string in /home/www/somesite/somfile.php on line *199 *Around that area in the code is some code something like: if(!$db->query("SQL QUERY HERE")) { echo 'Fail'; } Any ideas what it means or how I can fix it ? Thanks Ian P.S. Please copy me, i dont know if my list membership is working.
Re: [PHP] Odd error after upgrading from Php4 to Php5
Hi, $sql1 = "UPDATE members SET $pass WHERE id = '$editid'"; Thats whats on 199. ON line 198 i have: $pass = $_POST['pass']; Thanks, Ian On 11/29/06, Jochem Maas <[EMAIL PROTECTED]> wrote: Ian Barnes wrote: > Hi, > > We recently upgraded our primary webserver to php 5 from php4 and we are > now > getting the following errors on the site: > > *Catchable fatal error*: Object of class stdClass could not be converted to > string in /home/www/somesite/somfile.php on line *199 > > *Around that area in the code is some code something like: so what is line 199? > > if(!$db->query("SQL $HaveYouGoTAVarInHere HERE")) ?? > { > echo 'Fail'; > } > > Any ideas what it means or how I can fix it ? > > Thanks > Ian > > P.S. Please copy me, i dont know if my list membership is working. >
[PHP] Help with Class
Hi, I am writing a site where I need to access multiple classes of the same name located under certain directories. The reason for each directory is because the class under that directory talks only to the files in that directory and cant do multiple (its not my software) I have it so that I choose which ones I want to "post" to via checkboxes. I then do a foreach loop and here it is: foreach ( $forums as $num=>$val ) { $db = new db ( 'localhost' , 'user' , 'pass' , 'db' ); $sql = 'SELECT * FROM table WHERE id = "'.$val.'"'; $result = $db->get($sql); $fetchd = mysql_fetch_array ( $result ); $forumid = $fetchd['forumid']; $posterid = $fetchd['posterid']; $title = $_POST['title']; $desc = $_POST['desc']; $post = $_POST['post']; require_once ( $fetchd['path'].'sdk/ipbsdk_class.inc.php' ); $SDK =& new ipbsdk; $info = $SDK -> get_info ( $posterid ); $postername = $info['name']; echo "Forum ID:".$forumid; echo "Title:".$title; echo "Desc:".$desc; echo "Post:".$post; echo "PosterID:".$posterid; echo "PosterName:".$postername; echo ""; } See at the end of that foreach loop I need to unset the class $SDK so I can re-init it from another dir. How can I do this? I have tried some of the following: Unset ( $SDK); Unset ($GLOBALS['SDK'] ); Can anyone shed any light on my predicament ? Thanks in advance Cheers Ian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Help with Class
Hi, Thanks for the help, but none of those worked. Anyone else got any suggestions? Or possibly another way of achieving this ? Cheers Ian _ From: Jason Davidson [mailto:[EMAIL PROTECTED] Sent: 07 September 2005 05:47 PM To: Ian Barnes Cc: PHP General Subject: Re: [PHP] Help with Class I would have guessed unset($sqk); to work, but also try $sdk = null; Jason On 9/7/05, Ian Barnes <[EMAIL PROTECTED]> wrote: Hi, I am writing a site where I need to access multiple classes of the same name located under certain directories. The reason for each directory is because the class under that directory talks only to the files in that directory and cant do multiple (its not my software) I have it so that I choose which ones I want to "post" to via checkboxes. I then do a foreach loop and here it is: foreach ( $forums as $num=>$val ) { $db = new db ( 'localhost' , 'user' , 'pass' , 'db' ); $sql = 'SELECT * FROM table WHERE id = "'.$val.'"'; $result = $db->get($sql); $fetchd = mysql_fetch_array ( $result ); $forumid = $fetchd['forumid']; $posterid = $fetchd['posterid']; $title = $_POST['title']; $desc = $_POST['desc']; $post = $_POST['post']; require_once ( $fetchd['path'].'sdk/ipbsdk_class.inc.php' ); $SDK =& new ipbsdk; $info = $SDK -> get_info ( $posterid ); $postername = $info['name']; echo "Forum ID:".$forumid; echo "Title:".$title; echo "Desc:".$desc; echo "Post:".$post; echo "PosterID:".$posterid; echo "PosterName:".$postername; echo ""; } See at the end of that foreach loop I need to unset the class $SDK so I can re-init it from another dir. How can I do this? I have tried some of the following: Unset ( $SDK); Unset ($GLOBALS['SDK'] ); Can anyone shed any light on my predicament ? Thanks in advance Cheers Ian -- PHP General Mailing List ( http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Help with Class
Hi, Thanks for the help, but none of those worked. Anyone else got any suggestions? Or possibly another way of achieving this ? Cheers Ian _ From: Jason Davidson [mailto:[EMAIL PROTECTED] Sent: 07 September 2005 05:47 PM To: Ian Barnes Cc: PHP General Subject: Re: [PHP] Help with Class I would have guessed unset($sqk); to work, but also try $sdk = null; Jason On 9/7/05, Ian Barnes <[EMAIL PROTECTED]> wrote: Hi, I am writing a site where I need to access multiple classes of the same name located under certain directories. The reason for each directory is because the class under that directory talks only to the files in that directory and cant do multiple (its not my software) I have it so that I choose which ones I want to "post" to via checkboxes. I then do a foreach loop and here it is: foreach ( $forums as $num=>$val ) { $db = new db ( 'localhost' , 'user' , 'pass' , 'db' ); $sql = 'SELECT * FROM table WHERE id = "'.$val.'"'; $result = $db->get($sql); $fetchd = mysql_fetch_array ( $result ); $forumid = $fetchd['forumid']; $posterid = $fetchd['posterid']; $title = $_POST['title']; $desc = $_POST['desc']; $post = $_POST['post']; require_once ( $fetchd['path'].'sdk/ipbsdk_class.inc.php' ); $SDK =& new ipbsdk; $info = $SDK -> get_info ( $posterid ); $postername = $info['name']; echo "Forum ID:".$forumid; echo "Title:".$title; echo "Desc:".$desc; echo "Post:".$post; echo "PosterID:".$posterid; echo "PosterName:".$postername; echo ""; } See at the end of that foreach loop I need to unset the class $SDK so I can re-init it from another dir. How can I do this? I have tried some of the following: Unset ( $SDK); Unset ($GLOBALS['SDK'] ); Can anyone shed any light on my predicament ? Thanks in advance Cheers Ian -- PHP General Mailing List ( http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Help with Class
Hi Thomas, Thanks for the help. That didn't work though ... Its now set to be $SDK = new sdk; Nothing :( -Original Message- From: Thomas [mailto:[EMAIL PROTECTED] Sent: 08 September 2005 09:08 AM To: 'Ian Barnes' Subject: RE: [PHP] Help with Class Sorry for not explaining ... [code]$SDK =& new ipbsdk;[/code] initializes the $SDK variable as a reference of the class ipbsdk. The '&' operator is called the reference operator. So by leaving it out you copy (the default initialization) the resulting class object. Maybe that does the trick. T -----Original Message- From: Ian Barnes [mailto:[EMAIL PROTECTED] Sent: 08 September 2005 08:52 AM To: 'Thomas' Subject: RE: [PHP] Help with Class Sorry for the stupid question. How do I init the class as a copy not a reference ? -Original Message- From: Thomas [mailto:[EMAIL PROTECTED] Sent: 08 September 2005 08:25 AM To: 'Ian Barnes' Subject: RE: [PHP] Help with Class Hmm, that is strange because OO tells us that by nulling an object you destroy it. I don't see what the other person could have done to avoid the destruction of his class ... (that would be above my head) One more thing I would try (which you have not done yet) is to initialize the class as a copy and not a reference. That should not impair your code much because you are creating a new one ever time anyway. > think it cant be done That would somehow go against my understanding of OO programming ;-) ... Good luck. Thomas -Original Message- From: Ian Barnes [mailto:[EMAIL PROTECTED] Sent: 08 September 2005 08:07 AM To: 'Thomas' Subject: RE: [PHP] Help with Class Hi, I put the db object in there temporarily because the SDK class resets it and I haven't gotten round to changing it yet. I tried initing $SDK to null at the start but that hasn't worked either. The class that I initing isn't mine, it was written by someone else and they don't allow for multiple directories. The first run in the foreach loop runs perfectly, I get all the info back I need, so its just when the loop runs again. Here is my current code with all options I have tried: foreach ( $forums as $num=>$val ) { $SDK=null; $sdk = null; $db = new db ( 'localhost' , 'user' , 'pass' , 'db' ); $sql = 'SELECT * FROM vaults WHERE id = "'.$val.'"'; $result = $db->get($sql); $fetchd = mysql_fetch_array ( $result ); $forumid = $fetchd['forumid']; $posterid = $fetchd['posterid']; $title = $_POST['title']; $desc = $_POST['desc']; $post = $_POST['post']; require_once ( $fetchd['path'].'sdk/ipbsdk_class.inc.php' ); $SDK =& new ipbsdk; $info = $SDK -> get_info ( $posterid ); $postername = $info['name']; echo "Forum ID:".$forumid; echo "Title:".$title; echo "Desc:".$desc; echo "Post:".$post; echo "PosterID:".$posterid; echo "PosterName:".$postername; echo ""; // if ($SDK -> new_topic($forumid, $title, $desc, $post, $posterid, $postername)) { // echo 'Topic Created!'; // } else { // echo $SDK->sdk_error(); // } unset ( $sdk ); $SDK = null; unset ( $SDK ); $sdk = null; unset ( $GLOBALS['SDK']); unset ( $GLOBALS['sdk'] ) ; $GLOBALS['SDK'] = null; $GLOBALS['sdk'] = null; $_SESSION['sdk'] = null; $_SESSION['SDK'] = null; unset ( $_SESSION['SDK'] ); unset ( $_SESSION['sdk'] ); register_shutdown_function($SDK); register_shutdown_function($sdk); } So as you can see, I have tried a lot of things and im starting to think it cant be done, in which case ill just have to take the other persons class and either modify it (which is against his terms) or take what he does and do it manually myself. Thanks for the help. Ian -Original Message- From: Thomas [mailto:[EMAIL PROTECTED] Sent: 08 September 2005 07:54 AM To: 'Ian Barnes' Subject: RE: [PHP] Help with Class First up, I am not sure if you need to create a new db object every single loop, as far as I can see you can easily leave that outside the loop (unless you connect to a different db on each loop). Maybe you could initialize the $SDK variable on top of your loop with null ($SDK=null;) that way ever loop will serve you up with a 'nulled' $SDK variable. Does your current code not initialize the correct classes? T -----Original Message- From: Ian Barnes [mailto:[EMAIL PROTECTED] Sent: 08
RE: [PHP] Help with Class
Hi Ryan, I am including a different class.inc.php file each time the foreach loops. Each one sits in a different dir. Yes, I do get that error. My understanding of OOP is that I could null the $sdk variable and re-init it when the loop starts again.. Cheers -Original Message- From: Ryan Creaser [mailto:[EMAIL PROTECTED] Sent: 09 September 2005 12:34 AM To: Ian Barnes Cc: PHP General Subject: Re: [PHP] Help with Class Ian Barnes wrote: >require_once ( >$fetchd['path'].'sdk/ipbsdk_class.inc.php' ); > > What is the above line doing? It looks like you are trying to redeclare the ipbsdk class each time around the loop which is illegal in php. You can't do : class ipbsdk { ... } and then (in the same request) class ipbsdk { ... } because the names will clash. This should cause a "Fatal error: Cannot redeclare class ipbsdk ..." message though. Are you seeing any errors? - Ryan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Database Class Help
Hi, We have a database class that we want to use to connect to multiple databases at the same time using different variables. Here is part of the db class: class db { var $dbh = ""; var $q = ""; function db($db_host, $db_user, $db_pass, $db_name) { $this->dbh = @mysql_pconnect($db_host, $db_user, $db_pass); $this->select_db($db_name); } function select_db($db) { if ([EMAIL PROTECTED]($db, $this->dbh)) { die("Cannot select database because:\n" . mysql_error() . ""); } } function num_rows($_q) { if (!$this->q = mysql_query($_q, $this->dbh)) { die("Invalid query \"" . $_q . "\"\n" . mysql_error() . ""); } else { return mysql_num_rows($this->q); } @mysql_free_result($this->q); } } In my php file I say something like num_rows('select * from table1'); Echo $db_2->num_rows('select * from table2'); ?> Now that happens is when I try and do the query for db1, I get told that db2.table1 doesn't exist. I can swop anything around and it doesn't seem to work for one of the classes. Does anyone have any idea as to why this is happening? Thanks a lot, Ian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php