RE: [PHP] looping through a database

2008-06-17 Thread Ford, Mike
On 16 June 2008 21:58, Richard Kurth advised:

 I am looping through a database of files that are numbers 1 through 10
 if  number 1 is in the database I what to print out the first table
 below if it is not then print the else section below. Then
 loop through
 the database to see if 2 through 10 are there and do the same thing.
Of
 course what I am doing does not work. Should I move it all to
 an array
 and then loop through it. Or use a foreach loop.
 Could you please give me an idea where to start looking
 
 while($row=mysql_fetch_array($sql_result)){
 
 if ($row[number]==1) {
 tr
 td File 1/td
 tdThis is the file/td
 tdDelete/td
 /tr
 }else{
 tr
 tdFile1/td
 td/td
 tdAdd/td
 /tr
 }
 
 }

Well, first of you need a few ?php ? tags to make this legal:

  if ($row[number]==1) {
  ?
  tr
  td File 1/td
  tdThis is the file/td
  tdDelete/td
  /tr
  ?php
  }else{
  ?
  tr
  tdFile1/td
  td/td
  tdAdd/td
  /tr
  ?php
  }
  
  }

Of course, some people frown on this and prefer other techniques such as
echo-ing the HTML, or assembling it into a variable which gets echoed at
the end -- but whatever floats your boat...!!

Cheers!

Mike

 --
Mike Ford,  Electronic Information Developer,
C507, Leeds Metropolitan University, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 812 4730


To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

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



[PHP] looping through a database

2008-06-16 Thread Richard Kurth
I am looping through a database of files that are numbers 1 through 10 
if  number 1 is in the database I what to print out the first table 
below if it is not then print the else section below. Then loop through 
the database to see if 2 through 10 are there and do the same thing. Of 
course what I am doing does not work. Should I move it all to an array 
and then loop through it. Or use a foreach loop.

Could you please give me an idea where to start looking

while($row=mysql_fetch_array($sql_result)){

if ($row[number]==1) {
tr
td File 1/td
tdThis is the file/td
tdDelete/td
/tr
}else{
tr
tdFile1/td
td/td
tdAdd/td
/tr
}

}

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



Re: [PHP] looping through a database

2008-06-16 Thread Wolf

Richard Kurth wrote:
I am looping through a database of files that are numbers 1 through 10 
if  number 1 is in the database I what to print out the first table 
below if it is not then print the else section below. Then loop through 
the database to see if 2 through 10 are there and do the same thing. Of 
course what I am doing does not work. Should I move it all to an array 
and then loop through it. Or use a foreach loop.

Could you please give me an idea where to start looking

while($row=mysql_fetch_array($sql_result)){

if ($row[number]==1) {
tr
td File 1/td
tdThis is the file/td
tdDelete/td
/tr
}else{
tr
tdFile1/td
td/td
tdAdd/td
/tr
}

}



What is the query being executed?

Seriously, this needs more information.  On the upside, it LOOKS like it 
should work, however...


Here's what I use to get 1 random quote from a table I have:
--
$query=select quote from quotes where id=$id;
$query_res = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($query_res)  1)
{ //print message
 $display_block = PSomething blew up./P;
}
else
{ //get info and build Quote display
 $Quote = mysql_fetch_array($query_res);
 echo $Quote['quote'];
}


It could be as simple as the  not working where you really need '  but 
that depends on what/how you are doing things.


Wolf



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



Re: [PHP] looping through a database

2008-06-16 Thread Richard Kurth

Wolf wrote:

Richard Kurth wrote:
I am looping through a database of files that are numbers 1 through 
10 if  number 1 is in the database I what to print out the first 
table below if it is not then print the else section below. Then loop 
through the database to see if 2 through 10 are there and do the same 
thing. Of course what I am doing does not work. Should I move it all 
to an array and then loop through it. Or use a foreach loop.

Could you please give me an idea where to start looking

while($row=mysql_fetch_array($sql_result)){

if ($row[number]==1) {
tr
td File 1/td
tdThis is the file/td
tdDelete/td
/tr
}else{
tr
tdFile1/td
td/td
tdAdd/td
/tr
}

}



What is the query being executed?

Seriously, this needs more information.  On the upside, it LOOKS like 
it should work, however...


Here's what I use to get 1 random quote from a table I have:
--
$query=select quote from quotes where id=$id;
$query_res = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($query_res)  1)
{ //print message
 $display_block = PSomething blew up./P;
}
else
{ //get info and build Quote display
 $Quote = mysql_fetch_array($query_res);
 echo $Quote['quote'];
}


It could be as simple as the  not working where you really need '  
but that depends on what/how you are doing things.


Wolf




This is the query being executed
$sql = SELECT * FROM table WHERE members_id = . $_SESSION[members_id];
$sql_result = mysql_query($sql) or die(mysql_error());

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



Re: [PHP] looping through a database

2008-06-16 Thread Wolf

Richard Kurth wrote:

Wolf wrote:

Richard Kurth wrote:

Could you please give me an idea where to start looking

while($row=mysql_fetch_array($sql_result)){

if ($row[number]==1) {
tr
td File 1/td
tdThis is the file/td
tdDelete/td
/tr
}else{
tr
tdFile1/td
td/td
tdAdd/td
/tr
}

}



What is the query being executed?

!-- SNIP --




This is the query being executed
$sql = SELECT * FROM table WHERE members_id = . $_SESSION[members_id];
$sql_result = mysql_query($sql) or die(mysql_error());


That still pretty much tells me nothing.

Does your table named table exist?
Does your script connect or error?
What DOES output to your screen?
Does the schema for your table contain numbers?

What happens when you use $row['number']?

Or are you just hoping for someone to write your code?

As written, your code will fail due to having PHP interspersed with HTML 
code.  As such, you either need to echo or exit out of the PHP areas and 
then continue.


Wolf


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



Re: [PHP] looping through a database

2008-06-16 Thread paragasu
i am not sure what u want to do, for this case you need to tell us
about your database table
structure. i quess you have table like this.. assume the table name is
table1 and there are ten
column in it file1..file10 respectively

|table1 |
|member_id |
|file1|
|file2|
|file3|
|   :  |
|file10  |

while($row =  mysql_fecth_array($sql_result))
{
  echo display_file($row['file1']);
  echo display_file($row['file2']);
  :
  echo display_file($row['file10']);

}

function display_file($filename)
{
   if file not exist or null etc
  return   add file here link
  else
  return  display file, delete file

}

this is the idea. of course maybe not what you want, unless you can tell us what
really you want to do or what you got..

On 6/17/08, Wolf [EMAIL PROTECTED] wrote:
 Richard Kurth wrote:
 Wolf wrote:
 Richard Kurth wrote:
 Could you please give me an idea where to start looking

 while($row=mysql_fetch_array($sql_result)){

 if ($row[number]==1) {
 tr
 td File 1/td
 tdThis is the file/td
 tdDelete/td
 /tr
 }else{
 tr
 tdFile1/td
 td/td
 tdAdd/td
 /tr
 }

 }


 What is the query being executed?
 !-- SNIP --


 This is the query being executed
 $sql = SELECT * FROM table WHERE members_id = . $_SESSION[members_id];
 $sql_result = mysql_query($sql) or die(mysql_error());

 That still pretty much tells me nothing.

 Does your table named table exist?
 Does your script connect or error?
 What DOES output to your screen?
 Does the schema for your table contain numbers?

 What happens when you use $row['number']?

 Or are you just hoping for someone to write your code?

 As written, your code will fail due to having PHP interspersed with HTML
 code.  As such, you either need to echo or exit out of the PHP areas and
 then continue.

 Wolf


 --
 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] looping through a $_POST variable

2007-12-30 Thread Richard Kurth
I am trying to loop through a $_POST variable.   It comes  from a text 
area and it will have data like many email address or just one listed 
with a space or on a new line. I can't seam to get the data to extract 
properly. I have tried this below


$array = explode(' ', $_POST['emails']);
foreach ($array as $value) {
$sql = SELECT id FROM contacts where emailaddress = '$value' AND 
members_id = '$memberid';

$sql_result=safe_query($sql);
while ($row=mysql_fetch_array($sql_result)){
$id = $row[id];
$sql1=UPDATE contacts SET emailstatus ='Unsubscribed' WHERE id = '$id';
safe_query($sql1);
}}

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



Re: [PHP] looping through a $_POST variable

2007-12-30 Thread Richard Kurth
I am trying to get one email at a time and run it through the loop and 
process it but if I have more than one email in the text area it gives 
me nothing and does not run

What kind of problems are you having in extracting the data?

On Dec 30, 2007, at 4:29 PM, Richard Kurth wrote:

I am trying to loop through a $_POST variable.   It comes  from a 
text area and it will have data like many email address or just one 
listed with a space or on a new line. I can't seam to get the data to 
extract properly. I have tried this below


$array = explode(' ', $_POST['emails']);
foreach ($array as $value) {
$sql = SELECT id FROM contacts where emailaddress = '$value' AND 
members_id = '$memberid';

$sql_result=safe_query($sql);
while ($row=mysql_fetch_array($sql_result)){
$id = $row[id];
$sql1=UPDATE contacts SET emailstatus ='Unsubscribed' WHERE id = 
'$id';

safe_query($sql1);
}}

--
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



Re: [PHP] looping through a $_POST variable

2007-12-30 Thread Richard Lynch
On Sun, December 30, 2007 5:29 pm, Richard Kurth wrote:
 I am trying to loop through a $_POST variable.   It comes  from a text
 area and it will have data like many email address or just one listed
 with a space or on a new line. I can't seam to get the data to extract
 properly. I have tried this below

 $array = explode(' ', $_POST['emails']);

//see what you have.
//maybe it's not hat you think
var_dump($_POST['emails']);


 foreach ($array as $value) {

//you should probably validate the emails using:

http://php.net/imap_rfc822_parse_adrlist

$value_sql = mysql_real_escape_string($value);

 $sql = SELECT id FROM contacts where emailaddress = '$value' AND
 members_id = '$memberid';

Use '$value_sql' here.

And I dunno where $memberid came from, but maybe it should be escaped
as well.

 $sql_result=safe_query($sql);

I'm not sure what safe_query is doing, and maybe you think it can
escape the data you embedded into the SQL, but I don't see how you can
do that...  Sort of a Humpty-Dumpty problem...

 while ($row=mysql_fetch_array($sql_result)){
 $id = $row[id];
 $sql1=UPDATE contacts SET emailstatus ='Unsubscribed' WHERE id =
 '$id';
 safe_query($sql1);
 }}


-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] looping through a $_POST variable

2007-12-30 Thread Richard Kurth

When I do a var_dump($_POST['emails']); it has all the emails in it
string(65) [EMAIL PROTECTED] [EMAIL PROTECTED] 
[EMAIL PROTECTED]

I will validate the emails after I get the loop to work
$memberid comes from a part of the script I did not show you  $memberid 
=$_POST[members_id];

safe_query  is a function that I call that does query stuff

function safe_query ($query = ){
include (dataconf.inc.php);
dbconnect($dbname,$rootusername,$rootpassword,$roothostname);
   global$query_debug;

   if (empty($query)) { return FALSE; }

   if (!empty($query_debug)) { print pre$query/pre\n; }

   $result = mysql_query($query)
   or die(Query Failed: 
   .lierrorno=.mysql_errno(). br
   .lierror=.mysql_error(). brbr
   .liquery=.$query
   );
   return $result;
}


On Sun, December 30, 2007 5:29 pm, Richard Kurth wrote:
  

I am trying to loop through a $_POST variable.   It comes  from a text
area and it will have data like many email address or just one listed
with a space or on a new line. I can't seam to get the data to extract
properly. I have tried this below

$array = explode(' ', $_POST['emails']);



//see what you have.
//maybe it's not hat you think
var_dump($_POST['emails']);


  

foreach ($array as $value) {



//you should probably validate the emails using:

http://php.net/imap_rfc822_parse_adrlist

$value_sql = mysql_real_escape_string($value);

  

$sql = SELECT id FROM contacts where emailaddress = '$value' AND
members_id = '$memberid';



Use '$value_sql' here.

And I dunno where $memberid came from, but maybe it should be escaped
as well.

  

$sql_result=safe_query($sql);



I'm not sure what safe_query is doing, and maybe you think it can
escape the data you embedded into the SQL, but I don't see how you can
do that...  Sort of a Humpty-Dumpty problem...

  

while ($row=mysql_fetch_array($sql_result)){
$id = $row[id];
$sql1=UPDATE contacts SET emailstatus ='Unsubscribed' WHERE id =
'$id';
safe_query($sql1);
}}




  


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



Re: [PHP] looping through a $_POST variable

2007-12-30 Thread dg

You might want to check the loop alone and check each value of $value:

$array = explode(' ', $_POST['emails']);
foreach($array as $value) {
print '$value'br;
}

if it works that way, at least you narrow down the possibilities of  
weirdness.


On Dec 30, 2007, at 5:34 PM, Richard Kurth wrote:


When I do a var_dump($_POST['emails']); it has all the emails in it
string(65) [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] 


I will validate the emails after I get the loop to work
$memberid comes from a part of the script I did not show you   
$memberid =$_POST[members_id];

safe_query  is a function that I call that does query stuff

function safe_query ($query = ){
   include (dataconf.inc.php);
   dbconnect($dbname,$rootusername,$rootpassword,$roothostname);
  global$query_debug;

  if (empty($query)) { return FALSE; }

  if (!empty($query_debug)) { print pre$query/pre\n; }

  $result = mysql_query($query)
  or die(Query Failed: 
  .lierrorno=.mysql_errno(). br
  .lierror=.mysql_error(). brbr
  .liquery=.$query
  );
  return $result;
}


On Sun, December 30, 2007 5:29 pm, Richard Kurth wrote:

I am trying to loop through a $_POST variable.   It comes  from a  
text
area and it will have data like many email address or just one  
listed
with a space or on a new line. I can't seam to get the data to  
extract

properly. I have tried this below

$array = explode(' ', $_POST['emails']);



//see what you have.
//maybe it's not hat you think
var_dump($_POST['emails']);




foreach ($array as $value) {



//you should probably validate the emails using:

http://php.net/imap_rfc822_parse_adrlist

$value_sql = mysql_real_escape_string($value);



$sql = SELECT id FROM contacts where emailaddress = '$value' AND
members_id = '$memberid';



Use '$value_sql' here.

And I dunno where $memberid came from, but maybe it should be escaped
as well.



$sql_result=safe_query($sql);



I'm not sure what safe_query is doing, and maybe you think it can
escape the data you embedded into the SQL, but I don't see how you  
can

do that...  Sort of a Humpty-Dumpty problem...



while ($row=mysql_fetch_array($sql_result)){
$id = $row[id];
$sql1=UPDATE contacts SET emailstatus ='Unsubscribed' WHERE id =
'$id';
safe_query($sql1);
}}







--
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



Re: [PHP] looping through a $_POST variable

2007-12-30 Thread Richard Lynch
Okay.

Now var_dump($array) and see what it has.

On Sun, December 30, 2007 6:34 pm, Richard Kurth wrote:
 When I do a var_dump($_POST['emails']); it has all the emails in it
 string(65) [EMAIL PROTECTED] [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 I will validate the emails after I get the loop to work
 $memberid comes from a part of the script I did not show you
 $memberid
 =$_POST[members_id];
 safe_query  is a function that I call that does query stuff

 function safe_query ($query = ){
  include (dataconf.inc.php);
  dbconnect($dbname,$rootusername,$rootpassword,$roothostname);
 global$query_debug;

 if (empty($query)) { return FALSE; }

 if (!empty($query_debug)) { print pre$query/pre\n; }

 $result = mysql_query($query)
 or die(Query Failed: 
 .lierrorno=.mysql_errno(). br
 .lierror=.mysql_error(). brbr
 .liquery=.$query
 );
 return $result;
 }

 On Sun, December 30, 2007 5:29 pm, Richard Kurth wrote:

 I am trying to loop through a $_POST variable.   It comes  from a
 text
 area and it will have data like many email address or just one
 listed
 with a space or on a new line. I can't seam to get the data to
 extract
 properly. I have tried this below

 $array = explode(' ', $_POST['emails']);


 //see what you have.
 //maybe it's not hat you think
 var_dump($_POST['emails']);



 foreach ($array as $value) {


 //you should probably validate the emails using:

 http://php.net/imap_rfc822_parse_adrlist

 $value_sql = mysql_real_escape_string($value);


 $sql = SELECT id FROM contacts where emailaddress = '$value' AND
 members_id = '$memberid';


 Use '$value_sql' here.

 And I dunno where $memberid came from, but maybe it should be
 escaped
 as well.


 $sql_result=safe_query($sql);


 I'm not sure what safe_query is doing, and maybe you think it can
 escape the data you embedded into the SQL, but I don't see how you
 can
 do that...  Sort of a Humpty-Dumpty problem...


 while ($row=mysql_fetch_array($sql_result)){
 $id = $row[id];
 $sql1=UPDATE contacts SET emailstatus ='Unsubscribed' WHERE id =
 '$id';
 safe_query($sql1);
 }}








-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] looping through a $_POST variable

2007-12-30 Thread Richard Kurth

looks like that is my problem it is not separating the emails
string(67) [EMAIL PROTECTED] [EMAIL PROTECTED] 
[EMAIL PROTECTED]
array(1) { [0]= string(67) [EMAIL PROTECTED] [EMAIL PROTECTED] 
[EMAIL PROTECTED] }


$array = explode(' ', $_POST['emails']);
what should I use for spaces or next line to separate them



Okay.

Now var_dump($array) and see what it has.

On Sun, December 30, 2007 6:34 pm, Richard Kurth wrote:
  

When I do a var_dump($_POST['emails']); it has all the emails in it
string(65) [EMAIL PROTECTED] [EMAIL PROTECTED]
[EMAIL PROTECTED]
I will validate the emails after I get the loop to work
$memberid comes from a part of the script I did not show you
$memberid
=$_POST[members_id];
safe_query  is a function that I call that does query stuff

function safe_query ($query = ){
 include (dataconf.inc.php);
 dbconnect($dbname,$rootusername,$rootpassword,$roothostname);
global$query_debug;

if (empty($query)) { return FALSE; }

if (!empty($query_debug)) { print pre$query/pre\n; }

$result = mysql_query($query)
or die(Query Failed: 
.lierrorno=.mysql_errno(). br
.lierror=.mysql_error(). brbr
.liquery=.$query
);
return $result;
}



On Sun, December 30, 2007 5:29 pm, Richard Kurth wrote:

  

I am trying to loop through a $_POST variable.   It comes  from a
text
area and it will have data like many email address or just one
listed
with a space or on a new line. I can't seam to get the data to
extract
properly. I have tried this below

$array = explode(' ', $_POST['emails']);



//see what you have.
//maybe it's not hat you think
var_dump($_POST['emails']);



  

foreach ($array as $value) {



//you should probably validate the emails using:

http://php.net/imap_rfc822_parse_adrlist

$value_sql = mysql_real_escape_string($value);


  

$sql = SELECT id FROM contacts where emailaddress = '$value' AND
members_id = '$memberid';



Use '$value_sql' here.

And I dunno where $memberid came from, but maybe it should be
escaped
as well.


  

$sql_result=safe_query($sql);



I'm not sure what safe_query is doing, and maybe you think it can
escape the data you embedded into the SQL, but I don't see how you
can
do that...  Sort of a Humpty-Dumpty problem...


  

while ($row=mysql_fetch_array($sql_result)){
$id = $row[id];
$sql1=UPDATE contacts SET emailstatus ='Unsubscribed' WHERE id =
'$id';
safe_query($sql1);
}}




  




  


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



Re: [PHP] looping through a $_POST variable

2007-12-30 Thread Richard Lynch
You should use whatever is actually BETWEEN the emails, which could be
anything...

See the thread about Tedd's bazaar (sic) problem and use the technique
there to see what you are actually getting.

You may even need to resort to a split instead of explode if newlines,
spaces, and carriage-returns are all possible inputs from the end
users...

On Sun, December 30, 2007 7:33 pm, Richard Kurth wrote:
 looks like that is my problem it is not separating the emails
 string(67) [EMAIL PROTECTED] [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 array(1) { [0]= string(67) [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED] }

 $array = explode(' ', $_POST['emails']);
 what should I use for spaces or next line to separate them


 Okay.

 Now var_dump($array) and see what it has.

 On Sun, December 30, 2007 6:34 pm, Richard Kurth wrote:

 When I do a var_dump($_POST['emails']); it has all the emails in it
 string(65) [EMAIL PROTECTED] [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 I will validate the emails after I get the loop to work
 $memberid comes from a part of the script I did not show you
 $memberid
 =$_POST[members_id];
 safe_query  is a function that I call that does query stuff

 function safe_query ($query = ){
  include (dataconf.inc.php);
  dbconnect($dbname,$rootusername,$rootpassword,$roothostname);
 global$query_debug;

 if (empty($query)) { return FALSE; }

 if (!empty($query_debug)) { print pre$query/pre\n; }

 $result = mysql_query($query)
 or die(Query Failed: 
 .lierrorno=.mysql_errno(). br
 .lierror=.mysql_error(). brbr
 .liquery=.$query
 );
 return $result;
 }


 On Sun, December 30, 2007 5:29 pm, Richard Kurth wrote:


 I am trying to loop through a $_POST variable.   It comes  from a
 text
 area and it will have data like many email address or just one
 listed
 with a space or on a new line. I can't seam to get the data to
 extract
 properly. I have tried this below

 $array = explode(' ', $_POST['emails']);


 //see what you have.
 //maybe it's not hat you think
 var_dump($_POST['emails']);




 foreach ($array as $value) {


 //you should probably validate the emails using:

 http://php.net/imap_rfc822_parse_adrlist

 $value_sql = mysql_real_escape_string($value);



 $sql = SELECT id FROM contacts where emailaddress = '$value' AND
 members_id = '$memberid';


 Use '$value_sql' here.

 And I dunno where $memberid came from, but maybe it should be
 escaped
 as well.



 $sql_result=safe_query($sql);


 I'm not sure what safe_query is doing, and maybe you think it
 can
 escape the data you embedded into the SQL, but I don't see how you
 can
 do that...  Sort of a Humpty-Dumpty problem...



 while ($row=mysql_fetch_array($sql_result)){
 $id = $row[id];
 $sql1=UPDATE contacts SET emailstatus ='Unsubscribed' WHERE id =
 '$id';
 safe_query($sql1);
 }}












-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] looping through a $_POST variable

2007-12-30 Thread Mark Kelly
Hi.

On Monday 31 December 2007 00:34, Richard Kurth wrote:
 When I do a var_dump($_POST['emails']); it has all the emails in it
 string(65) [EMAIL PROTECTED] [EMAIL PROTECTED]
 [EMAIL PROTECTED]

Then this simple regex should do you; just use it instead of explode:

$AddressList = preg_split('/\s+/', $_POST['emails']);

 I will validate the emails after I get the loop to work

An better idea might be to do that INSIDE the loop (the following assumes 
your $memberid is a number, adjust to suit if this is not the case):

foreach ($AddressList as $emailaddress) {
// Escape the data before letting it near the db
$SAFE_emailaddress = mysql_real_escape_string($emailaddress);
$SAFE_memberid = intval($_POST[members_id]);
// Build the query
$sql = SELECT id 
FROM contact
WHERE emailaddress = '$SAFE_emailaddress' 
AND members_id = '$SAFE_memberid';
// etc. etc.
}

 safe_query  is a function that I call that does query stuff

That is a *terrible* name for that function, as it does nothing at all to 
make the query safe. You might consider renaming it to run_query or 
something. Remember, other people may have to make sense of your code one 
day.

Hope this helps,

Mark

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



[PHP] Looping through array

2006-11-16 Thread Ashley M. Kirchner


   Say I have an array containing ten items, and I want to display them 
in a table as follows:


5 4 3 2 1
   10 9 8 7 6

   What's the best way to loop through that array to do that?  My 
thinking gets me to create a loop for 5 through 1, repeated twice, and 
the second time I add '5' to the index value.  There's got to be a saner 
way...


--
W | It's not a bug - it's an undocumented feature.
 +
 Ashley M. Kirchner mailto:[EMAIL PROTECTED]   .   303.442.6410 x130
 IT Director / SysAdmin / Websmith . 800.441.3873 x130
 Photo Craft Imaging   . 3550 Arapahoe Ave. #6
 http://www.pcraft.com . .  ..   Boulder, CO 80303, U.S.A.

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



Re: [PHP] Looping through array

2006-11-16 Thread Brad Bonkoski

Ashley M. Kirchner wrote:


   Say I have an array containing ten items, and I want to display 
them in a table as follows:


5 4 3 2 1
   10 9 8 7 6

   What's the best way to loop through that array to do that?  My 
thinking gets me to create a loop for 5 through 1, repeated twice, and 
the second time I add '5' to the index value.  There's got to be a 
saner way...



Something like this perhaps...

$arr = array(...);
$per_row = 5;
$elem = count($arr);
for($i=0; $i$elem; $i++) {
   if( $i == 0 )
  echo tr;
   if( $i % $per_row == 0 )
  echo /trtr;
   echo td$arr[$i]/td;
}

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



Re: [PHP] Looping through array

2006-11-16 Thread Brad Bonkoski

Ashley M. Kirchner wrote:


   Say I have an array containing ten items, and I want to display 
them in a table as follows:


5 4 3 2 1
   10 9 8 7 6

   What's the best way to loop through that array to do that?  My 
thinking gets me to create a loop for 5 through 1, repeated twice, and 
the second time I add '5' to the index value.  There's got to be a 
saner way...



Something like this perhaps...

$arr = array(...);
$per_row = 5;
$elem = count($arr);
for($i=0; $i$elem; $i++) {
   if( $i == 0 )
  echo tr;
   else if( $i % $per_row == 0 )
  echo /trtr;
   echo td$arr[$i]/td;
}

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



Re: [PHP] Looping through array

2006-11-16 Thread Darrell Brogdon

?php
$arr = array(5, 4, 3, 2, 1, 10, 9, 8, 7, 6,);

echo 'table border=1';
echo 'tr';

for ($x=0,$y=sizeof($arr); $x$y; ++$x) {
echo td{$arr[$x]}/td;

if ($x == 4) {
echo '/trtr';
}
}

echo '/tr';
echo '/table';
?

On Nov 16, 2006, at 1:19 PM, Ashley M. Kirchner wrote:



   Say I have an array containing ten items, and I want to display  
them in a table as follows:


5 4 3 2 1
   10 9 8 7 6

   What's the best way to loop through that array to do that?  My  
thinking gets me to create a loop for 5 through 1, repeated twice,  
and the second time I add '5' to the index value.  There's got to  
be a saner way...


--
W | It's not a bug - it's an undocumented feature.
 +
 Ashley M. Kirchner mailto:[EMAIL PROTECTED]   .   303.442.6410 x130
 IT Director / SysAdmin / Websmith . 800.441.3873 x130
 Photo Craft Imaging   . 3550 Arapahoe Ave. #6
 http://www.pcraft.com . .  ..   Boulder, CO 80303, U.S.A.

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







Darrell Brogdon
[EMAIL PROTECTED]
http://darrell.brogdon.net

*
** Prepare for PHP Certication!**
** http://phpflashcards.com**
*




Re: [PHP] Looping through array

2006-11-16 Thread Ashley M. Kirchner

Brad Bonkoski wrote:

Something like this perhaps...

$arr = array(...);
$per_row = 5;
$elem = count($arr);
for($i=0; $i$elem; $i++) {
   if( $i == 0 )
  echo tr;
   else if( $i % $per_row == 0 )
  echo /trtr;
   echo td$arr[$i]/td;
}

   That simply displays things in order, 1 through 5, then 6 through 10.

--
W | It's not a bug - it's an undocumented feature.
 +
 Ashley M. Kirchner mailto:[EMAIL PROTECTED]   .   303.442.6410 x130
 IT Director / SysAdmin / Websmith . 800.441.3873 x130
 Photo Craft Imaging   . 3550 Arapahoe Ave. #6
 http://www.pcraft.com . .  ..   Boulder, CO 80303, U.S.A.

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



Re: [PHP] Looping through array

2006-11-16 Thread Dave Goodchild

If you know the array elements, you may not need to loop. Why not just echo
the particular array elements i.e. td?php echo $array[2]; ?/td for
example?


Re: [PHP] Looping through array

2006-11-16 Thread James Tu

$arr = array(...);

$first_row = '';
$second_row = '';
for ($i=4; $i=0; $i--){
$first_row = $first_row . td{$arr[$x]}/td;
$second_row = $second_row . td{$arr[$x + 5]}/td;
}
print 'tr' . $first_row . '/tr';
print 'tr' . $second_row . '/tr';


On Nov 16, 2006, at 3:19 PM, Ashley M. Kirchner wrote:



   Say I have an array containing ten items, and I want to display  
them in a table as follows:


5 4 3 2 1
   10 9 8 7 6

   What's the best way to loop through that array to do that?  My  
thinking gets me to create a loop for 5 through 1, repeated twice,  
and the second time I add '5' to the index value.  There's got to  
be a saner way...


--
W | It's not a bug - it's an undocumented feature.
 +
 Ashley M. Kirchner mailto:[EMAIL PROTECTED]   .   303.442.6410 x130
 IT Director / SysAdmin / Websmith . 800.441.3873 x130
 Photo Craft Imaging   . 3550 Arapahoe Ave. #6
 http://www.pcraft.com . .  ..   Boulder, CO 80303, U.S.A.

--
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



Re: [PHP] Looping through array

2006-11-16 Thread Darrell Brogdon
So in other words, you have an array like $arr = array 
(1,2,3,4,5,6,7,8,9,10) but you want it to render on the page as:


  5 4 3 2 1
10 9 8 7 6

right?

-D


On Nov 16, 2006, at 1:35 PM, Ashley M. Kirchner wrote:


Darrell Brogdon wrote:

$arr = array(5, 4, 3, 2, 1, 10, 9, 8, 7, 6,);

   The array is in order, from 1 to 10.  It was populated that way.

--
W | It's not a bug - it's an undocumented feature.
 +
 Ashley M. Kirchner mailto:[EMAIL PROTECTED]   .   303.442.6410 x130
 IT Director / SysAdmin / Websmith . 800.441.3873 x130
 Photo Craft Imaging   . 3550 Arapahoe Ave. #6
 http://www.pcraft.com . .  ..   Boulder, CO 80303, U.S.A.







Darrell Brogdon
[EMAIL PROTECTED]
http://darrell.brogdon.net

*
** Prepare for PHP Certication!**
** http://phpflashcards.com**
*




Re: [PHP] Looping through array

2006-11-16 Thread Ashley M. Kirchner

Darrell Brogdon wrote:
So in other words, you have an array like $arr = 
array(1,2,3,4,5,6,7,8,9,10) but you want it to render on the page as:


  5 4 3 2 1
10 9 8 7 6

right?
   That would be correct.  James Tu provided a solution that I think 
will work.  I'm always open to other suggestions of course.


--
W | It's not a bug - it's an undocumented feature.
 +
 Ashley M. Kirchner mailto:[EMAIL PROTECTED]   .   303.442.6410 x130
 IT Director / SysAdmin / Websmith . 800.441.3873 x130
 Photo Craft Imaging   . 3550 Arapahoe Ave. #6
 http://www.pcraft.com . .  ..   Boulder, CO 80303, U.S.A.

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



Re: [PHP] Looping through array

2006-11-16 Thread tedd

At 1:19 PM -0700 11/16/06, Ashley M. Kirchner wrote:
   Say I have an array containing ten items, and I want to display 
them in a table as follows:


5 4 3 2 1
   10 9 8 7 6

   What's the best way to loop through that array to do that?  My 
thinking gets me to create a loop for 5 through 1, repeated twice, 
and the second time I add '5' to the index value.  There's got to be 
a saner way...


Ashley:

Look into array_chunk() and array_flip(). The first can break your 
main array into two and the second can reverse the results.


tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Looping through array

2006-11-16 Thread Paul Novitski

At 11/16/2006 12:19 PM, Ashley M. Kirchner wrote:

   Say I have an array containing ten items, and I want to display 
them in a table as follows:


5 4 3 2 1
   10 9 8 7 6

   What's the best way to loop through that array to do that?  My 
thinking gets me to create a loop for 5 through 1, repeated twice, 
and the second time I add '5' to the index value.  There's got to 
be a saner way...



In order to figure out the best PHP logic to generate the series, I'd 
first make sure the markup is solid.  I realize that you've already 
indicated a table markup in two rows, but I'd like to examine 
that.  Can you tell us why the numbers are in this particular sequence?


Do the numbers represent items that are conceptually in ascending 
order but are presented in reverse order on the screen?  If so, I'd 
wonder whether someone reading the page with assistive technology 
might be confused by the reverse order, and I'd try to find a way to 
mark them up ascending and then change the sequence stylistically.


Are they split into two rows because they represent two discrete 
groups in the data set or because of display considerations?  If the 
latter, I'd argue that they don't really belong in two table rows; 
that using tables to force presentation is misapplying the tool.


Have you considered an unordered list, floated right, wrapped in a 
container whose width naturally forces a wrap after the fifth 
item?  I like that solution because it allows you to mark up the 
numbers in sequence and in future change the number of items in the 
sequence and/or change the way the series is presented visually 
without having to mess with the logic generating the markup.


Regards,
Paul  


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



[PHP] Looping through a Db query result twice in PEAR

2006-05-24 Thread Phillip S. Baker

Greetings All,

I have a problem that I usually solve in MySQL pretty easily, but using 
PEAR identifiers are not working.

Any suggestions.
I want to loop through a result set in two different while loops that 
are not nested.


I am able to do in it MySQl as follows

$sql=Some query;
$result = $conn-query($sql);

while ($row = $result-fetchArray()) {
echo $row['hey'];
}

while ($row2 = $result-fetchArray()) {
echo $row2['otherhey'];
}

This has worked in the past and I do not have to hit up the DB twice for 
the same information.


However when I try something similar with PEAR it does not work.
So the below does not work. This is my first time using PEAR.
So can anyone help me out.
I cannot seem to find anything about this on the documentation online.

$sql=Some query;
$result = $db-query($sql);
while($result-fetchInto($data)) {
echo \t\t\tlia 
href=\#$data[id]\$data[question]/a/li\n;
}

while($result-fetchInto($data2)) {
echo a name=\#$data2[id]\$data2[answer]/a/li\n;
}

Thanks

Phillip

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



RE: [PHP] Looping through a Db query result twice in PEAR

2006-05-24 Thread Warren Vail
 
Shouldn't it be;

$sql=Some query;
$result = $conn-query($sql);
//V VVV
while ($row = $conn-fetchArray($result)) {
echo $row['hey'];
}
// V VVV
while ($row2 = $conn-fetchArray($result)) {
echo $row2['otherhey'];
}

Warren Vail

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



Re: [PHP] Looping through a Db query result twice in PEAR

2006-05-24 Thread Curt Zirzow
On Wed, May 24, 2006 at 02:28:33PM -0600, Phillip S. Baker wrote:
 Greetings All,
 
 I have a problem that I usually solve in MySQL pretty easily, but using 
 PEAR identifiers are not working.
 Any suggestions.
 I want to loop through a result set in two different while loops that 
 are not nested.
 
 I am able to do in it MySQl as follows
 
 $sql=Some query;
 $result = $conn-query($sql);

I'm not sure how this is mysql specific. it appears that this is
some class you are using.

 
 while ($row = $result-fetchArray()) {
   echo $row['hey'];
 }
 
 while ($row2 = $result-fetchArray()) {
   echo $row2['otherhey'];
 }
 
 This has worked in the past and I do not have to hit up the DB twice for 
 the same information.

The class you are using probably does some caching of the result so
you are able to do this.

 
 However when I try something similar with PEAR it does not work.
 So the below does not work. This is my first time using PEAR.
 So can anyone help me out.
 I cannot seem to find anything about this on the documentation online.
 
 $sql=Some query;
 $result = $db-query($sql);
 while($result-fetchInto($data)) {
   echo \t\t\tlia 
   href=\#$data[id]\$data[question]/a/li\n;
 }
 
 while($result-fetchInto($data2)) {
   echo a name=\#$data2[id]\$data2[answer]/a/li\n;
 }

This is sort of expected with any interface, if you want to start
over you would probably have a $result-seek() call resetting the
result  to the beginning of the result set. I dont think pear
has such a thing.  The pear mailing list might be more helpful.

Curt.
-- 
cat .signature: No such file or directory

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



Re: [PHP] Looping information into a table

2006-04-04 Thread Georgi Ivanov
A little OT but i think it is important :
I really would not write this code like this .
You are making too many queries to the database . If u have 100 rows in first 
table and 200 rows returned from  second query , you make 100*200 queries to 
the database !
Try using SQL Joins. Like this :

?php
$query =select * from cforum cf INNER JOIN scforum;
$res=mysql_query($query);

while ($line=mysql_fetch_array($res)){
?
 table width=94% border=-1 bordercolor=black cellspacing=1
 cellpadding=0 align=center tr
 td
 table width=100% border=0 cellspacing=0 cellpadding=0
 bgcolor=#ff6600 tr
 tdfont face=tahoma size=1 color=white?php echo(font face =tahoma 
color=black size=1b$line[cname];/b/fontbr);
 ?/font/td td align=rightfont face=tahoma size=1
 color=whiteForum Mods Will Go Here/font/td /tr
 /table
 /td
 /tr
 tr
 td
 table width=98% border=0 cellspacing=2 cellpadding=0
 align=center tr
 tdfont face=tahoma color=black size=1
 ?php echo(font face =tahoma color=black size=1b-- Topic Name:
 /b$line[scname] br b-- Topic Description:/b line[scdesc]br); ?

 /td
 /tr
 /table
 /td
 /tr
 /tablebr
?php
}

You may want to use LEfT Join ..
This way you will make just ONE query to the database 

On Monday April 3 2006 06:31, benifactor wrote:
 i am creating a forum and i am having trouble getting the database
 information in to an html table

 i believe it has somthing to do with the placement of the while loops
 because they repeat the segment of code over untill the statment returns
 false, thus adding extra html.. you guys are the experts so if you could
 help i would appreaciate it. i will give you the code and an example of how
 its shows up and then how i need it to show up and if you could point me in
 the right direction it would be awsome...


 //code
 ?
 $query = mysql_query(select * from cforum);
 while ($query1 = mysql_fetch_array($query)) {
 $lid = $query1[id];

 $query2 = mysql_query(select * from scforum where cfid = '$lid');
 while ($query3 = mysql_fetch_array($query2)) {

 ?
 table width=94% border=-1 bordercolor=black cellspacing=1
 cellpadding=0 align=center tr
 td
 table width=100% border=0 cellspacing=0 cellpadding=0
 bgcolor=#ff6600 tr
 tdfont face=tahoma size=1 color=white?php echo(font face
 =tahoma color=black size=1b$query1[cname];/b/fontbr);
 ?/font/td td align=rightfont face=tahoma size=1
 color=whiteForum Mods Will Go Here/font/td /tr
 /table
 /td
 /tr
 tr
 td
 table width=98% border=0 cellspacing=2 cellpadding=0
 align=center tr
 tdfont face=tahoma color=black size=1
 ?php echo(font face =tahoma color=black size=1b-- Topic Name:
 /b$query3[scname] br b-- Topic Description:/b
 $query3[scdesc]br); ?

 /td
 /tr
 /table
 /td
 /tr
 /tablebr



 ?
 }
 }

 ?

 //end code

 //here is how it displays

 General;
Forum Mods Will Go Here

 -- Topic Name: General
 -- Topic Description: blagh l adsklhdfkhadklfhaklsdhf sdhlkh





 Other;
Forum Mods Will Go Here

 -- Topic Name: Other
 -- Topic Description: sdfdsjl;asdf





 Other;
Forum Mods Will Go Here

 -- Topic Name: Another Other
 -- Topic Description: sdafkasdhkdhas





 other;
Forum Mods Will Go Here

 -- Topic Name: yet another other
 -- Topic Description: Talk about all aspects of other. oh wait
 There is another forum just for that!





 Bug Reports;
Forum Mods Will Go Here

 -- Topic Name: Web Site Bug Reports
 -- Topic Description: Report bugs here. Please include
 information like, how the problem was encountered, the nature of the bug
 e.x. Spelling error on the forum page. Please give us steps on how to
 re-create the bug so we can fix it.




 // see this looks ok, but the 'others' should be grouped together

 like this
 Other; forum Mods Will Go Here
 -- Topic Name: Another Other
 -- Topic Description: sdafkasdhkdhas

 -- Topic Name: Other
 -- Topic Description: sdfdsjl;asdf


 -- Topic Name: yet another other
   -- Topic Description: Talk about all aspects of other.
 oh wait There is another forum just for that!




  if you get what i mean and can offer any help i would appreaciate it thank
 you in advance!

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



Re: [PHP] Looping information into a table

2006-04-04 Thread Georgi Ivanov
Sorry . 
The correct SQL should be:
 $query =select * from cforum cf INNER JOIN scforum ON  
cforum.id=scforum.cfid;

:) 

On Tuesday April 4 2006 11:58, Georgi Ivanov wrote:
 A little OT but i think it is important :
 I really would not write this code like this .
 You are making too many queries to the database . If u have 100 rows in
 first table and 200 rows returned from  second query , you make 100*200
 queries to the database !
 Try using SQL Joins. Like this :

 ?php
 $query =select * from cforum cf INNER JOIN scforum ON ;
 $res=mysql_query($query);

 while ($line=mysql_fetch_array($res)){
 ?
table width=94% border=-1 bordercolor=black cellspacing=1
  cellpadding=0 align=center tr
  td
  table width=100% border=0 cellspacing=0 cellpadding=0
  bgcolor=#ff6600 tr
  tdfont face=tahoma size=1 color=white?php echo(font face
 =tahoma color=black size=1b$line[cname];/b/fontbr);
  ?/font/td td align=rightfont face=tahoma size=1
  color=whiteForum Mods Will Go Here/font/td /tr
  /table
  /td
  /tr
  tr
  td
  table width=98% border=0 cellspacing=2 cellpadding=0
  align=center tr
  tdfont face=tahoma color=black size=1
  ?php echo(font face =tahoma color=black size=1b-- Topic Name:
  /b$line[scname] br b-- Topic Description:/b line[scdesc]br);
 ?

  /td
  /tr
  /table
  /td
  /tr
  /tablebr
 ?php
 }

 You may want to use LEfT Join ..
 This way you will make just ONE query to the database

 On Monday April 3 2006 06:31, benifactor wrote:
  i am creating a forum and i am having trouble getting the database
  information in to an html table
 
  i believe it has somthing to do with the placement of the while loops
  because they repeat the segment of code over untill the statment returns
  false, thus adding extra html.. you guys are the experts so if you could
  help i would appreaciate it. i will give you the code and an example of
  how its shows up and then how i need it to show up and if you could point
  me in the right direction it would be awsome...
 
 
  //code
  ?
  $query = mysql_query(select * from cforum);
  while ($query1 = mysql_fetch_array($query)) {
  $lid = $query1[id];
 
  $query2 = mysql_query(select * from scforum where cfid = '$lid');
  while ($query3 = mysql_fetch_array($query2)) {
 
  ?
  table width=94% border=-1 bordercolor=black cellspacing=1
  cellpadding=0 align=center tr
  td
  table width=100% border=0 cellspacing=0 cellpadding=0
  bgcolor=#ff6600 tr
  tdfont face=tahoma size=1 color=white?php echo(font face
  =tahoma color=black size=1b$query1[cname];/b/fontbr);
  ?/font/td td align=rightfont face=tahoma size=1
  color=whiteForum Mods Will Go Here/font/td /tr
  /table
  /td
  /tr
  tr
  td
  table width=98% border=0 cellspacing=2 cellpadding=0
  align=center tr
  tdfont face=tahoma color=black size=1
  ?php echo(font face =tahoma color=black size=1b-- Topic Name:
  /b$query3[scname] br b-- Topic Description:/b
  $query3[scdesc]br); ?
 
  /td
  /tr
  /table
  /td
  /tr
  /tablebr
 
 
 
  ?
  }
  }
 
  ?
 
  //end code
 
  //here is how it displays
 
  General;
 Forum Mods Will Go Here
 
  -- Topic Name: General
  -- Topic Description: blagh l adsklhdfkhadklfhaklsdhf sdhlkh
 
 
 
 
 
  Other;
 Forum Mods Will Go Here
 
  -- Topic Name: Other
  -- Topic Description: sdfdsjl;asdf
 
 
 
 
 
  Other;
 Forum Mods Will Go Here
 
  -- Topic Name: Another Other
  -- Topic Description: sdafkasdhkdhas
 
 
 
 
 
  other;
 Forum Mods Will Go Here
 
  -- Topic Name: yet another other
  -- Topic Description: Talk about all aspects of other. oh
  wait There is another forum just for that!
 
 
 
 
 
  Bug Reports;
 Forum Mods Will Go Here
 
  -- Topic Name: Web Site Bug Reports
  -- Topic Description: Report bugs here. Please include
  information like, how the problem was encountered, the nature of the bug
  e.x. Spelling error on the forum page. Please give us steps on how to
  re-create the bug so we can fix it.
 
 
 
 
  // see this looks ok, but the 'others' should be grouped together
 
  like this
  Other; forum Mods Will Go Here
  -- Topic Name: Another Other
  -- Topic Description: sdafkasdhkdhas
 
  -- Topic Name: Other
  -- Topic Description: sdfdsjl;asdf
 
 
  -- Topic Name: yet another other
-- Topic Description: Talk about all aspects of other.
  oh wait There is another forum just for that!
 
 
 
 
   if you get what i mean and can offer any help i would appreaciate it
  thank you in advance!

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



Re: [PHP] Looping information into a table

2006-04-03 Thread tedd
i am creating a forum and i am having trouble getting the database 
information in to an html table


i believe it has somthing to do with the placement of the while 
loops because they repeat the segment of code over untill the 
statment returns false, thus adding extra html.. you guys are the 
experts so if you could help i would appreaciate it. i will give you 
the code and an example of how its shows up and then how i need it 
to show up and if you could point me in the right direction it would 
be awsome...




Try something more simple, like:

http://www.weberdev.com/get_example-5.html

tedd
--

http://sperling.com

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



Re: [PHP] Looping information into a table

2006-04-02 Thread Chris

benifactor wrote:

i am creating a forum and i am having trouble getting the database information 
in to an html table

i believe it has somthing to do with the placement of the while loops because 
they repeat the segment of code over untill the statment returns false, thus 
adding extra html.. you guys are the experts so if you could help i would 
appreaciate it. i will give you the code and an example of how its shows up and 
then how i need it to show up and if you could point me in the right direction 
it would be awsome...


It sure is. You're printing out the heading over and over again inside 
the second loop.


try this code:

http://pastebin.com/637039

I don't know if it was a mail problem, but can I suggest you indent your 
code, it makes it so much easier to see where your loops are.


--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] Looping from A to Z

2006-02-20 Thread Jason Motes

Richard K Miller wrote:
Good afternoon.  I'm having trouble getting PHP to loop from A  through 
Z.  Here is what I tried, coming from a C background:


for ($l = A; $l = Z; $l++)
 echo $l;



I use this:

for($i='a'; $i != 'aa'; $i++){
  print $i;
|

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



[PHP] Looping from A to Z

2006-02-19 Thread Richard K Miller
Good afternoon.  I'm having trouble getting PHP to loop from A  
through Z.  Here is what I tried, coming from a C background:


for ($l = A; $l = Z; $l++)
 echo $l;

// Returns A, B, C, ..., X, Y, Z, AA, AB, AC, AD, AE, ... YX, YY,  
YZ.  (26 * 26 results!)


Interestingly, if I make it a less than operation instead of less  
than or equal to, it works correctly (except for the Z):


for ($l = A; $l  Z; $l++)
 echo $l;

// Returns A, B, C, ..., W, X, Y  (25 results)

Anyone know why PHP would do that?

Richard

---
Richard K. Miller
www.richardkmiller.com

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



Re: [PHP] Looping from A to Z

2006-02-19 Thread Philip Hallstrom
Good afternoon.  I'm having trouble getting PHP to loop from A through Z. 
Here is what I tried, coming from a C background:


for ($l = A; $l = Z; $l++)
   echo $l;

// Returns A, B, C, ..., X, Y, Z, AA, AB, AC, AD, AE, ... YX, YY, YZ.  (26 * 
26 results!)


Interestingly, if I make it a less than operation instead of less than or 
equal to, it works correctly (except for the Z):


for ($l = A; $l  Z; $l++)
   echo $l;

// Returns A, B, C, ..., W, X, Y  (25 results)

Anyone know why PHP would do that?


Nope... but try...

for ( $l = ord(A); $l = ord(Z); $l++ )
echo $l;

Also maybe check out the range() function.

-philip

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



Re: [PHP] Looping from A to Z

2006-02-19 Thread tedd
Good afternoon.  I'm having trouble getting PHP to loop from A 
through Z.  Here is what I tried, coming from a C background:


for ($l = A; $l = Z; $l++)
 echo $l;

// Returns A, B, C, ..., X, Y, Z, AA, AB, AC, AD, AE, ... YX, YY, 
YZ.  (26 * 26 results!)


Interestingly, if I make it a less than operation instead of less 
than or equal to, it works correctly (except for the Z):


for ($l = A; $l  Z; $l++)
 echo $l;

// Returns A, B, C, ..., W, X, Y  (25 results)

Anyone know why PHP would do that?

Richard



I don't see the problem.

There are 26 letters. If you say start at A and finish before Z, then 
you should expect 25 letters returned.


Maybe there is something I'm not understanding.

tedd
--

http://sperling.com/

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



Re: [PHP] Looping from A to Z

2006-02-19 Thread Jim McIntyre
Good afternoon.  I'm having trouble getting PHP to loop from A
through Z.  Here is what I tried, coming from a C background:

for ($l = A; $l = Z; $l++)
  echo $l;

// Returns A, B, C, ..., X, Y, Z, AA, AB, AC, AD, AE, ... YX, YY, YZ. 
(26 * 26 results!)

Interestingly, if I make it a less than operation instead of less
than or equal to, it works correctly (except for the Z):

for ($l = A; $l  Z; $l++)
  echo $l;

// Returns A, B, C, ..., W, X, Y  (25 results)

Anyone know why PHP would do that?

Richard


From the PHP docs:

PHP follows Perl's convention when dealing with arithmetic operations on
character variables and not C's. For example, in Perl 'Z'+1 turns into
'AA', while in C 'Z'+1 turns into '[' ( ord('Z') == 90, ord('[') == 91 ).
Note that character variables can be incremented but not decremented.

-Jim

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



Re: [PHP] looping through an array problem

2005-06-06 Thread Jochem Maas

Jack Jackson wrote:
Forgive me if this comes twice: my ISP had a service blackout for three 
hours and I don't know what went:



If my last post read (and I see that it did) that I was defending myself
as opposed to falling ALL OVER my sword, I apologize: allow me to be clear:

No, you're all correct and M. Sokolewicz doubly so: I had
unintentionally selected fields from the wrong table for no reason other
than  lack of sleep coupled with lack of experience and a desperation to
try to understand

The problem was that I was pulling data in a manner both useless and
complex from a thoroughly unnecessary table (I could tell you all why
but you'll all just laugh at me more)

I am grateful for all the help everyone has offered up to now and hope I
did not offend  - I was trying in my last post to indicate that I  was
an idiot, and it appears I've come off as arrogant. I promise it was not
my intent!


don't worry - I got the idea that maybe there was some confusion
- nothing else. oh and I don't think anyone is/will laugh at you
(well most of us won't ;-/), we have all been 'there' :-)

so all is well.




[Then I wrote::]

Ah. I just remembered one reason I had done it involving the art_id field:

I have more publishers in the db than are currently associated with 
artworks. I don't want a publisher to appear unless there is at least 
one image associated with it. So I did this to avoid having people see a 
link to the Sneezy Acres Tribune only to arrive at the next page and 
see, There are no images associated with this publisher.




Jochem Maas wrote:


Jack Jackson wrote:




M. Sokolewicz wrote:


Jack Jackson wrote:

Thanks for all the replies. Jochem, thank you for this code, which 
will take me all night to understand (though I bet it works). I 
also note that SELECT DISTINCT worked here, too


Also as many of you noticed before me, the art_id was in there as a 
fly in the ointment.





by that statement I ment the exact same thing Jochem ment in his 2nd 
part; I have NO idea why you're selecting *ANYTHING* from the arts 
table... it's *useless* if you don't need the data...





Er, yes, that was what I meant: I had unintentionally included that 
bit.Thank you for your help.




Er, Jack - your original query was:

SELECT art.art_id,art.publisher_id,publisher.publisher_name,
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

which is a selection on the art table... ( with a typo)
if you did:

SELECT art.publisher_id,publisher.publisher_name
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

nothing would change. and if you did:

SELECT publisher.publisher_id,publisher.publisher_name
publisher

i.e. not 'unintentionally' selecting from the arts table.
then you would not have had a problem in the first place?!

I think I'm missing something ;-)





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



[PHP] looping through an array problem

2005-06-05 Thread Jack Jackson

This is something dumb I am doing but:

Trying to pull all names of publishers in db. This sql:

SELECT art.art_id,art.publisher_id,publisher.publisher_name,
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

pulls (in phpmyadmin) four rows:
  artID  pubID Publisher_name
  17   The New York Times: Sunday Styles
  23   The New York Sun
  32   Metro NY
  43   The New York Sun


I'm trying to make a sidebar which will make links to each unique 
publisher name:


while ($cartoon = mysql_fetch_assoc($result)) {
 $pub_sidebar[] = ul class='sidebar-menu'a class='img-link' 
href='{$_SERVER['PHP_SELF']}?p={$cartoon['publisher_id']}' 
title=\{$cartoon['publisher_name']}\{$cartoon['publisher_name']}/a/ul;

  }


This prints:
  The New York Times: Sunday Styles

  The New York Sun

  Metro NY

  The New York Sun


I'd like to stop the NY Sun from appearing twice! What have i missed here?

Thanks in advance!

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



Re: [PHP] looping through an array problem

2005-06-05 Thread Mark Cain
One way to do it is to change this :

$pub_sidebar[] = ul class='sidebar-menu'a class='img-link'

to this:

$pub_sidebar[$cartoon['publisher_id']] = ul class='sidebar-menu'a
class='img-link'

Mark Cain

- Original Message -
From: Jack Jackson [EMAIL PROTECTED]
To: php-general@lists.php.net
Sent: Sunday, June 05, 2005 4:37 PM
Subject: [PHP] looping through an array problem


 This is something dumb I am doing but:

 Trying to pull all names of publishers in db. This sql:

 SELECT art.art_id,art.publisher_id,publisher.publisher_name,
 FROM art
 LEFT JOIN publisher
 ON publisher.publisher_id=art.publisher_id

 pulls (in phpmyadmin) four rows:
artID  pubID Publisher_name
17   The New York Times: Sunday Styles
23   The New York Sun
32   Metro NY
43   The New York Sun


 I'm trying to make a sidebar which will make links to each unique
 publisher name:

 while ($cartoon = mysql_fetch_assoc($result)) {
   $pub_sidebar[] = ul class='sidebar-menu'a class='img-link'
 href='{$_SERVER['PHP_SELF']}?p={$cartoon['publisher_id']}'

title=\{$cartoon['publisher_name']}\{$cartoon['publisher_name']}/a/ul
;
}


 This prints:
The New York Times: Sunday Styles

The New York Sun

Metro NY

The New York Sun


 I'd like to stop the NY Sun from appearing twice! What have i missed here?

 Thanks in advance!

 --
 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



Re: [PHP] looping through an array problem

2005-06-05 Thread Paul Waring
On 6/5/05, Jack Jackson [EMAIL PROTECTED] wrote:
 I'd like to stop the NY Sun from appearing twice! What have i missed here?

There's nothing wrong with your PHP code as such (although you could
filter out duplicates there if you wanted), all you should need to do
is add the DISTINCT keyword to your SQL query on the appropriate colum
like so:

SELECT art.art_id,art.publisher_id, DISTINCT publisher.publisher_name,
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

I believe the DISTINCT keyword is part of the SQL standard, so it
should work on MySQL, Postgres etc.

Hope this helps.

Paul

-- 
Rogue Tory
http://www.roguetory.org.uk

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



Re: [PHP] looping through an array problem

2005-06-05 Thread Jochem Maas

Jack Jackson wrote:

This is something dumb I am doing but:

Trying to pull all names of publishers in db. This sql:



its a mysql question in disguise, maybe...:

SELECT DISTINCT art.art_id,art.publisher_id,publisher.publisher_name
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

on the other hand if you want to pull every article
from the DB then that won't do it. maybe you
need to be extracting the name of the article instead/aswell?

on the other hand if you are trying to display a list of
publishers, why are you selecting from the arts table?

SELECT p.publisher_id,p.publisher_name
FROM publisher p ORDER BY p publisher_id DESC

(maybe you only want to show publishers with listed 'art's?)

what does this do for you?:

SELECT COUNT(a.art_id) as art_count,a.publisher_id,p.publisher_name
FROM art a, publisher p
WHERE p.publisher_id=a.publisher_id
AND art_count  0
GROUP BY a.publisher_id


SELECT art.art_id,art.publisher_id,publisher.publisher_name,
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

pulls (in phpmyadmin) four rows:
  artID  pubID Publisher_name
  17   The New York Times: Sunday Styles
  23   The New York Sun
  32   Metro NY
  43   The New York Sun


I'm trying to make a sidebar which will make links to each unique 
publisher name:




and/or something like.:

?php

// $result   = DB::doMagic();

$seenAlready = array();
$templet = 'ul class=sidebar-menua class=img-link href='
 . $_SERVER['PHP_SELF']
 . '?p=%1$s title=%2$s%2$s/a/ul';

while ($cartoon = mysql_fetch_assoc($result)) {
if (in_array($cartoon['publisher_id'], $seenAlready))
continue;

$seenAlready[] = $cartoon['publisher_id'];
$pub_sidebar[] = sprintf($templet,
 $cartoon['publisher_id'],
 $cartoon['publisher_name']);
}


while ($cartoon = mysql_fetch_assoc($result)) {
 $pub_sidebar[] = ul class='sidebar-menu'a class='img-link' 
href='{$_SERVER['PHP_SELF']}?p={$cartoon['publisher_id']}' 
title=\{$cartoon['publisher_name']}\{$cartoon['publisher_name']}/a/ul; 


  }


This prints:
  The New York Times: Sunday Styles

  The New York Sun

  Metro NY

  The New York Sun


I'd like to stop the NY Sun from appearing twice! What have i missed here?

Thanks in advance!



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



Re: [PHP] looping through an array problem

2005-06-05 Thread Brian V Bonini
On Sun, 2005-06-05 at 16:37, Jack Jackson wrote:
 This is something dumb I am doing but:
 
 Trying to pull all names of publishers in db. This sql:
 
 SELECT art.art_id,art.publisher_id,publisher.publisher_name,
 FROM art
 LEFT JOIN publisher
 ON publisher.publisher_id=art.publisher_id
 
 pulls (in phpmyadmin) four rows:
artID  pubID Publisher_name
17   The New York Times: Sunday Styles
23   The New York Sun
32   Metro NY
43   The New York Sun
 
 
 I'm trying to make a sidebar which will make links to each unique 
 publisher name:
 
 while ($cartoon = mysql_fetch_assoc($result)) {
   $pub_sidebar[] = ul class='sidebar-menu'a class='img-link' 
 href='{$_SERVER['PHP_SELF']}?p={$cartoon['publisher_id']}' 
 title=\{$cartoon['publisher_name']}\{$cartoon['publisher_name']}/a/ul;
}
 
 
 This prints:
The New York Times: Sunday Styles
 
The New York Sun
 
Metro NY
 
The New York Sun
 
 
 I'd like to stop the NY Sun from appearing twice! What have i missed here?


SELECT DISTINCT publisher.publisher_name etc... ??


-- 

s/:-[(/]/:-)/g


BrianGnuPG - KeyID: 0x04A4F0DC | Key Server: pgp.mit.edu
==
gpg --keyserver pgp.mit.edu --recv-keys 04A4F0DC
Key Info: http://gfx-design.com/keys
Linux Registered User #339825 at http://counter.li.org

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



Re: [PHP] looping through an array problem

2005-06-05 Thread Jack Jackson
Thanks for all the replies. Jochem, thank you for this code, which will 
take me all night to understand (though I bet it works). I also note 
that SELECT DISTINCT worked here, too


Also as many of you noticed before me, the art_id was in there as a fly 
in the ointment.


Thanks all!



Jochem Maas wrote:

Jack Jackson wrote:


This is something dumb I am doing but:

Trying to pull all names of publishers in db. This sql:



its a mysql question in disguise, maybe...:

SELECT DISTINCT art.art_id,art.publisher_id,publisher.publisher_name
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_iduse, 


on the other hand if you want to pull every article
from the DB then that won't do it. maybe you
need to be extracting the name of the article instead/aswell?

on the other hand if you are trying to display a list of
publishers, why are you selecting from the arts table?

SELECT p.publisher_id,p.publisher_name
FROM publisher p ORDER BY p publisher_id DESC

(maybe you only want to show publishers with listed 'art's?)

what does this do for you?:

SELECT COUNT(a.art_id) as art_count,a.publisher_id,p.publisher_name
FROM art a, publisher p
WHERE p.publisher_id=a.publisher_id
AND art_count  0
GROUP BY a.publisher_id


SELECT art.art_id,art.publisher_id,publisher.publisher_name,
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

pulls (in phpmyadmin) four rows:
  artID  pubID Publisher_name
  17   The New York Times: Sunday Styles
  23   The New York Sun
  32   Metro NY
  43   The New York Sun


I'm trying to make a sidebar which will make links to each unique 
publisher name:




and/or something like.:

?php

// $result   = DB::doMagic();

$seenAlready = array();
$templet = 'ul class=sidebar-menua class=img-link href='
 . $_SERVER['PHP_SELF']
 . '?p=%1$s title=%2$s%2$s/a/ul';

while ($cartoon = mysql_fetch_assoc($result)) {
if (in_array($cartoon['publisher_id'], $seenAlready))
continue;

$seenAlready[] = $cartoon['publisher_id'];
$pub_sidebar[] = sprintf($templet,
 $cartoon['publisher_id'],
 $cartoon['publisher_name']);
}


while ($cartoon = mysql_fetch_assoc($result)) {
 $pub_sidebar[] = ul class='sidebar-menu'a class='img-link' 
href='{$_SERVER['PHP_SELF']}?p={$cartoon['publisher_id']}' 
title=\{$cartoon['publisher_name']}\{$cartoon['publisher_name']}/a/ul; 


  }


This prints:
  The New York Times: Sunday Styles

  The New York Sun

  Metro NY

  The New York Sun


I'd like to stop the NY Sun from appearing twice! What have i missed 
here?


Thanks in advance!







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



Re: [PHP] looping through an array problem

2005-06-05 Thread M. Sokolewicz

Jack Jackson wrote:
Thanks for all the replies. Jochem, thank you for this code, which will 
take me all night to understand (though I bet it works). I also note 
that SELECT DISTINCT worked here, too


Also as many of you noticed before me, the art_id was in there as a fly 
in the ointment.
by that statement I ment the exact same thing Jochem ment in his 2nd 
part; I have NO idea why you're selecting *ANYTHING* from the arts 
table... it's *useless* if you don't need the data...




Thanks all!



Jochem Maas wrote:


Jack Jackson wrote:


This is something dumb I am doing but:

Trying to pull all names of publishers in db. This sql:



its a mysql question in disguise, maybe...:

SELECT DISTINCT art.art_id,art.publisher_id,publisher.publisher_name
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_iduse,
on the other hand if you want to pull every article
from the DB then that won't do it. maybe you
need to be extracting the name of the article instead/aswell?

on the other hand if you are trying to display a list of
publishers, why are you selecting from the arts table?

SELECT p.publisher_id,p.publisher_name
FROM publisher p ORDER BY p publisher_id DESC

(maybe you only want to show publishers with listed 'art's?)

what does this do for you?:

SELECT COUNT(a.art_id) as art_count,a.publisher_id,p.publisher_name
FROM art a, publisher p
WHERE p.publisher_id=a.publisher_id
AND art_count  0
GROUP BY a.publisher_id


SELECT art.art_id,art.publisher_id,publisher.publisher_name,
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

pulls (in phpmyadmin) four rows:
  artID  pubID Publisher_name
  17   The New York Times: Sunday Styles
  23   The New York Sun
  32   Metro NY
  43   The New York Sun


I'm trying to make a sidebar which will make links to each unique 
publisher name:




and/or something like.:

?php

// $result   = DB::doMagic();

$seenAlready = array();
$templet = 'ul class=sidebar-menua class=img-link href='
 . $_SERVER['PHP_SELF']
 . '?p=%1$s title=%2$s%2$s/a/ul';

while ($cartoon = mysql_fetch_assoc($result)) {
if (in_array($cartoon['publisher_id'], $seenAlready))
continue;

$seenAlready[] = $cartoon['publisher_id'];
$pub_sidebar[] = sprintf($templet,
 $cartoon['publisher_id'],
 $cartoon['publisher_name']);
}


while ($cartoon = mysql_fetch_assoc($result)) {
 $pub_sidebar[] = ul class='sidebar-menu'a class='img-link' 
href='{$_SERVER['PHP_SELF']}?p={$cartoon['publisher_id']}' 
title=\{$cartoon['publisher_name']}\{$cartoon['publisher_name']}/a/ul; 


  }


This prints:
  The New York Times: Sunday Styles

  The New York Sun

  Metro NY

  The New York Sun


I'd like to stop the NY Sun from appearing twice! What have i missed 
here?


Thanks in advance!







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



Re: [PHP] looping through an array problem

2005-06-05 Thread Jack Jackson



M. Sokolewicz wrote:

Jack Jackson wrote:

Thanks for all the replies. Jochem, thank you for this code, which 
will take me all night to understand (though I bet it works). I also 
note that SELECT DISTINCT worked here, too


Also as many of you noticed before me, the art_id was in there as a 
fly in the ointment.


by that statement I ment the exact same thing Jochem ment in his 2nd 
part; I have NO idea why you're selecting *ANYTHING* from the arts 
table... it's *useless* if you don't need the data...


Er, yes, that was what I meant: I had unintentionally included that 
bit.Thank you for your help.


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



Re: [PHP] looping through an array problem

2005-06-05 Thread Jochem Maas

Jack Jackson wrote:



M. Sokolewicz wrote:


Jack Jackson wrote:

Thanks for all the replies. Jochem, thank you for this code, which 
will take me all night to understand (though I bet it works). I also 
note that SELECT DISTINCT worked here, too


Also as many of you noticed before me, the art_id was in there as a 
fly in the ointment.



by that statement I ment the exact same thing Jochem ment in his 2nd 
part; I have NO idea why you're selecting *ANYTHING* from the arts 
table... it's *useless* if you don't need the data...



Er, yes, that was what I meant: I had unintentionally included that 
bit.Thank you for your help.




Er, Jack - your original query was:

SELECT art.art_id,art.publisher_id,publisher.publisher_name,
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

which is a selection on the art table... ( with a typo)
if you did:

SELECT art.publisher_id,publisher.publisher_name
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

nothing would change. and if you did:

SELECT publisher.publisher_id,publisher.publisher_name
publisher

i.e. not 'unintentionally' selecting from the arts table.
then you would not have had a problem in the first place?!

I think I'm missing something ;-)

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



Re: [PHP] looping through an array problem

2005-06-05 Thread Jack Jackson
Forgive me if this comes twice: my ISP had a service blackout for three 
hours and I don't know what went:



If my last post read (and I see that it did) that I was defending myself
as opposed to falling ALL OVER my sword, I apologize: allow me to be clear:

No, you're all correct and M. Sokolewicz doubly so: I had
unintentionally selected fields from the wrong table for no reason other
than  lack of sleep coupled with lack of experience and a desperation to
try to understand

The problem was that I was pulling data in a manner both useless and
complex from a thoroughly unnecessary table (I could tell you all why
but you'll all just laugh at me more)

I am grateful for all the help everyone has offered up to now and hope I
did not offend  - I was trying in my last post to indicate that I  was
an idiot, and it appears I've come off as arrogant. I promise it was not
my intent!


[Then I wrote::]

Ah. I just remembered one reason I had done it involving the art_id field:

I have more publishers in the db than are currently associated with 
artworks. I don't want a publisher to appear unless there is at least 
one image associated with it. So I did this to avoid having people see a 
link to the Sneezy Acres Tribune only to arrive at the next page and 
see, There are no images associated with this publisher.




Jochem Maas wrote:

Jack Jackson wrote:




M. Sokolewicz wrote:


Jack Jackson wrote:

Thanks for all the replies. Jochem, thank you for this code, which 
will take me all night to understand (though I bet it works). I also 
note that SELECT DISTINCT worked here, too


Also as many of you noticed before me, the art_id was in there as a 
fly in the ointment.




by that statement I ment the exact same thing Jochem ment in his 2nd 
part; I have NO idea why you're selecting *ANYTHING* from the arts 
table... it's *useless* if you don't need the data...




Er, yes, that was what I meant: I had unintentionally included that 
bit.Thank you for your help.




Er, Jack - your original query was:

SELECT art.art_id,art.publisher_id,publisher.publisher_name,
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

which is a selection on the art table... ( with a typo)
if you did:

SELECT art.publisher_id,publisher.publisher_name
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

nothing would change. and if you did:

SELECT publisher.publisher_id,publisher.publisher_name
publisher

i.e. not 'unintentionally' selecting from the arts table.
then you would not have had a problem in the first place?!

I think I'm missing something ;-)



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



Re: [PHP] looping through an array problem

2005-06-05 Thread Jack Jackson

Ah. I just remembered one reason I had done it involving the art_id field:

I have more publishers in the db than are currently associated with 
artworks. I don't want a publisher to appear unless there is at least 
one image associated with it. So I did this to avoid having people see a 
link to the Sneezy Acres Tribune only to arrive at the next page and 
see, There are no images associated with this publisher.





Jochem Maas wrote:

Jack Jackson wrote:




M. Sokolewicz wrote:


Jack Jackson wrote:

Thanks for all the replies. Jochem, thank you for this code, which 
will take me all night to understand (though I bet it works). I also 
note that SELECT DISTINCT worked here, too


Also as many of you noticed before me, the art_id was in there as a 
fly in the ointment.




by that statement I ment the exact same thing Jochem ment in his 2nd 
part; I have NO idea why you're selecting *ANYTHING* from the arts 
table... it's *useless* if you don't need the data...




Er, yes, that was what I meant: I had unintentionally included that 
bit.Thank you for your help.




Er, Jack - your original query was:

SELECT art.art_id,art.publisher_id,publisher.publisher_name,
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

which is a selection on the art table... ( with a typo)
if you did:

SELECT art.publisher_id,publisher.publisher_name
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

nothing would change. and if you did:

SELECT publisher.publisher_id,publisher.publisher_name
publisher

i.e. not 'unintentionally' selecting from the arts table.
then you would not have had a problem in the first place?!

I think I'm missing something ;-)



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



Re: [PHP] looping through an array problem

2005-06-05 Thread Jack Jackson
If my last post read (and I see that it did) that I was defending myself 
as opposed to falling ALL OVER my sword, I apologize: allow me to be clear:


No, you're all correct and M. Sokolewicz doubly so: I had 
unintentionally selected fields from the wrong table for no reason other 
than  lack of sleep coupled with lack of experience and a desperation to 
try to understand


The problem was that I was pulling data in a manner both useless and 
complex from a thoroughly unnecessary table (I could tell you all why 
but you'll all just laugh at me more)


I am grateful for all the help everyone has offered up to now and hope I 
did not offend  - I was trying in my last post to indicate that I  was 
an idiot, and it appears I've come off as arrogant. I promise it was not 
my intent!






Jochem Maas wrote:

Jack Jackson wrote:




M. Sokolewicz wrote:


Jack Jackson wrote:

Thanks for all the replies. Jochem, thank you for this code, which 
will take me all night to understand (though I bet it works). I also 
note that SELECT DISTINCT worked here, too


Also as many of you noticed before me, the art_id was in there as a 
fly in the ointment.




by that statement I ment the exact same thing Jochem ment in his 2nd 
part; I have NO idea why you're selecting *ANYTHING* from the arts 
table... it's *useless* if you don't need the data...




Er, yes, that was what I meant: I had unintentionally included that 
bit.Thank you for your help.




Er, Jack - your original query was:

SELECT art.art_id,art.publisher_id,publisher.publisher_name,
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

which is a selection on the art table... ( with a typo)
if you did:

SELECT art.publisher_id,publisher.publisher_name
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

nothing would change. and if you did:

SELECT publisher.publisher_id,publisher.publisher_name
publisher

i.e. not 'unintentionally' selecting from the arts table.
then you would not have had a problem in the first place?!

I think I'm missing something ;-)



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



[PHP] Looping through results of pg_meta_data()

2004-10-22 Thread Ken Tozier
I'm trying to build an html table using the results from pg_meta_data() 
but none of the access functions seem to work. I am getting results but 
just can't seem to do anything with them.

Here's what I'm using to verify that results are being returned:
$connstring = dbname=pub_status user=postgres host=localhost 
port=5432;
$db = pg_connect($connstring);
$meta = pg_meta_data($db, 'table_definitions');
echo 'pre';
var_dump($meta);
echo '/pre';

Which yeilds:
array(2) {
  [field_id]=
  array(5) {
[num]=
int(1)
[type]=
string(4) int8
[len]=
int(8)
[not null]=
bool(true)
[has default]=
bool(true)
  }
  [field_name]=
  array(5) {
[num]=
int(2)
[type]=
string(4) text
[len]=
int(-1)
[not null]=
bool(true)
[has default]=
bool(false)
  }
}
But none of these seem to do anything:
$row_count = pg_num_rows($meta);
echo $row_count;
- result a blank web page
$row = pg_fetch_row($meta, 0);
echo $row;
- result a blank web page
$row = pg_fetch_array($meta, 0);
echo $row;
- result a blank web page
$row = pg_fetch_object($meta, 0);
echo $row;
- result a blank web page
What am I doing wrong?
Thanks for any help,
Ken
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] looping through an array

2004-04-04 Thread Jason Wong
On Sunday 04 April 2004 08:22, Andy B wrote:

[snip]

 i tried using while($_SESSION['guestbook']) but it proves in php's mind to
 be blank or that whole statement gets ignored...

The above doesn't make sense, if you don't have anything inside your 
while-loop which alters $_SESSION['guestbook'] then you're going to either 
(a) have a zero iteration while-loop, or (b) have an infinite loop.

If $_SESSION['guestbook'] contains an array use a foreach-loop. Or provide 
some more details.

-- 
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-general
--
/*
Don't hate me because I'm beautiful.  Hate me because I'm beautiful, smart 
and rich.
-- Calvin Keegan
*/

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



[PHP] looping through an array

2004-04-03 Thread Andy B
hi...

i have a combo box that is filled with a query from an sql table...

this is its logic:
if $_SESSION['guestbook'] doesnt exist
then query database, fill $_SESSION['guestbook'] with its values from the db, turn the 
value part of the option into the values from $_SESSION['guestbook']['Number'] and 
when done close the box...

if $_SESSION['guestbook'] already exists and is filled then use those existing values 
to do the above (fill the combobox)

the part i have the problem with is how to get $_SESSION['guestbook'] to do the above 
if it already exists...

i tried using while($_SESSION['guestbook']) but it proves in php's mind to be blank or 
that whole statement gets ignored...

help...



[PHP] looping variables from a file

2004-03-24 Thread Ryan A
Hi,
I have a config_inc.php file which has around 60 parameters set in it.
eg:
$db_name=something;
$db_user=root;
$db_pass=blah;
$x_installed_path=/home/blah/;
etc

I have a requirment of echoing out these statements to the client to show
him how his setup is:

eg:
echo DB_name=font color green.$db_name./font;

if I was getting variables via a POST or a GET I would use something like
this:

foreach ($_POST as $key = $val)
{ echo $key=font color green $value /font;}

as you can imagine the above loop will save a crapload of time instead of
partially hard codeing each key
and value but how do I do this while reading from a file? and the other big
problem is the file contains one or
two arrays...

Any ideas?

Thanks,
-Ryan

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



Re: [PHP] looping variables from a file

2004-03-24 Thread Richard Davey
Hello Ryan,

Wednesday, March 24, 2004, 5:29:33 PM, you wrote:

RA as you can imagine the above loop will save a crapload of time
RA instead of partially hard codeing each key and value but how do
RA I do this while reading from a file? and the other big problem is
RA the file contains one or two arrays...

Why not just suck in the contents of the file using file_get_contents
and they display the output? Perhaps using a regexp to search for the
= sign and anything on the left is the variable name?

-- 
Best regards,
 Richard Davey
 http://www.phpcommunity.org/wiki/296.html

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



Re: [PHP] looping variables from a file

2004-03-24 Thread John W. Holmes
From: Ryan A [EMAIL PROTECTED]

 I have a config_inc.php file which has around 60 parameters set in it.
 eg:
 $db_name=something;
 $db_user=root;
 $db_pass=blah;
 $x_installed_path=/home/blah/;
 etc

 I have a requirment of echoing out these statements to the client to show
 him how his setup is:

 eg:
 echo DB_name=font color green.$db_name./font;

One idea is to just fopen() the actual file (not the resulting PHP, which
will be empty), and do some str_replaces to add in the font tags, etc. The
rules for that could get tricky, though.

Another option is to use get_defined_vars() before you include the file
(saved into $array1), then save the results again after you include the file
and create the new variables (saved into $array2). Now use
array_diff($array2,$array1) to find the variables that were added. Now loop
through those with foreach() and apply the formatting.

Isn't PHP fun!?

---John Holmes...

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



RE: [PHP] looping variables from a file

2004-03-24 Thread Ford, Mike [LSS]
 -Original Message-
 From: Ryan A [mailto:[EMAIL PROTECTED] 
 Sent: 24 March 2004 17:30
 
 Hi,
 I have a config_inc.php file which has around 60 parameters set in it.
 eg:
 $db_name=something;
 $db_user=root;
 $db_pass=blah;
 $x_installed_path=/home/blah/;
 etc
 
 I have a requirment of echoing out these statements to the 
 client to show him how his setup is:
 
 eg:
 echo DB_name=font color green.$db_name./font;
 
 if I was getting variables via a POST or a GET I would use 
 something like
 this:
 
 foreach ($_POST as $key = $val)
 { echo $key=font color green $value /font;}
 
 as you can imagine the above loop will save a crapload of 
 time instead of partially hard codeing each key and value 
 but how do I do this while reading from a file? and the other 
 big problem is the file contains one or two arrays...

One possibility, if you're able to change the format of the config_inc file
without causing too much havoc, would be to write it something like this:

$CONFIG = array(
  'db_name' = 'something',
  'db_user' = 'root',
  'db_pass' = 'blah',
  'x_installed_path = '/home/blah/',
  ...
);

Then you have your array all neatly set up for you.  (And you can always
extract($CONFIG) whilst you convert all your other usages to $CONFIG[]...!!)

I do like John Holmes's solution, though!

As far as the arrays-within-the-array goes, this sounds like a perfect setup
for a recursive procedure.  If you write it to emit, say, an unordered list,
then each recursive call will produce a nested list and, hey presto!, you've
got nicely structured output too.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services, JG125, James
Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS,  LS6
3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211

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



Re: [PHP] looping variables from a file

2004-03-24 Thread John W. Holmes
Second what Rich said, keep replies to the list, please. This can benifit
everyone.

---John Holmes...

- Original Message - 
From: John W. Holmes [EMAIL PROTECTED]
To: Ryan A [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Wednesday, March 24, 2004 1:22 PM
Subject: Re: [PHP] looping variables from a file


 From: Ryan A [EMAIL PROTECTED]

  I knew this would be complicated when I started to write to the list for
  help but didnt know so
  complicatedI can just about understand (barely) what you guys are
  telling me but dont know
  where to start..can you give me some starting code example/s which I can
  build on?

 Sure...

 $array1 = get_defined_vars();
 include('yourfile.php');
 $array2 = get_defined_vars();

 $newvars = array_diff($array2,$array1);
 foreach($newvars as $name = $value)
 { echo $name = font color=\green\$value/fontbr /\n; }

 Actually, if you said there were arrays inside the include file, it may
get
 a little more complicated. If they are one dimensional arrays, you can
test
 $value with is_array() and maybe implode() the values into a string to
 display.

 if(is_array($value))
 { echo implode(',',$value); }
 else
 { echo $value; }

 If there are multi-dimensional arrays, then you'll need a recursive
 function. Have fun!

 ---John Holmes...

 PS: This is all assuming the user comments are correct and variables from
 include()'d files are captured by get_defined_vars().


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



Re: [PHP] looping variables from a file

2004-03-24 Thread Ryan A
Hey John,

 $array1 = get_defined_vars();
 include('yourfile.php');
 $array2 = get_defined_vars();

 $newvars = array_diff($array2,$array1);
 foreach($newvars as $name = $value)
 { echo $name = font color=\green\$value/fontbr /\n; }

Cool, thanks, will try it out.


 If there are multi-dimensional arrays, then
 you'll need a recursive
 function. Have fun!

Nope, I don't use multi-dimensional arrays unless absolutely no other way..
they get too complicated and gives me a headache when I try to understand
them
if I come back to the project after a long time
Definitely not my idea of fun.


 This is all assuming the user comments are correct and variables from
 include()'d
 files are captured by get_defined_vars().
Yep, will check that out, but it should..will write back to the list if it
does'nt.

Thanks again.

Cheers,
-Ryan

P.S I got the other script working where I force the download of a php file
while creating
the file dynimacally and not having the file on the server, works great.
Thanks for that idea too.
(Incase you dont remember, the subject of that was outputting php file)

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



[PHP] Looping problem?

2004-01-06 Thread Jas
require 'database.php';
$t_02 = subnets;
$sql_subs = mysql_query(SELECT * FROM $t_02,$db)or 
die(mysql_error());	 while(list($id,$sub,$msk,$dns01,$dns02,$rtrs,$rnge) 
= mysql_fetch_array($sql_subs)) {
   $num = mysql_num_rows($sql_subs);
  for($z = 0; $z  $num; $z++) {
	$vlans[] = subnet $subbrnetmask $msk {broption domain-name-servers 
$dns01, $dns02;broption routers $rtrs;brrange $rnge;br}br; }
}
// Write everything out formated...
echo $vlans[$z]br /\n;

Right now it only pulling the last record???
Jas
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Looping problem?

2004-01-06 Thread Brad Pauly
On Tue, 2004-01-06 at 15:04, Jas wrote:
 require 'database.php';
 $t_02 = subnets;
 $sql_subs = mysql_query(SELECT * FROM $t_02,$db)or 
 die(mysql_error());while(list($id,$sub,$msk,$dns01,$dns02,$rtrs,$rnge) 
 = mysql_fetch_array($sql_subs)) {
 $num = mysql_num_rows($sql_subs);
for($z = 0; $z  $num; $z++) {
   $vlans[] = subnet $subbrnetmask $msk {broption domain-name-servers 
 $dns01, $dns02;broption routers $rtrs;brrange $rnge;br}br; }
 }
 // Write everything out formated...
 echo $vlans[$z]br /\n;
 
 Right now it only pulling the last record???

You are only echo'ing the last record, $vlanz[$z]. You will need to loop
over $vlans again or put the echo line inside the for loop.

- Brad

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



RE: [PHP] Looping problem?

2004-01-06 Thread Martin Towell
This is probably more like what you need.
I can't see why you'd need to loop through your results using two different
methods (while and for)

require 'database.php';
$t_02 = subnets;
$sql_subs = mysql_query(SELECT * FROM $t_02,$db) or die(mysql_error());
$num = mysql_num_rows($sql_subs);
for ($z = 0; $z  $num; $z++)
{
  list($id, $sub, $msk, $dns01, $dns02, $rtrs, $rnge) =
mysql_fetch_array($sql_subs);
  $vlans[] = subnet $subbrnetmask $msk {broption domain-name-servers
$dns01, $dns02;broption routers $rtrs;brrange $rnge;br}br;
}
// Write everything out formated...
for ($z = 0; $z  $num; $z++)
  echo $vlans[$z]br /\n;


Martin


 -Original Message-
 From: Jas [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, 7 January 2004 9:05 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Looping problem?
 
 
 require 'database.php';
 $t_02 = subnets;
 $sql_subs = mysql_query(SELECT * FROM $t_02,$db)or 
 die(mysql_error());
 while(list($id,$sub,$msk,$dns01,$dns02,$rtrs,$rnge) 
 = mysql_fetch_array($sql_subs)) {
 $num = mysql_num_rows($sql_subs);
for($z = 0; $z  $num; $z++) {
   $vlans[] = subnet $subbrnetmask $msk {broption 
 domain-name-servers 
 $dns01, $dns02;broption routers $rtrs;brrange $rnge;br}br; }
 }
 // Write everything out formated...
 echo $vlans[$z]br /\n;
 
 Right now it only pulling the last record???
 Jas
 
 -- 
 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



Re: [PHP] Looping problem?

2004-01-06 Thread joel boonstra
On Wed, Jan 07, 2004 at 09:17:35AM +1100, Martin Towell wrote:
 This is probably more like what you need.
 I can't see why you'd need to loop through your results using two different
 methods (while and for)
 
 require 'database.php';
 $t_02 = subnets;
 $sql_subs = mysql_query(SELECT * FROM $t_02,$db) or die(mysql_error());
 $num = mysql_num_rows($sql_subs);
 for ($z = 0; $z  $num; $z++)
 {
   list($id, $sub, $msk, $dns01, $dns02, $rtrs, $rnge) =
 mysql_fetch_array($sql_subs);
   $vlans[] = subnet $subbrnetmask $msk {broption domain-name-servers
 $dns01, $dns02;broption routers $rtrs;brrange $rnge;br}br;
 }
 // Write everything out formated...
 for ($z = 0; $z  $num; $z++)
   echo $vlans[$z]br /\n;

No need to calculate the number of rows:

?php
require 'database.php';
$t_02 = subnets;
$sql_subs = mysql_query(SELECT * FROM $t_02,$db) 
  or die(mysql_error());
while (list($id, $sub, $msk, $dns01, $dns02, $rtrs, $rnge) =
 mysql_fetch_array($sql_subs)) {
  $tmp = subnet $subbrnetmask $msk {broption domain-name-servers
$dns01, $dns02;broption routers $rtrs;brrange $rnge;br}br;
  print $tmp;
  $vlans[] = $tmp;
}
?

I would recommend not simply doing a select *, but rather specifying
which columns you want.  That way, if your database schema changes
(e.g., you add two more columns), your code won't break.

joel

-- 
[ joel boonstra | gospelcom.net ]

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



Re: [PHP] Looping problem?

2004-01-06 Thread joel boonstra
On Tue, Jan 06, 2004 at 05:33:41PM -0500, joel boonstra wrote:
snip
 I would recommend not simply doing a select *, but rather specifying
 which columns you want.  That way, if your database schema changes
 (e.g., you add two more columns), your code won't break.

And, responding to myself, specifying your columns is also good practice
because MySQL makes no guarantees about the order that columns are
returned when you say SELECT *.  Today, it may well be the order that
you specified when you created your table.  With the next upgrade, it
may be alphabetical order, or by column type, or some other order that
the software chooses.  If you specify column names in your SELECT
statement, you don't need to worry about it.  This is especially
important when you are using list() to assign variables based on their
position in your fetched array.

joel

-- 
[ joel boonstra | gospelcom.net ]

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



[PHP] looping problem?

2003-12-30 Thread Jas
Problem with looping over a CSV file (3 results for each line)?  Here is 
the CSV file contents...

MTPC-01,00:02:B3:A2:9D:ED,155.97.15.11
MTPC-02,00:02:B3:A2:B6:F4,155.97.15.12
MTPC-03,00:02:B3:A2:A1:A7,155.97.15.13
MTPC-04,00:02:B3:A2:07:F2,155.97.15.14
MTPC-05,00:02:B3:A2:B8:4D,155.97.15.15
Here is the script...
?php
$row = 1;
$file = fa.csv;
$id = fopen($file,r);
  while($data = fgetcsv($id,100,,)) {
  $num = count($data);
  $row++;
for($c = 0; $c  $num; $c++) {
   echo host $data[0] {br /\nhardware ethernet $data[1];br 
/\nfixed-address $data[2];br /\n}br /\n; }
	}
fclose($id);
?

And this is the output...
(notice 3 results for the first line in the CSV file)
host MTPC-01 {
hardware ethernet 00:02:B3:A2:9D:ED;
fixed-address 155.97.15.11;
}
host MTPC-01 {
hardware ethernet 00:02:B3:A2:9D:ED;
fixed-address 155.97.15.11;
}
host MTPC-01 {
hardware ethernet 00:02:B3:A2:9D:ED;
fixed-address 155.97.15.11;
}
Any help is appreciated...
Jas
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] looping problem?

2003-12-30 Thread Mike Migurski
Problem with looping over a CSV file (3 results for each line)?

Here is the script...
?php
$row = 1;
$file = fa.csv;
$id = fopen($file,r);
   while($data = fgetcsv($id,100,,)) {
   $num = count($data);
   $row++;
 for($c = 0; $c  $num; $c++) {
echo host $data[0] {br /\nhardware ethernet $data[1];br
/\nfixed-address $data[2];br /\n}br /\n; }
   }
fclose($id);
?

Remove the for-loop on the 8th line.

-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html

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



Re: [PHP] looping problem?

2003-12-30 Thread Hitek
Shorter version of the script:
?
$line = file(fa.csv);
for($i=0;$icount($line);$i++){
$data = explode(,, $line[$i]);
echo host $data[0] {br /\nhardware ethernet $data[1];br 
/\nfixed-address $data[2];br /\n}br /\n;
}
?

At 08:10 AM 12/30/2003, Jas wrote:
Problem with looping over a CSV file (3 results for each line)?  Here is 
the CSV file contents...

MTPC-01,00:02:B3:A2:9D:ED,155.97.15.11
MTPC-02,00:02:B3:A2:B6:F4,155.97.15.12
MTPC-03,00:02:B3:A2:A1:A7,155.97.15.13
MTPC-04,00:02:B3:A2:07:F2,155.97.15.14
MTPC-05,00:02:B3:A2:B8:4D,155.97.15.15
Here is the script...
?php
$row = 1;
$file = fa.csv;
$id = fopen($file,r);
  while($data = fgetcsv($id,100,,)) {
  $num = count($data);
  $row++;
for($c = 0; $c  $num; $c++) {
   echo host $data[0] {br /\nhardware ethernet $data[1];br 
/\nfixed-address $data[2];br /\n}br /\n; }
}
fclose($id);
?

And this is the output...
(notice 3 results for the first line in the CSV file)
host MTPC-01 {
hardware ethernet 00:02:B3:A2:9D:ED;
fixed-address 155.97.15.11;
}
host MTPC-01 {
hardware ethernet 00:02:B3:A2:9D:ED;
fixed-address 155.97.15.11;
}
host MTPC-01 {
hardware ethernet 00:02:B3:A2:9D:ED;
fixed-address 155.97.15.11;
}
Any help is appreciated...
Jas
--
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] Looping through a list - Newbie question

2003-08-27 Thread James Johnson
Hi,

I have a list contained in a session var. I want to loop through the list,
getting the value of the current item, then do a query based on that value.
Is there an easy way to do this, or do I need to convert the list to an
array first? In the code below, $id isn't being set.

Here's my code (this is just testing stuff, sv_CampusList is set somewhere
else):
?php
session_start();
$_SESSION['sv_CampusList'] = 1,2,4,5; 
for($i=1; $i=strlen($_SESSION['sv_CampusList']); $i++){
$id = strpos($_SESSION['sv_CampusList'],$i);
echo $id;
}
?

Thanks,
James

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



RE: [PHP] Looping through a list - Newbie question

2003-08-27 Thread Javier Tacon
There are a lot of methods. The most common is using an array:

$_SESSION['sv_CampusList'] = Array (1,2,3,4,5);
foreach($_SESSION['sv_CampusList'] as $id) {
  echo $id;
}

If you want to use sv_CampusList as string:

$_SESSION['sv_CampusList'] = 1,2,4,5; 
$tmpArr = explode(,,$_SESSION['sv_CampusList']);
foreach($tmpArr as $id) {
  echo $id;
}


-Mensaje original-
De: James Johnson [mailto:[EMAIL PROTECTED]
Enviado el: miércoles, 27 de agosto de 2003 4:45
Para: [EMAIL PROTECTED]
Asunto: [PHP] Looping through a list - Newbie question


Hi,

I have a list contained in a session var. I want to loop through the list,
getting the value of the current item, then do a query based on that value.
Is there an easy way to do this, or do I need to convert the list to an
array first? In the code below, $id isn't being set.

Here's my code (this is just testing stuff, sv_CampusList is set somewhere
else):
?php
session_start();
$_SESSION['sv_CampusList'] = 1,2,4,5; 
for($i=1; $i=strlen($_SESSION['sv_CampusList']); $i++){
$id = strpos($_SESSION['sv_CampusList'],$i);
echo $id;
}
?

Thanks,
James

-- 
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



Re: [PHP] Looping through a list - Newbie question

2003-08-27 Thread CPT John W. Holmes
From: James Johnson [EMAIL PROTECTED]
 I have a list contained in a session var. I want to loop through the list,
 getting the value of the current item, then do a query based on that
value.
 Is there an easy way to do this, or do I need to convert the list to an
 array first? In the code below, $id isn't being set.

 Here's my code (this is just testing stuff, sv_CampusList is set somewhere
 else):
 ?php
 session_start();
 $_SESSION['sv_CampusList'] = 1,2,4,5;
 for($i=1; $i=strlen($_SESSION['sv_CampusList']); $i++){
 $id = strpos($_SESSION['sv_CampusList'],$i);
 echo $id;
 }
 ?

What are you actually trying to accomplish here? I could tell you how to
loop through a list in a string and run a query for each number, but I'd
have the horrible feeling that you're using some inefficient method to
accomplish something.

For instance, if you're just trying to select data matching the numbers in
your list, you can do this:

$query = SELECT * FROM Table WHERE campus_list IN
({$_SESSION['sv_CampusList']});

---John Holmes...

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



RE: [PHP] Looping through a list - Newbie question

2003-08-27 Thread James Johnson
I need to loop through a list that is generated by a select tag, so I can
query a lookup table. I managed to come up with this, 

?php
session_start();
$_SESSION['sv_CampusList'] = 1,2,4,5; // set elsewhere. Here for
demo/testing purposes
$lst= split(,,$_SESSION['sv_CampusList']);
foreach ($lst as $id){
print($idbr);
}
?

And have modified it to query the lookup table, then the main table. Seems
to work ok.

Thanks,
J

-Original Message-
From: CPT John W. Holmes [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, August 27, 2003 7:23 AM
To: James Johnson; [EMAIL PROTECTED]
Subject: Re: [PHP] Looping through a list - Newbie question


From: James Johnson [EMAIL PROTECTED]
 I have a list contained in a session var. I want to loop through the 
 list, getting the value of the current item, then do a query based on 
 that
value.
 Is there an easy way to do this, or do I need to convert the list to 
 an array first? In the code below, $id isn't being set.

 Here's my code (this is just testing stuff, sv_CampusList is set 
 somewhere
 else):
 ?php
 session_start();
 $_SESSION['sv_CampusList'] = 1,2,4,5;
 for($i=1; $i=strlen($_SESSION['sv_CampusList']); $i++){
 $id = strpos($_SESSION['sv_CampusList'],$i);
 echo $id;
 }
 ?

What are you actually trying to accomplish here? I could tell you how to
loop through a list in a string and run a query for each number, but I'd
have the horrible feeling that you're using some inefficient method to
accomplish something.

For instance, if you're just trying to select data matching the numbers in
your list, you can do this:

$query = SELECT * FROM Table WHERE campus_list IN
({$_SESSION['sv_CampusList']});

---John Holmes...

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



[PHP] Looping or what?

2003-07-09 Thread Zac Hillier - Net Affectors
The code below is suppose to replace some images and links but when I run it
the page just seems to hang and eventually times out.

Am I Looping somewhere and not realising it?

Thanks

Zac

$i = $c01_1;
$imgLst = '';

function imgRplc($val){
 global $imgLst;
 global $i;
 $imgLst .= div class=\figTtl\Fig. $i/divimg src=\$val[1]\ /,;

 return 'div class=fig(Fig.'.$i.')/div';
}

// first remove pics and add a reference to the end of the doc for those
that are required
while(preg_match(/img type=\reg\ src/,$disp)){

 $disp = preg_replace_callback(/img type=\reg\ src=\(.+)\ alt=(.+)
\//i, 'imgRplc', $disp,1);
 $i++;

}

// now remove all other pics
$disp = preg_replace(/img (.+) \//i, '', $disp);

// remove bigPic links  target=bigPic
$disp = preg_replace(/a (.+) target=\bigPic\(.+)\/a/i, '\\2',
$disp);

// next find shopping links and mark up
$disp = preg_replace(/a href=\(.+)\(.*)(.+)\/a/i, 'div
class=shpLnkLink to: \\3 (Enter into your browser:
http://www.lasersailing.com\\1)/div', $disp);

// remove paragraphs
$disp = preg_replace(/\/p(\s*)p/i, 'br /br /', $disp);
$disp = preg_replace(/p/i, '', $disp);
$disp = preg_replace(/\/p/i, '', $disp);

echo $disp;



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



Re: [PHP] Looping or what?

2003-07-09 Thread Jason Wong
On Wednesday 09 July 2003 21:12, Zac Hillier - Net Affectors wrote:
 The code below is suppose to replace some images and links but when I run
 it the page just seems to hang and eventually times out.

 Am I Looping somewhere and not realising it?

print $i to find out?

-- 
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-general
--
/*
FORTUNE'S RULES TO LIVE BY: #2
Never goose a wolverine.
*/


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



[PHP] looping through values from a field? Need hellp.

2003-07-05 Thread Micah Montoy
I have this javascript that enables browsing and selecting of a file.  This
file location and name are then transferred further down in the form as an
option.  Multiple files may be chosen as they are just added one below the
other.  Anyway, when the form is submitted it is only retrieving the last
file name from the form.  How can I get PHP to return all the values from
the select part.  Basically this is what is happening:

1.  Choose a file  input type=file name=viewing onchange=loadImg();
2. File location and name are displayed in the
select name=imgList style=width:350; size=6 multiple/select as
option value=c:\images\filename.gifc:\images\filename.gif/option
The javascript creates the option and a new option is added and appended
when a new file is chosen.
3. Submit form to php script to send location and stuff to database.

Anyone have any ideas of how I can get PHP to loop through and pull out each
option value?  They are separated by a comma.  Right now, it only grabs the
last file even though all files are highlighted before submission.

thanks



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



Re: [PHP] looping through values from a field? Need hellp.

2003-07-05 Thread Lars Torben Wilson
On Sat, 2003-07-05 at 15:55, Micah Montoy wrote:
 I have this javascript that enables browsing and selecting of a file.  This
 file location and name are then transferred further down in the form as an
 option.  Multiple files may be chosen as they are just added one below the
 other.  Anyway, when the form is submitted it is only retrieving the last
 file name from the form.  How can I get PHP to return all the values from
 the select part.  Basically this is what is happening:
 
 1.  Choose a file  input type=file name=viewing onchange=loadImg();
 2. File location and name are displayed in the
 select name=imgList style=width:350; size=6 multiple/select as
 option value=c:\images\filename.gifc:\images\filename.gif/option
 The javascript creates the option and a new option is added and appended
 when a new file is chosen.
 3. Submit form to php script to send location and stuff to database.
 
 Anyone have any ideas of how I can get PHP to loop through and pull out each
 option value?  They are separated by a comma.  Right now, it only grabs the
 last file even though all files are highlighted before submission.
 
 thanks


http://ca2.php.net/manual/en/faq.html.php#faq.html.select-multiple


Hope this helps,

Torben  

-- 
 Torben Wilson [EMAIL PROTECTED]+1.604.709.0506
 http://www.thebuttlesschaps.com  http://www.inflatableeye.com
 http://www.hybrid17.com  http://www.themainonmain.com
 - Boycott Starbucks!  http://www.haidabuckscafe.com -




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



Re: [PHP] looping through values from a field? Need hellp.

2003-07-05 Thread Micah Montoya
I think that will do it.

thanks,

- Original Message - 
From: Lars Torben Wilson [EMAIL PROTECTED]
To: Micah Montoy [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Saturday, July 05, 2003 4:59 PM
Subject: Re: [PHP] looping through values from a field? Need hellp.


 On Sat, 2003-07-05 at 15:55, Micah Montoy wrote:
  I have this javascript that enables browsing and selecting of a file.
This
  file location and name are then transferred further down in the form as
an
  option.  Multiple files may be chosen as they are just added one below
the
  other.  Anyway, when the form is submitted it is only retrieving the
last
  file name from the form.  How can I get PHP to return all the values
from
  the select part.  Basically this is what is happening:
 
  1.  Choose a file  input type=file name=viewing
onchange=loadImg();
  2. File location and name are displayed in the
  select name=imgList style=width:350; size=6 multiple/select as
  option value=c:\images\filename.gifc:\images\filename.gif/option
  The javascript creates the option and a new option is added and appended
  when a new file is chosen.
  3. Submit form to php script to send location and stuff to database.
 
  Anyone have any ideas of how I can get PHP to loop through and pull out
each
  option value?  They are separated by a comma.  Right now, it only grabs
the
  last file even though all files are highlighted before submission.
 
  thanks


 http://ca2.php.net/manual/en/faq.html.php#faq.html.select-multiple


 Hope this helps,

 Torben

 -- 
  Torben Wilson [EMAIL PROTECTED]+1.604.709.0506
  http://www.thebuttlesschaps.com  http://www.inflatableeye.com
  http://www.hybrid17.com  http://www.themainonmain.com
  - Boycott Starbucks!  http://www.haidabuckscafe.com -







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



RE: [PHP] looping through values from a field? Need hellp.

2003-07-05 Thread Giz
Yeah, this is the behavior of select lists.  What comes through in the form
post is the item that was last selected.  

What I've found you have to do with javascript is populate a hidden field
with the values, using some delimiter (I've used commas) and you can easily
explode those values into an array in the processing script.

In your form have an onsubmit like this:

onSubmit=SetList2Values(this.yourlist,this.list2values)

(change list2values to the hidden field you define for this purpose.

Here's the javascript function list2values I use:

echo function SetList2Values(box,list2values)  {\n;
echo var t = \\;;
echo for(var i=0; ibox.options.length; i++) {\n;
echo if(box.options[i].value != \\) {\n;
echo t = t + box.options[i].value + \,\;\n;
echo   }\n;
echo}\n;
echo list2values.value = t;;
echo return true;}\n;

echo // End --\n;
echo /script\n;


In the post script I have:

$rListvalues = explode(,, $_POST['list2values']);

foreach through that and do your processing.

-Original Message-
From: Micah Montoy [mailto:[EMAIL PROTECTED] 
Sent: Saturday, July 05, 2003 3:56 PM
To: [EMAIL PROTECTED]
Subject: [PHP] looping through values from a field? Need hellp.


1.  Choose a file  input type=file name=viewing onchange=loadImg();
2. File location and name are displayed in the
select name=imgList style=width:350; size=6 multiple/select as
option value=c:\images\filename.gifc:\images\filename.gif/option
The javascript creates the option and a new option is added and appended
when a new file is chosen.
3. Submit form to php script to send location and stuff to database.

Anyone have any ideas of how I can get PHP to loop through and pull out each
option value?  They are separated by a comma.  Right now, it only grabs the
last file even though all files are highlighted before submission.




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



Re: [PHP] looping through values from a field? Need hellp.

2003-07-05 Thread Micah Montoya
Ok.  I gave it a shot but have run into one other question that I wasn't
able to find that was addressed by the article.

My select statement looks like this:

select name=imgList[] style=width:350; size=6 multiple/select

When I create the php file, I am trying something like below but it isn't
working and I am receiving an error.  What am I not doing?

$filename = $_POST[imgList];

for each ($filename as $value) {
 echo $value;
}

thanks



- Original Message - 
From: Lars Torben Wilson [EMAIL PROTECTED]
To: Micah Montoy [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Saturday, July 05, 2003 4:59 PM
Subject: Re: [PHP] looping through values from a field? Need hellp.


 On Sat, 2003-07-05 at 15:55, Micah Montoy wrote:
  I have this javascript that enables browsing and selecting of a file.
This
  file location and name are then transferred further down in the form as
an
  option.  Multiple files may be chosen as they are just added one below
the
  other.  Anyway, when the form is submitted it is only retrieving the
last
  file name from the form.  How can I get PHP to return all the values
from
  the select part.  Basically this is what is happening:
 
  1.  Choose a file  input type=file name=viewing
onchange=loadImg();
  2. File location and name are displayed in the
  select name=imgList style=width:350; size=6 multiple/select as
  option value=c:\images\filename.gifc:\images\filename.gif/option
  The javascript creates the option and a new option is added and appended
  when a new file is chosen.
  3. Submit form to php script to send location and stuff to database.
 
  Anyone have any ideas of how I can get PHP to loop through and pull out
each
  option value?  They are separated by a comma.  Right now, it only grabs
the
  last file even though all files are highlighted before submission.
 
  thanks


 http://ca2.php.net/manual/en/faq.html.php#faq.html.select-multiple


 Hope this helps,

 Torben

 -- 
  Torben Wilson [EMAIL PROTECTED]+1.604.709.0506
  http://www.thebuttlesschaps.com  http://www.inflatableeye.com
  http://www.hybrid17.com  http://www.themainonmain.com
  - Boycott Starbucks!  http://www.haidabuckscafe.com -







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



Re: [PHP] looping through values from a field? Need hellp.

2003-07-05 Thread Lars Torben Wilson
On Sat, 2003-07-05 at 17:13, Micah Montoya wrote:
 Ok.  I gave it a shot but have run into one other question that I wasn't
 able to find that was addressed by the article.
 
 My select statement looks like this:
 
 select name=imgList[] style=width:350; size=6 multiple/select
 
 When I create the php file, I am trying something like below but it isn't
 working and I am receiving an error.  What am I not doing?
 
 $filename = $_POST[imgList];
 
 for each ($filename as $value) {
  echo $value;
 }
 
 thanks

Impossible to say without know what the error says. :) Anyway, if that
code is cut-and-pasted, then 'foreach' should have no space in it. That
would cause a parse error. Otherwise, you could be getting a Notice
if you're actually passing something in via method=GET but checking
the $_POST array instead.



-- 
 Torben Wilson [EMAIL PROTECTED]+1.604.709.0506
 http://www.thebuttlesschaps.com  http://www.inflatableeye.com
 http://www.hybrid17.com  http://www.themainonmain.com
 - Boycott Starbucks!  http://www.haidabuckscafe.com -




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



Re: [PHP] looping through values from a field? Need hellp.

2003-07-05 Thread Micah Montoya
That was the trick.  Just the space was messing things up.  Thanks.


- Original Message - 
From: Lars Torben Wilson [EMAIL PROTECTED]
To: Micah Montoya [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Saturday, July 05, 2003 6:18 PM
Subject: Re: [PHP] looping through values from a field? Need hellp.


 On Sat, 2003-07-05 at 17:13, Micah Montoya wrote:
  Ok.  I gave it a shot but have run into one other question that I wasn't
  able to find that was addressed by the article.
 
  My select statement looks like this:
 
  select name=imgList[] style=width:350; size=6 multiple/select
 
  When I create the php file, I am trying something like below but it
isn't
  working and I am receiving an error.  What am I not doing?
 
  $filename = $_POST[imgList];
 
  for each ($filename as $value) {
   echo $value;
  }
 
  thanks

 Impossible to say without know what the error says. :) Anyway, if that
 code is cut-and-pasted, then 'foreach' should have no space in it. That
 would cause a parse error. Otherwise, you could be getting a Notice
 if you're actually passing something in via method=GET but checking
 the $_POST array instead.



 -- 
  Torben Wilson [EMAIL PROTECTED]+1.604.709.0506
  http://www.thebuttlesschaps.com  http://www.inflatableeye.com
  http://www.hybrid17.com  http://www.themainonmain.com
  - Boycott Starbucks!  http://www.haidabuckscafe.com -







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



[PHP] Looping through the mysql_field_name function

2003-02-02 Thread Davy Obdam
Hi ppl,

I have a problem that probably very simple, but i cannot figure it out 
right now
I need to get the field names of my database. I have a query like select 
* from books and now i wanna have both the result and the field name. I 
have been trying with mysql_field_name, but not succesfully...

$i = 0;
for($a=0; $a  sizeof(mysql_field_name($db-sqlResult, $i)); $a++) {
   echo mysql_field_name($db-sqlResult, $i).br /;
   $i++;
}

Can anyone help me please.. Your help is greatly appreciated;-)

Best regards,

Davy Obdam
mailto:[EMAIL PROTECTED]



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



Re: [PHP] Looping through the mysql_field_name function

2003-02-02 Thread Philip Olson
On Sun, 2 Feb 2003, Davy Obdam wrote:

 Hi ppl,
 
 I have a problem that probably very simple, but i cannot figure it out 
 right now
 I need to get the field names of my database. I have a query like select 
 * from books and now i wanna have both the result and the field name. I 
 have been trying with mysql_field_name, but not succesfully...
 
 $i = 0;
 for($a=0; $a  sizeof(mysql_field_name($db-sqlResult, $i)); $a++) {
 echo mysql_field_name($db-sqlResult, $i).br /;
 $i++;
 }
 
 Can anyone help me please.. Your help is greatly appreciated;-)

Please read the example in the manual as well as the user
contributed notes.  They show how to do this:

  http://www.php.net/mysql_field_name

See also: mysql_num_fields()

Regards,
Philip


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




[PHP] Looping through directories?

2003-01-08 Thread Jeff Lewis
Currently I have a script that reads an index file and from that index file it then 
loops through all files in that directory based on the index.

Instead of one directory now I have several and I want to loop through each directory 
and go to each directory's index file. Since there is no pattern for the name if the 
indexes, I assume I need to create an array holding the directory name and the 
associated index file name like so $dirs = array(Sports = spindex.xml, Business 
News = business.xml) etc

Now, I need help with the loop to whip through each directory. Would I do a foreach on 
the array I just created? Any help would be greatly appreciated. I need to be able to 
access both the directory name and index name.

Jeff



Re: [PHP] Looping through directories?

2003-01-08 Thread Chris Wesley
On Wed, 8 Jan 2003, Jeff Lewis wrote:

 pattern for the name if the indexes, I assume I need to create an array
 holding the directory name and the associated index file name like so
 $dirs = array(Sports = spindex.xml, Business News =
 business.xml) etc

 Now, I need help with the loop to whip through each directory. Would I
 do a foreach on the array I just created? Any help would be greatly
 appreciated. I need to be able to access both the directory name and
 index name.

foreach() would work for you ...

foreach( $dirs as $dirName = $indexName ){
$indexPath = ${dirName}/${indexName};
$fh = fopen( $indexPath, r );
// ...
fclose( $fh );
// I'm just guessing; do whatever you want in this loop
}

hth,
~Chris


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




[PHP] Looping needs to re-open parm file

2002-12-19 Thread Jacob van Zanen
Hi All,

I'm reading a paramter file and a text file.
Per line of the text file I want to check if there is a word in there from
the parameter file.
However I need to open and read the parameter file for each line in the text
file. How can I change this?

Followin is the code I have.


?

if (!($FileContent = file(d:\MyPhp\\test.ora)))
{
 Print (File could not be opened);
 exit;
}
while (list ($LineNum, $Line) = each ($FileContent))
{
 // Open an ini file
 if (!($IniContent = file(d:\MyPhp\initORA.ini)))
 {
  Print (File could not be opened);
  exit;
 }
 while (list($KeyNum, $IniParm) = each($IniContent))
 {
  if (strstr($Line,rtrim($IniParm)))
 {
  print ($LineBR\n);
 }
 }
}
?



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




Re: [PHP] Looping needs to re-open parm file

2002-12-19 Thread Wico de Leeuw
Did you look at:
http://www.php.net/manual/en/function.file.php
Puts all lines in an array

Gr,

At 12:00 19-12-02 +0100, Jacob van Zanen wrote:

Hi All,

I'm reading a paramter file and a text file.
Per line of the text file I want to check if there is a word in there from
the parameter file.
However I need to open and read the parameter file for each line in the text
file. How can I change this?

Followin is the code I have.


?

if (!($FileContent = file(d:\MyPhp\\test.ora)))
{
 Print (File could not be opened);
 exit;
}
while (list ($LineNum, $Line) = each ($FileContent))
{
 // Open an ini file
 if (!($IniContent = file(d:\MyPhp\initORA.ini)))
 {
  Print (File could not be opened);
  exit;
 }
 while (list($KeyNum, $IniParm) = each($IniContent))
 {
  if (strstr($Line,rtrim($IniParm)))
 {
  print ($LineBR\n);
 }
 }
}
?



--
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




Re: [PHP] Looping needs to re-open parm file

2002-12-19 Thread Wico de Leeuw
Hiya

something like this
?
if ($FileContent = file(d:\MyPhp\\test.ora) AND $IniContent = 
file(d:\MyPhp\initORA.ini)) {
foreach($FileContent AS $line) {
if (in_array($line, $iniContent)) {
 echo $LineBR\n;
}
}
}
?

At 12:00 19-12-02 +0100, Jacob van Zanen wrote:
Hi All,

I'm reading a paramter file and a text file.
Per line of the text file I want to check if there is a word in there from
the parameter file.
However I need to open and read the parameter file for each line in the text
file. How can I change this?

Followin is the code I have.


?

if (!($FileContent = file(d:\MyPhp\\test.ora)))
{
 Print (File could not be opened);
 exit;
}
while (list ($LineNum, $Line) = each ($FileContent))
{
 // Open an ini file
 if (!($IniContent = file(d:\MyPhp\initORA.ini)))
 {
  Print (File could not be opened);
  exit;
 }
 while (list($KeyNum, $IniParm) = each($IniContent))
 {
  if (strstr($Line,rtrim($IniParm)))
 {
  print ($LineBR\n);
 }
 }
}
?



--
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




RE: [PHP] Looping needs to re-open parm file

2002-12-19 Thread John W. Holmes
 I'm reading a paramter file and a text file.
 Per line of the text file I want to check if there is a word in there
from
 the parameter file.
 However I need to open and read the parameter file for each line in
the
 text
 file. How can I change this?

Can't you read the param file first into an array, and then loop through
the text file, using in_array() to see if a line matches a param?

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



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




[PHP] Looping through Form Elements in a form

2002-12-11 Thread Steve Vernon
Hiya,
I am working on a generic JavaScript form checked, that takes the names
of the elements, with the first two letters being the type of element, so
its checks that it is right, if not gives a generic error message e.g. YOu
Need To Fill this in and selects it, or Sorry only numbers are allowed in
this box or Email addresses only, so reemail could mean a field which is
required and an email address. .

   JavaScript as long as you have a link to the object of the form, gives
the elements in an array. Is there a way to do this in PHP? Have a form with
the action something like
register.php?action=updatemembers with members being a table name. The
elements would be checked like JavaScripts checks them. Ok I would need to
then set the order and manually do the call to the database, but it would be
nice not to have to do the manuual checks on the elements.

So a function to check all the elements in a form in PHP would be nice,
then if it fails it would return an array with the wrong fields, and the
error, this could then be used to make a page where they correct there
mistakes.

Thanks!

Love,

Steve




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




Re: [PHP] Looping through Form Elements in a form

2002-12-11 Thread Jason Wong
On Thursday 12 December 2002 04:13, Steve Vernon wrote:
 Hiya,
 I am working on a generic JavaScript form checked, that takes the names
 of the elements, with the first two letters being the type of element, so
 its checks that it is right, if not gives a generic error message e.g. YOu
 Need To Fill this in and selects it, or Sorry only numbers are allowed in
 this box or Email addresses only, so reemail could mean a field which is
 required and an email address. .

JavaScript as long as you have a link to the object of the form, gives
 the elements in an array. Is there a way to do this in PHP? Have a form
 with the action something like
 register.php?action=updatemembers with members being a table name. The
 elements would be checked like JavaScripts checks them. Ok I would need to
 then set the order and manually do the call to the database, but it would
 be nice not to have to do the manuual checks on the elements.

 So a function to check all the elements in a form in PHP would be nice,
 then if it fails it would return an array with the wrong fields, and the
 error, this could then be used to make a page where they correct there
 mistakes.

There are some classes in www.phpclasses.org which helps you validate forms.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
An open mind has but one disadvantage: it collects dirt.
-- a saying at RPI
*/


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




RE: [PHP] Looping through Form Elements in a form

2002-12-11 Thread John W. Holmes
 I am working on a generic JavaScript form checked, that takes the
 names
 of the elements, with the first two letters being the type of element,
so
 its checks that it is right, if not gives a generic error message e.g.
YOu
 Need To Fill this in and selects it, or Sorry only numbers are allowed
in
 this box or Email addresses only, so reemail could mean a field which
is
 required and an email address. .
 
JavaScript as long as you have a link to the object of the form,
gives
 the elements in an array. Is there a way to do this in PHP? Have a
form
 with
 the action something like
 register.php?action=updatemembers with members being a table name.
The
 elements would be checked like JavaScripts checks them. Ok I would
need to
 then set the order and manually do the call to the database, but it
would
 be
 nice not to have to do the manuual checks on the elements.
 
 So a function to check all the elements in a form in PHP would be
 nice,
 then if it fails it would return an array with the wrong fields, and
the
 error, this could then be used to make a page where they correct there
 mistakes.

I don't really understand what your question is, but I wouldn't
recommend this method. What's to stop me from downloading your form,
editing the name of the form elements and having you correctly validate
some text when you normally think it's going to be a number? It all
depends on how you implement your form, but it can be easily exploited
if you don't know what you're doing. 

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



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




RE: [PHP] Looping Addition

2002-12-06 Thread Ford, Mike [LSS]
- Original Message -
From: Chris Wesley [EMAIL PROTECTED]
To: PHP List [EMAIL PROTECTED]

 On Wed, 4 Dec 2002, Stephen wrote:
  This is only a snippet, there is more to it but for simplicities
sake...
  Then I calculate it. My question is, how would I loop the adding? I
hope
you
  understand this now...

 Ah!, I think I understand better now.  You want to add num1, num2,
num3,
 ... numN, which are inputs from the second form in your sequence.
Gotcha.

 If you name /all/ the form elements as nums[] instead of
individually as
 num${current}, the numbers put into the form will all be accessible
in
 one array to the PHP script that does the adding.  Then you can just
loop
 over the array of numbers.

 In your second form, change this:
 input name=num?php echo $current; ? type=text id=vars
value=0
  size=25

 To this:
 input name=nums[] type=text id=vars value=0 size=25

 Then in the script that adds the numbers:
 $total = 0;
 foreach( $_POST['nums'] as $number ){
 $total += $number;
 }

Or even $total = array_sum($_POST['nums'])

Cheers!

Mike

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




Re: [PHP] Looping Addition

2002-12-05 Thread Stephen
One more question... If I then wanted to do this for the other operations
(such as multiplication, division, etc), how would I do that?


- Original Message -
From: John W. Holmes [EMAIL PROTECTED]
To: 'Stephen' [EMAIL PROTECTED]; 'Chris Wesley'
[EMAIL PROTECTED]
Cc: 'PHP List' [EMAIL PROTECTED]
Sent: Wednesday, December 04, 2002 9:01 PM
Subject: RE: [PHP] Looping Addition


  Let me explain this as best I can. The user enters how many numbers he
  wants
  to add. This form goes to another page. This page loops a form field
 and
  it's name is num and after num is the number it is currently on.
 Here's
  the code:
 
form name=add method=post action=?php $_SERVER['PHP_SELF'];
 ?
  tr
td width=35%How many numbers to add:/td
tdinput name=vars type=text id=vars value=2 size=10
  maxlength=2/td
  /tr
  tr
td colspan=2div align=center
input name=submit type=submit id=submit value=Next
  gt;
  /div/td
  /tr
/form
  ?php
   }
   else
   {
if(!is_numeric($_POST['vars']) || $_POST['vars'] = 1)
{
 echo a href=\javascript:history.back(-1)\Go back/a and enter
 a
  number or something greater then 1. DO NOT enter a letter or symbol.;
}
else
{
  ?
  form name=add action=module.php?id=?php echo
 $HTTP_GET_VARS['id'];
  ?show=calculate method=post
  input type=hidden name=vars value=?php echo $_POST['vars'];
 ?
  ?php
   $current = 1;
   do
   {
  ?
  tr
td width=35%?php echo Number .$current.:; ?/td
tdinput name=num?php echo $current; ? type=text
 id=vars
  value=0 size=25/td
  /tr
  ?php
   $current++;
   } while($current = $_POST['vars'])
  ?

 Change the above to:

 ?php
 for($x=0;$x$_POST['vars'];$x++)
 {
   ?
 tr
 td width=35%Number ?php echo $x; ?:/td
 tdinput name=num[] type=text id=vars value=0 size=25/td
 ?php } ?

  tr
td colspan=2div align=center
input name=add type=submit id=add value=Next gt;
  /div/td
  /tr
  /form
 
  This is only a snippet, there is more to it but for simplicities
 sake...
  Then I calculate it. My question is, how would I loop the adding? I
 hope
  you
  understand this now...

 And to do the addition...

 $sum = array_sum($_POST['num']);

 ---John Holmes...





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




Re: [PHP] Looping Addition

2002-12-05 Thread 1LT John W. Holmes
 One more question... If I then wanted to do this for the other operations
 (such as multiplication, division, etc), how would I do that?

Assuming you've figured out how to do an array...

You'll have to loop through the values like in the code that others posted.

foreach($_POST['number'] as $num)
{ //calculate total here with $num }

* = multiplication
/ = divide

---John Holmes...




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




Re: [PHP] Looping Addition

2002-12-05 Thread Stephen
So would I just put this?

foreach(%_POST['number'] as $num)
{
$output *= $num;
}
echo $output;

That's for multiplication.


- Original Message -
From: 1LT John W. Holmes [EMAIL PROTECTED]
To: Stephen [EMAIL PROTECTED]
Cc: PHP List [EMAIL PROTECTED]
Sent: Thursday, December 05, 2002 8:24 AM
Subject: Re: [PHP] Looping Addition


  One more question... If I then wanted to do this for the other
operations
  (such as multiplication, division, etc), how would I do that?

 Assuming you've figured out how to do an array...

 You'll have to loop through the values like in the code that others
posted.

 foreach($_POST['number'] as $num)
 { //calculate total here with $num }

 * = multiplication
 / = divide

 ---John Holmes...




 --
 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




Re: [PHP] Looping Addition

2002-12-05 Thread Jason Wong
On Thursday 05 December 2002 23:05, Stephen wrote:
 So would I just put this?

 foreach(%_POST['number'] as $num)
 {
 $output *= $num;
 }
 echo $output;

 That's for multiplication.

Yes. Wouldn't it have been quicker for you to try it than to ask?

BTW make sure that none of $num is zero.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
The longest part of the journey is said to be the passing of the gate.
-- Marcus Terentius Varro
*/


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




Re: [PHP] Looping Addition

2002-12-05 Thread Stephen
Continuing this even more...how would I use this same method only to
subtract?

What I'm doing right now would result in the following sitution.

The user types in 5 as their first number. The second number is 4. Instead
of returnin 1, it returns -9. It's subtracting the first number from 0, then
taking 4 and subtracting that from -5. How can I fix this keeping in mind
the user may type in more then two numbers?


- Original Message -
From: Chris Wesley [EMAIL PROTECTED]
To: PHP List [EMAIL PROTECTED]
Cc: Stephen [EMAIL PROTECTED]
Sent: Wednesday, December 04, 2002 8:42 PM
Subject: Re: [PHP] Looping Addition


 On Wed, 4 Dec 2002, Stephen wrote:
  This is only a snippet, there is more to it but for simplicities sake...
  Then I calculate it. My question is, how would I loop the adding? I hope
you
  understand this now...

 Ah!, I think I understand better now.  You want to add num1, num2, num3,
 ... numN, which are inputs from the second form in your sequence.  Gotcha.

 If you name /all/ the form elements as nums[] instead of individually as
 num${current}, the numbers put into the form will all be accessible in
 one array to the PHP script that does the adding.  Then you can just loop
 over the array of numbers.

 In your second form, change this:
 input name=num?php echo $current; ? type=text id=vars value=0
  size=25

 To this:
 input name=nums[] type=text id=vars value=0 size=25

 Then in the script that adds the numbers:
 $total = 0;
 foreach( $_POST['nums'] as $number ){
 $total += $number;
 }

 Hopefully I understood your problem this time!  Let me know if I missed
 again.
 g.luck,
 ~Chris




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




Re: [PHP] Looping Addition

2002-12-05 Thread Kevin Stone
You simply need the absolute value of the difference.  So taking Stephen's
example below..

$total = 0;
foreach( $_POST['nums'] as $number )
{
  $total -= $number;// if users inputs 5 as first value result equals -5
  $total = abs($total); // result now equals 5
}


- Original Message -
From: Stephen [EMAIL PROTECTED]
To: Chris Wesley [EMAIL PROTECTED]
Cc: PHP List [EMAIL PROTECTED]
Sent: Thursday, December 05, 2002 12:33 PM
Subject: Re: [PHP] Looping Addition


 Continuing this even more...how would I use this same method only to
 subtract?

 What I'm doing right now would result in the following sitution.

 The user types in 5 as their first number. The second number is 4. Instead
 of returnin 1, it returns -9. It's subtracting the first number from 0,
then
 taking 4 and subtracting that from -5. How can I fix this keeping in mind
 the user may type in more then two numbers?


 - Original Message -
 From: Chris Wesley [EMAIL PROTECTED]
 To: PHP List [EMAIL PROTECTED]
 Cc: Stephen [EMAIL PROTECTED]
 Sent: Wednesday, December 04, 2002 8:42 PM
 Subject: Re: [PHP] Looping Addition


  On Wed, 4 Dec 2002, Stephen wrote:
   This is only a snippet, there is more to it but for simplicities
sake...
   Then I calculate it. My question is, how would I loop the adding? I
hope
 you
   understand this now...
 
  Ah!, I think I understand better now.  You want to add num1, num2, num3,
  ... numN, which are inputs from the second form in your sequence.
Gotcha.
 
  If you name /all/ the form elements as nums[] instead of individually
as
  num${current}, the numbers put into the form will all be accessible in
  one array to the PHP script that does the adding.  Then you can just
loop
  over the array of numbers.
 
  In your second form, change this:
  input name=num?php echo $current; ? type=text id=vars
value=0
   size=25
 
  To this:
  input name=nums[] type=text id=vars value=0 size=25
 
  Then in the script that adds the numbers:
  $total = 0;
  foreach( $_POST['nums'] as $number ){
  $total += $number;
  }
 
  Hopefully I understood your problem this time!  Let me know if I missed
  again.
  g.luck,
  ~Chris
 
 


 --
 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




Re: [PHP] Looping Addition

2002-12-05 Thread Stephen
But then, if the user entered 5 - 6, it should be -1 but it'd return
positive one... Is there another way?


- Original Message -
From: Kevin Stone [EMAIL PROTECTED]
To: Stephen [EMAIL PROTECTED]; Chris Wesley [EMAIL PROTECTED]
Cc: PHP List [EMAIL PROTECTED]
Sent: Thursday, December 05, 2002 2:51 PM
Subject: Re: [PHP] Looping Addition


 You simply need the absolute value of the difference.  So taking Stephen's
 example below..

 $total = 0;
 foreach( $_POST['nums'] as $number )
 {
   $total -= $number;// if users inputs 5 as first value result
equals -5
   $total = abs($total); // result now equals 5
 }


 - Original Message -
 From: Stephen [EMAIL PROTECTED]
 To: Chris Wesley [EMAIL PROTECTED]
 Cc: PHP List [EMAIL PROTECTED]
 Sent: Thursday, December 05, 2002 12:33 PM
 Subject: Re: [PHP] Looping Addition


  Continuing this even more...how would I use this same method only to
  subtract?
 
  What I'm doing right now would result in the following sitution.
 
  The user types in 5 as their first number. The second number is 4.
Instead
  of returnin 1, it returns -9. It's subtracting the first number from 0,
 then
  taking 4 and subtracting that from -5. How can I fix this keeping in
mind
  the user may type in more then two numbers?
 
 
  - Original Message -
  From: Chris Wesley [EMAIL PROTECTED]
  To: PHP List [EMAIL PROTECTED]
  Cc: Stephen [EMAIL PROTECTED]
  Sent: Wednesday, December 04, 2002 8:42 PM
  Subject: Re: [PHP] Looping Addition
 
 
   On Wed, 4 Dec 2002, Stephen wrote:
This is only a snippet, there is more to it but for simplicities
 sake...
Then I calculate it. My question is, how would I loop the adding? I
 hope
  you
understand this now...
  
   Ah!, I think I understand better now.  You want to add num1, num2,
num3,
   ... numN, which are inputs from the second form in your sequence.
 Gotcha.
  
   If you name /all/ the form elements as nums[] instead of
individually
 as
   num${current}, the numbers put into the form will all be accessible
in
   one array to the PHP script that does the adding.  Then you can just
 loop
   over the array of numbers.
  
   In your second form, change this:
   input name=num?php echo $current; ? type=text id=vars
 value=0
size=25
  
   To this:
   input name=nums[] type=text id=vars value=0 size=25
  
   Then in the script that adds the numbers:
   $total = 0;
   foreach( $_POST['nums'] as $number ){
   $total += $number;
   }
  
   Hopefully I understood your problem this time!  Let me know if I
missed
   again.
   g.luck,
   ~Chris
  
  
 
 
  --
  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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




  1   2   >