RE: [PHP] Re: Editing files by line

2002-07-16 Thread Onaje Johnston

-Original Message-
From: Analysis & Solutions
Sent: Tuesday, July 16, 2002 4:40 PM
To: PHP List
Subject: Re: [PHP] Re: Editing files by line

On Tue, Jul 16, 2002 at 04:25:25PM -0400, Onaje Johnston wrote:
>>
>> if ($insert && $linenumber) {

>But, if $linenumber is 0, this process won't happen.  And, that was the
>complaint you mentioned up front.
>
>So, you should do an "isset($linenumber)" instead.

>--Dan

Thanks.

It works using "if ($insert && isset($linenumber)) {".

So because the value of linenumber is 0 on the first line, the if statement
was evaluating to false and therefore the update wouldn't occur, correct?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: Editing files by line

2002-07-16 Thread Onaje Johnston

-Original Message-
>From: Analysis & Solutions

>Without seeing the script, it'd be hard for us to say.  So, post the
>_relevant parts_ of the script to the list.

Here's the code:

I'm sorry, but I couldn't open a file!";
exit;
  }

$array = file($file_name);

  // this is the stuff we get from the form, we insert it into an array
$input = array ($id, $name, $creator, $myreview, $prefix, $directory,
$sort, $comments);

  // note that we add a \n (line break) to the end of the string.
$output_line = implode ($input, "|")."\n";

  // Now open the file (get a file pointer)
$output_stream = fopen($file_name, "w+");

$counter = 0;
  foreach($array as $key => $line) {
if($counter == $linenumber) {
$line = $output_line;
}
$out[] = chop($line);
$counter++;
}

foreach($out as $key => $line) {
$result=fputs($output_stream, $line."\n");
}

// close the file pointer
fclose($output_stream);

  // give feedback
if ($result) {
  echo "Data has been sucessfully added.\n";
  echo "View updated
record";
}
  else {
echo "Uhoh. . . the database didn't like that.";
  }

}else{
// Viewing data from file in a form
//to read the file use:
$fp2= fopen("data.txt", "r");

$line_cnt=0;

while ($servinfo=fgets($fp2,1024)){

if ($line_cnt == $line_num){
$right_line = $servinfo;
list($id, $name, $creator, $myreview, $prefix, $directory, $sort,
$comments)= explode("|",$right_line);
break;
   }
   $line_cnt++;
}
fclose($fp2);
?>



Racestyle data settings:)
Race ID:

Racestyle Name:

Creator:

MyReview:

Race Prefix

Race Directory:

Sort:

>small case
>Upper Case

Comments:






  
  




The data.txt file has this format:
5|8|4|2|7|2|ship_names|
2|3|7|2|1|9|ship_names_2L|7
4|3|2|7|5|6|ship_names|3

The default line_num is 0. The other entries - database3.php?line_num=1,
database3.php?line_num=2 etc.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: Editing files by line

2002-07-15 Thread Onaje Johnston

-Original Message-
From: Analysis & Solutions
Sent: Friday, July 12, 2002 9:57 AM
To: PHP List
Subject: Re: [PHP] Re: Editing files by line

>Unfortunately, if a file is opened for appending via fopen('name', 'a'),
>the manual says the data is put at the end of the file regardless of using
>fseek().
>
> --Dan
I've written a script that edits a specific line in a text file and saves
the changes to the file for that specific line. I've noticed though that I
can't edit the first line in the file, which would be zero in the array
created by the file() function. When I write the edited data back to the
file I am using "w+" as the mode.

Is this related to the array or to the file mode?

-- Onaje Johnston


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: compare arrays problem

2001-02-19 Thread Onaje Johnston

Thank you Tim and Richard. With your help I was able to figure out how to
get this script working as I intended.
Here's the code, in case anyone wants to do something similar in the future.
:-))

$pages=mysql_query("SELECT CP.page_id, pagename FROM cluster_pagetbl as CP,
pagetbl WHERE 
CP.cluster_id = '$id' AND CP.page_id=pagetbl.page_id order by page_id");

$pgids= array();

if (mysql_Numrows($pages)>0) {

$prows=mysql_NumRows($pages);
$i=0;
while ($i<$prows){
 
//figure out how to get page ids into array
$pid= mysql_result($pages,$i, page_id);
$pagename =mysql_result($pages, $i, pagename);
 
 $pgids[$pid] = $pagename;

$i++;
}
}

//prints what is in the pgid array. 
foreach($pgids as $pid => $pagename){
 print $pid.' => '.$pagename.'';
}

$query2=mysql_query("select page_id, pagename FROM 
pagetbl order by page_id");

$mpgids= array();

if (mysql_Numrows($query2)>0) {

$numrows=mysql_NumRows($query2);
$x=0;
while ($x<$numrows){

$mpid=mysql_result($query2,$x, page_id);
$mpagename=mysql_result($query2,$x, pagename);

$mpgids[$mpid] = $mpagename;   
  
$x++;
}
}

//prints the checkboxes, compares pgids and mgids array
foreach ($mpgids as $mpid => $mpagename){
print ''.$mpagename;
}

//double check to see what values are in both arrays, then print it.
$diff = array_intersect($mpgids,$pgids);

foreach ($diff as $element){
print ''.$element.'';}



-- 
PHP General 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] compare arrays problem

2001-02-17 Thread Onaje Johnston

I am hoping that someone really understands arrays reads this and can tell
me why the following isn't working as I expect it to. I've been trying for
days to get it to work. 

$pages=mysql_query("SELECT CP.page_id, pagename FROM cluster_pagetbl as CP,
pagetbl WHERE 
CP.cluster_id = '$id' AND CP.page_id=pagetbl.page_id order by page_id");

/*
SQL Result for $id=1:
page_id pagename 
 1   breakingnews  
 3   weather  
*/
 
if (mysql_Numrows($pages)>0) {

$prows=mysql_NumRows($pages);
$i=0;
while ($i<$prows){
 
//figure out how to get page ids into array
$pid= mysql_result($pages,$i, page_id);
$pagename =mysql_result($pages, $i, pagename);
 
 $pgids= array("$pid" => "$pagename");

foreach($pgids as $pid => $pagename){
 print $pid.' => '.$pagename.'';
}

/* prints:
1 => breakingnews
3 => weather

At this point the correct number of values appear to be in the pgids array
*/

$i++;
}
}

$query2=mysql_query("select page_id, pagename FROM 
pagetbl order by page_id");

/*
SQL Result:
page_id pagename 
 1   breakingnews  
 2   pastnews  
 3   weather 
*/

if (mysql_Numrows($query2)>0) {

$numrows=mysql_NumRows($query2);
$x=0;
while ($x<$numrows){

$mpid=mysql_result($query2,$x, page_id);
$mpagename=mysql_result($query2,$x, pagename);

$mpgids= array("$mpid" => "$mpagename");   
  
foreach ($mpgids as $mpid => $mpagename){
print ''.$mpagename;
}

// prints out three checkboxes, since that's the total number of pages
present
//but only the third checkbox (weather) gets checked, the first one should
be checked also

$x++;
}
}

//I used the array intersect function to doublecheck what is going on and it
finds only weather also
//What is happening to the first value?

$diff = array_intersect($mpgids,$pgids);

foreach ($diff as $element){
print ''.$element.'';} 
 
//prints: weather



-- 
PHP General 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] include problem using windows

2001-01-09 Thread Onaje Johnston

I've setup apache 1.3.14 with php 4.0.4. I'm getting an error when trying to
include/require files. 

Failed opening 'tcalendar2.inc' for inclusion (include_path='./') in
c:/apache/htdocs/caltest2.phtml 

I tried changing the include path in php.ini to 'c:/Apache/htdocs' to
'c:\Apache\htdocs' to '.' etc. I still get the error. 

Is this a php bug or is it something that I have to fix in apache?



-- 
PHP General 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]