[PHP-DB] Quering the mySQL DB for statistics results - best way of doing this

2003-11-24 Thread Kim Steinhaug
Hello,

Im about to write a script that will generate several reports from
a database which loggs all visits. I see that my script will need
alot of queries against the database whenever a report is generated,
and I would love to get some input from you if my way of solving
this is bad.

Example, I have a database filled with informations stored from
each visit, I will only focus on the IP data just here. What I want to
do is, pull out the visits ald present theese on the screen. This is 1
query, and the result gives me a mile long page. To make it a little
better I want to group all the IP, this will give me a much shorter list.
From what Ive understood the group by statement will solve this,
but then I wont know the exact number of each IP. I therefore
need to do an extra database query for each and every IP, right?

Look at this code :

function query(){ // DB Abstraction layer }
$allrecords = query(select * from stats group by ip);
for ($i = 0; $i  mysql_num_rows($allrecords) ; $i++) {
 $record=mysql_fetch_object($allrecords);
 $temp = mysql_fetch_object(query(select count(*) as count from stats where
ip='.$record-ip.'));
 $ipcount = $temp-count;
 echo 'Echo out needed $record data, this ip has ' . $ipcount . '
entries.br';
}
echo $i .  Records totalbr;

This code will generate a heck of a lot of queries againt the mySQL
database, but is it possible to do this another way? This is just one
problem, other reports may dig further into the database and require
more queries if using the above method.

By the way, if you know of any recourses for report making and such I
would love to see them, :)

-- 
Kim Steinhaug
---
There are 10 types of people when it comes to binary numbers:
those who understand them, and those who don't.
---

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



[PHP-DB] Re: Send formmail data to Email and Database

2003-11-24 Thread Neil Smth
Since you didn't feel it necessary to include your form processing code, 
and as we're not mind readers, we are unable to help you. Sorry, better 
luck next time.

Cheers - Neil.

At 07:57 24/11/2003 +, you wrote:
  PHP List stats since 1997:
http://zirzow.dyndns.org/html/mlists/
From: howard gramer [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Date: Sun, 23 Nov 2003 18:49:23 +
Mime-Version: 1.0
Content-Type: text/plain; format=flowed
Message-ID: [EMAIL PROTECTED]
Subject: Send formmail data to Email and Database
(newbie alert!)
DWMX, Host: PHP, MySQL, Sendmail, and my own Cgi-Bin
I had the database action working well.  But then trying to get the email 
to work I had to switch their positions in the code. Email now on top and 
database on bottom.  So now the database action is not activated.

How can I get the form data to post to the email and the database?
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Re: Send formmail data to Email and Database

2003-11-24 Thread howard gramer
What a sweet way to greet someone on their first post!  Nice to meet you 
too!
Some lists want code off the bat and some do not!  Now I know it's ok to 
post it without it being requested.

--begin--
?php require_once('Connections/connGlobal.php'); ?
?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = , 
$theNotDefinedValue = )
{
 $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

 switch ($theType) {
   case text:
 $theValue = ($theValue != ) ? ' . $theValue . ' : NULL;
 break;
   case long:
   case int:
 $theValue = ($theValue != ) ? intval($theValue) : NULL;
 break;
   case double:
 $theValue = ($theValue != ) ? ' . doubleval($theValue) . ' : 
NULL;
 break;
   case date:
 $theValue = ($theValue != ) ? ' . $theValue . ' : NULL;
 break;
   case defined:
 $theValue = ($theValue != ) ? $theDefinedValue : 
$theNotDefinedValue;
 break;
 }
 return $theValue;
}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
 $editFormAction .= ? . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS[MM_insert]))  ($HTTP_POST_VARS[MM_insert] 
== form1)) {
 $insertSQL = sprintf(INSERT INTO comments (FIRST_NAME, LAST_NAME, EMAIL, 
COMMENTS) VALUES (%s, %s, %s, %s),
  GetSQLValueString($HTTP_POST_VARS['FIRST_NAME'], 
text),
  GetSQLValueString($HTTP_POST_VARS['LAST_NAME'], 
text),
  GetSQLValueString($HTTP_POST_VARS['EMAIL'], text),
  GetSQLValueString($HTTP_POST_VARS['COMMENTS'], 
text));

 mysql_select_db($database_connGlobal, $connGlobal);
 $Result1 = mysql_query($insertSQL, $connGlobal) or die(mysql_error());
 $insertGoTo = insertOK.php;
 if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
   $insertGoTo .= (strpos($insertGoTo, '?')) ?  : ?;
   $insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
 }
 header(sprintf(Location: %s, $insertGoTo));
}
?
html
head
titleCustomer Service/title
meta http-equiv=Content-Type content=text/html; charset=iso-8859-1
script language=JavaScript
!--
function MM_swapImgRestore() { //v3.0
 var i,x,a=document.MM_sr; for(i=0;aia.length(x=a[i])x.oSrc;i++) 
x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; ia.length; 
i++)
   if (a[i].indexOf(#)!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
 var p,i,x;  if(!d) d=document; 
if((p=n.indexOf(?))0parent.frames.length) {
   d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
 if(!(x=d[n])d.all) x=d.all[n]; for (i=0;!xid.forms.length;i++) 
x=d.forms[i][n];
 for(i=0;!xd.layersid.layers.length;i++) 
x=MM_findObj(n,d.layers[i].document);
 if(!x  d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; 
for(i=0;i(a.length-2);i+=3)
  if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) 
x.oSrc=x.src; x.src=a[i+2];}
}
//--
/script
link href=Assets/master.css rel=stylesheet type=text/css
/head

body bgcolor=#FF leftmargin=0 topmargin=0 marginwidth=0 
marginheight=0 
onLoad=MM_preloadImages('Assets/images/btnCustomerService_on.jpg','Assets/images/btnLocations_on.jpg','Assets/images/btnHome_on.jpg')
table width=100% border=0 cellspacing=0 cellpadding=4
 tr
   td rowspan=2 bgcolor=#424973img src=Assets/images/logo.jpg 
alt=Logo width=235 height=48/td
   td width=100% bgcolor=#424973div align=rightfont 
color=#FFbThe
   International Car Rental Specialists/b/font/div/td
 /tr
 tr
   td table width=100% border=0 cellspacing=1 cellpadding=2
   tr
 td align=center width=20% bgcolor=#424973a 
href=index.htm onMouseOut=MM_swapImgRestore() 
onMouseOver=MM_swapImage('menu1','','Assets/images/btnHome_on.jpg',1)img 
src=Assets/images/btnHome.jpg alt=Home Button name=menu1 width=90 
height=25 border=0/a/td
 td align=center width=20% bgcolor=#424973a 
href=customerService.php onMouseOut=MM_swapImgRestore() 
onMouseOver=MM_swapImage('menu2','','Assets/images/btnCustomerService_on.jpg',1)img 
src=Assets/images/btnCustomerService.jpg alt=Customer Service Button 
name=menu2 width=110 height=25 border=0/a/td
 td align=center width=20% bgcolor=#424973a href=# 
onMouseOut=MM_swapImgRestore() 
onMouseOver=MM_swapImage('menu3','','Assets/images/btnLocations_on.jpg',1)img 
src=Assets/images/btnLocations.jpg alt=Locations Button name=menu3 
width=90 height=25 border=0/a/td
   /tr
 /table/td
 /tr
/table
br

table width=841 border=0 cellpadding=0 cellspacing=0
 tr
   td width=618 height=35 valign=top FONT SIZE=+2 
COLOR=#FF6600Customer
 Service/FONT/td
   td rowspan=3 width=223 align=right valign=topnbsp; /td
 /tr
 tr
   td height=405 valign=toppWe value your comments and questions. 
Please
   

[PHP-DB] PostgreSQL

2003-11-24 Thread David Kendal
Hello! I'm new to to Postgre so excuse me, but is Postgre the same as MySQL?

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



Re: [PHP-DB] PostgreSQL

2003-11-24 Thread Gerard Samuel
On Monday 24 November 2003 10:58 am, David Kendal wrote:
 Hello! I'm new to to Postgre so excuse me, but is Postgre the same as
 MySQL?

Yes and No.

Both are databases.  Both can be interfaced to php.

But

Under the hoods of both, are very different.

For more information, 
http://www.mysql.com/
http://www.postgresql.org/

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



Re: [PHP-DB] Sessions and input form

2003-11-24 Thread jeffreyb
Dear Aleks:

What I usually do for a situation like this is...

1) User fills out form and data is INSERTed into the table. If you use 
auto_increment for the row id, use PHP's mysql_insert_id to get the id and 
use this for step 2.

2) Page confirms data by SELECTing the data from the MySQL table and 
inserting it into the form. 

3) If the user makes changes, it is UPDATEd in the MySQL table.

I hope this is clear.

Good luck,

Jeffrey Baumgartner

 Hi all,
 
 I have a form that when populated and submitted is entered into a MySQL dB.
 What I would like to do is be able to present the submitter with a
 confirmation page listing the information from the form and then ask them to
 confirm their submission. Also, if there is a problem or want to change
 something, they can use the browser back button to go to the previous page and
 make corrections.
 
 At first I thought that using Sessions to add the form values would allow this
 to work.. I have gone threw this twice since last night and find that my logic
 is flawed... It works once... then when another submissions is attempted the
 process hangs and returns a CGI timeout.
 
 I am by no means a newbie but obviously I am not doing something right with
 regards to session use. So I ask you more knowledgeable then I for your input
 and advise. In hind sight I think my problem is that once the information is
 confirmed and supposed to be entered into the dB I am not destroying the
 session... Like I said, I think my approach is all wrong here. I already have
 a login routine that uses sessions and works flawlessly..[at least in
 appearance].
 
 Any help would be very much appreciated.
 
 TYIA
 
 Aleks
 
 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

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



[PHP-DB] Re: Quering the mySQL DB for statistics results - best way of doing this

2003-11-24 Thread Justin Patrin
You can do it all in one query, just as you're already doing it:

SELECT COUNT(*) AS count FROM stats GROUP BY ip

Kim Steinhaug wrote:
Hello,

Im about to write a script that will generate several reports from
a database which loggs all visits. I see that my script will need
alot of queries against the database whenever a report is generated,
and I would love to get some input from you if my way of solving
this is bad.
Example, I have a database filled with informations stored from
each visit, I will only focus on the IP data just here. What I want to
do is, pull out the visits ald present theese on the screen. This is 1
query, and the result gives me a mile long page. To make it a little
better I want to group all the IP, this will give me a much shorter list.
From what Ive understood the group by statement will solve this,
but then I wont know the exact number of each IP. I therefore
need to do an extra database query for each and every IP, right?
Look at this code :

function query(){ // DB Abstraction layer }
$allrecords = query(select * from stats group by ip);
for ($i = 0; $i  mysql_num_rows($allrecords) ; $i++) {
 $record=mysql_fetch_object($allrecords);
 $temp = mysql_fetch_object(query(select count(*) as count from stats where
ip='.$record-ip.'));
 $ipcount = $temp-count;
 echo 'Echo out needed $record data, this ip has ' . $ipcount . '
entries.br';
}
echo $i .  Records totalbr;
This code will generate a heck of a lot of queries againt the mySQL
database, but is it possible to do this another way? This is just one
problem, other reports may dig further into the database and require
more queries if using the above method.
By the way, if you know of any recourses for report making and such I
would love to see them, :)
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] Re: Quering the mySQL DB for statistics results - best way of doing

2003-11-24 Thread Justin Patrin
Whoops, forgot the rest of the fields.

SELECT COUNT(*) AS count, * FROM stats GROUP BY ip

Note that this will not work on Oracle and some other DBs. It will work 
in MySQL. Oracle will only let you do:

SELECT COUNT(*) count, ip, FROM stats GROUP BY ip

Justin Patrin wrote:

You can do it all in one query, just as you're already doing it:

SELECT COUNT(*) AS count FROM stats GROUP BY ip

Kim Steinhaug wrote:

Hello,

Im about to write a script that will generate several reports from
a database which loggs all visits. I see that my script will need
alot of queries against the database whenever a report is generated,
and I would love to get some input from you if my way of solving
this is bad.
Example, I have a database filled with informations stored from
each visit, I will only focus on the IP data just here. What I want to
do is, pull out the visits ald present theese on the screen. This is 1
query, and the result gives me a mile long page. To make it a little
better I want to group all the IP, this will give me a much shorter list.
From what Ive understood the group by statement will solve this,
but then I wont know the exact number of each IP. I therefore
need to do an extra database query for each and every IP, right?
Look at this code :

function query(){ // DB Abstraction layer }
$allrecords = query(select * from stats group by ip);
for ($i = 0; $i  mysql_num_rows($allrecords) ; $i++) {
 $record=mysql_fetch_object($allrecords);
 $temp = mysql_fetch_object(query(select count(*) as count from stats 
where
ip='.$record-ip.'));
 $ipcount = $temp-count;
 echo 'Echo out needed $record data, this ip has ' . $ipcount . '
entries.br';
}
echo $i .  Records totalbr;

This code will generate a heck of a lot of queries againt the mySQL
database, but is it possible to do this another way? This is just one
problem, other reports may dig further into the database and require
more queries if using the above method.
By the way, if you know of any recourses for report making and such I
would love to see them, :)
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] Get query value from URL?

2003-11-24 Thread Mingyan Shao
Hi, there,

I am learning PHP/MySQL now, and got an sample code from
http://hotwired.lycos.com/webmonkey/99/21/index3a_page3.html?tw=programming,
but when I test the code on my machine, it does not work as it
suppose to.

What it should do is: when you first run the php code, it
gives the names of the employees, each of which creates a link to the
detail info, for example, a href=\%s?id=%s\%s %s/abr\n,
$PHP_SELF, $myrow[id], $myrow[last], $myrow[position]. When you
click any name, it should get the query value($id) from the URL, and use
it to search in the database.

It seems can't get the $id from the URL querystring, i.e., the html page
does not change after I click a specific name.


The code is the following:

?php

$db = mysql_connect(localhost, root);

mysql_select_db(mydb,$db);

// display individual record

if ($id) {

   $result = mysql_query(SELECT * FROM employees WHERE id=$id,$db);

   $myrow = mysql_fetch_array($result);

   printf(First name: %s\nbr, $myrow[first]);

   printf(Last name: %s\nbr, $myrow[last]);

   printf(Address: %s\nbr, $myrow[address]);

   printf(Position: %s\nbr, $myrow[position]);

} else {

// show employee list

   $result = mysql_query(SELECT * FROM employees,$db);

if ($myrow = mysql_fetch_array($result)) {

  // display list if there are records to display

  do {

printf(a href=\%s?id=%s\%s %s/abr\n, $PHP_SELF,
$myrow[id], $myrow[first], $myrow[last]);

  } while ($myrow = mysql_fetch_array($result));

} else {

  // no records to display

  echo Sorry, no records were found!;

}

}

?



Any comments and suggestions are appreciated.

-Mingyan

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



[PHP-DB] Extracting values from an array (I think)

2003-11-24 Thread dpgirago
Hello All,

I'm familiar and comfortable with selecting and utilizing one record at a 
time in my php-mysql gui / application. But now I'm faced with having to 
select one field from 24 records and assign the results to 24 different 
variables. 

Table structure: 

CONFIG
+--+--+
| Field  | Type  |
+--+--+
| meter_num | int(11)   |  primary key
| x | double|
| y | double|
| z | double|
| cc_val| varchar(64)   |
| cc_date   | date  |  primary key
| esn   | varchar(64)   |
| dsn   | varchar(64)   |
| csn   | varchar(64)   |
| comm_setup| varchar(128)  |
| multi_port| varchar(16)   |
| threshold | double|
| short_label   | varchar(20)   |
| label | varchar(80)   |
| comments  | varchar(255)  |
| mod_date  | datetime  |
+-+--+--+---+

query =SELECT  short_label  FROM  config  ORDER BY  meter_num;

There will be 24 records max in this table, and meter_num is a primary key 
with values 1- 24 .

If I run this query in the MySQL client, I get a result set like this:

short_label_1
short_label_2
//
//
short_label_24

And I'd like to be able to do this:

$sLabel_1 = short_label_1;
$sLabel_2 = short_label_2;

etc...

These variables / values then get displayed in an HTML table in the 
appropriate place. I know that I can add a where clause to the query to 
select / assign each label individually, but that's 24 queries just for 
this one piece of data. Seems to me there must be a more efficient way to 
do this, but I'm runnin' out of ideas. 

Hope someone is thinking more clearly than I am right now.

Thanks.

David

RE: [PHP-DB] Sessions and input form

2003-11-24 Thread Aleks @ USA.net
 Dear Jeffrey,

Yes that is clear thank you... I have used this technique in the past
But wanted to give sessions a try. I did manage to get it working. Seems
That typing code at midnight can lead to frustrating and volatile results..

Thanks again for your response... 

Aleks

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Monday, November 24, 2003 12:30 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] Sessions and input form

Dear Aleks:

What I usually do for a situation like this is...

1) User fills out form and data is INSERTed into the table. If you use
auto_increment for the row id, use PHP's mysql_insert_id to get the id and
use this for step 2.

2) Page confirms data by SELECTing the data from the MySQL table and
inserting it into the form. 

3) If the user makes changes, it is UPDATEd in the MySQL table.

I hope this is clear.

Good luck,

Jeffrey Baumgartner

 Hi all,
 
 I have a form that when populated and submitted is entered into a MySQL
dB.
 What I would like to do is be able to present the submitter with a 
 confirmation page listing the information from the form and then ask 
 them to confirm their submission. Also, if there is a problem or want 
 to change something, they can use the browser back button to go to the 
 previous page and make corrections.
 
 At first I thought that using Sessions to add the form values would 
 allow this to work.. I have gone threw this twice since last night and 
 find that my logic is flawed... It works once... then when another 
 submissions is attempted the process hangs and returns a CGI timeout.
 
 I am by no means a newbie but obviously I am not doing something right 
 with regards to session use. So I ask you more knowledgeable then I 
 for your input and advise. In hind sight I think my problem is that 
 once the information is confirmed and supposed to be entered into the 
 dB I am not destroying the session... Like I said, I think my approach 
 is all wrong here. I already have a login routine that uses sessions 
 and works flawlessly..[at least in appearance].
 
 Any help would be very much appreciated.
 
 TYIA
 
 Aleks
 
 --
 PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: 
 http://www.php.net/unsub.php

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

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



Re: [PHP-DB] Extracting values from an array (I think)

2003-11-24 Thread John Krewson
If you have to assign 24 unique variables rather than storing this data 
in an array, then you could apply some variable variable action.  Here 
is a code sample that assumes you are looping through a result set from 
a database:

query =SELECT  short_label  FROM  config  ORDER BY  meter_num;
$result= @MSSQL_QUERY($query)
	or die(Can't connect or something painfully obscure);
while($row = mysql_fetch_assoc($result)) 
{
	${$short_label}=$row[short_label];
}

That will, I believe, give you a list of variables/values such as:
$short_label_1 = short_label_1
$short_label_2 = short_label_2
You can also adjust the variable name to your liking, such as:

${$short_label._counterPerhaps}=$row[short_label];

The above should be correct, but I do admit that I don't use this technique daily.

To bad you cannot just throw your values into an associative array and pluck them when 
needed
using $key = $value type of combinations.


-John

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


[PHP-DB] Re: Quering the mySQL DB for statistics results - best way of doing

2003-11-24 Thread Kim Steinhaug
Thanks for your ideas, im sitting here drinking beer and drinks, so
Im having a little difficulty grasping the whole idea with this new
SQl statement, but it works! Thanks a lot.

To help the other people reading this who might not get it I did
some benchmarking, my method (mentioned in the beginning in
the thread) :

Time - 0.3663

I altered the routine, from 114 nested queries (my dataset) into
1 single query from Justin Patrin like this :

$sql = select ip,  count(*) as ipcount FROM stats Group By ip;
$allrecords = query($sql);
for ($i = 0; $i  mysql_num_rows($allrecords) ; $i++) {
 $record=mysql_fetch_object($allrecords);
 echo $record-ipcount . '-';
}

Time - 0.0101

Remarkable difference indeed! Im just happy that I just made 1 single
report script at the moment using my rather terrible queries... :)

Thanks for the help Justin!

-- 
Kim Steinhaug
---
There are 10 types of people when it comes to binary numbers:
those who understand them, and those who don't.
---


Justin Patrin [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Whoops, forgot the rest of the fields.

 SELECT COUNT(*) AS count, * FROM stats GROUP BY ip

 Note that this will not work on Oracle and some other DBs. It will work
 in MySQL. Oracle will only let you do:

 SELECT COUNT(*) count, ip, FROM stats GROUP BY ip

 Justin Patrin wrote:

  You can do it all in one query, just as you're already doing it:
 
  SELECT COUNT(*) AS count FROM stats GROUP BY ip
 
  Kim Steinhaug wrote:
 
  Hello,
 
  Im about to write a script that will generate several reports from
  a database which loggs all visits. I see that my script will need
  alot of queries against the database whenever a report is generated,
  and I would love to get some input from you if my way of solving
  this is bad.
 
  Example, I have a database filled with informations stored from
  each visit, I will only focus on the IP data just here. What I want to
  do is, pull out the visits ald present theese on the screen. This is 1
  query, and the result gives me a mile long page. To make it a little
  better I want to group all the IP, this will give me a much shorter
list.
  From what Ive understood the group by statement will solve this,
  but then I wont know the exact number of each IP. I therefore
  need to do an extra database query for each and every IP, right?
 
  Look at this code :
 
  function query(){ // DB Abstraction layer }
  $allrecords = query(select * from stats group by ip);
  for ($i = 0; $i  mysql_num_rows($allrecords) ; $i++) {
   $record=mysql_fetch_object($allrecords);
   $temp = mysql_fetch_object(query(select count(*) as count from stats
  where
  ip='.$record-ip.'));
   $ipcount = $temp-count;
   echo 'Echo out needed $record data, this ip has ' . $ipcount . '
  entries.br';
  }
  echo $i .  Records totalbr;
 
  This code will generate a heck of a lot of queries againt the mySQL
  database, but is it possible to do this another way? This is just one
  problem, other reports may dig further into the database and require
  more queries if using the above method.
 
  By the way, if you know of any recourses for report making and such I
  would love to see them, :)
 

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



Re: [PHP-DB] Extracting values from an array (I think)

2003-11-24 Thread dpgirago
Thanks for your kind reply, John. I've not used the variable variable 
technique before but do recall reading about it in the PHP Bible. 

I'll give it a try.

David





John Krewson [EMAIL PROTECTED]

11/24/2003 01:33 PM



 

To:
[EMAIL PROTECTED]
cc:





Subject:
Re: [PHP-DB] Extracting values from an array (I think)



If you have to assign 24 unique variables rather than storing this data 
in an array, then you could apply some variable variable action.  Here 
is a code sample that assumes you are looping through a result set from 
a database:

query =SELECT  short_label  FROM  config  ORDER BY  meter_num;
$result= @MSSQL_QUERY($query)
 or die(Can't connect or something painfully obscure);
while($row = mysql_fetch_assoc($result)) 
{
 ${$short_label}=$row[short_label];
}

That will, I believe, give you a list of variables/values such as:
$short_label_1 = short_label_1
$short_label_2 = short_label_2

You can also adjust the variable name to your liking, such as:

${$short_label._counterPerhaps}=$row[short_label];

The above should be correct, but I do admit that I don't use this 
technique daily.

To bad you cannot just throw your values into an associative array and 
pluck them when needed
using $key = $value type of combinations.




-John

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





Re: [PHP-DB] Get query value from URL?

2003-11-24 Thread Mingyan Shao
I got the solution:

Adding this line before if($id): $id = $_GET['id'];

Similarily, may add $submit=$_POST['submit'];,$firstname=$_POST['firstname'];
 if handle forms, like insertion a record into database.



On Mon, 24 Nov 2003, Mingyan Shao wrote:

 Hi, there,

 I am learning PHP/MySQL now, and got an sample code from
 http://hotwired.lycos.com/webmonkey/99/21/index3a_page3.html?tw=programming,
 but when I test the code on my machine, it does not work as it
 suppose to.

 What it should do is: when you first run the php code, it
 gives the names of the employees, each of which creates a link to the
 detail info, for example, a href=\%s?id=%s\%s %s/abr\n,
 $PHP_SELF, $myrow[id], $myrow[last], $myrow[position]. When you
 click any name, it should get the query value($id) from the URL, and use
 it to search in the database.

 It seems can't get the $id from the URL querystring, i.e., the html page
 does not change after I click a specific name.


 The code is the following:

 ?php

 $db = mysql_connect(localhost, root);

 mysql_select_db(mydb,$db);

 // display individual record

 if ($id) {

$result = mysql_query(SELECT * FROM employees WHERE id=$id,$db);

$myrow = mysql_fetch_array($result);

printf(First name: %s\nbr, $myrow[first]);

printf(Last name: %s\nbr, $myrow[last]);

printf(Address: %s\nbr, $myrow[address]);

printf(Position: %s\nbr, $myrow[position]);

 } else {

 // show employee list

$result = mysql_query(SELECT * FROM employees,$db);

 if ($myrow = mysql_fetch_array($result)) {

   // display list if there are records to display

   do {

 printf(a href=\%s?id=%s\%s %s/abr\n, $PHP_SELF,
 $myrow[id], $myrow[first], $myrow[last]);

   } while ($myrow = mysql_fetch_array($result));

 } else {

   // no records to display

   echo Sorry, no records were found!;

 }

 }

 ?



 Any comments and suggestions are appreciated.

 -Mingyan

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


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



[PHP-DB] Re: sendmail

2003-11-24 Thread Kim Steinhaug
You should check out phpmailer at sourceforge.
It solved all my problems, and will probably solve all yours to.

As a bonus, you get a mailer that has a lot of more functions,
like attachements and HTML mail and such.

-- 
Kim Steinhaug
---
There are 10 types of people when it comes to binary numbers:
those who understand them, and those who don't.
---


Unknown Sender [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Hi
Sorry to be off topic but I have problem with sendmail
If anyone know sth about sendmail please e-mail priv.

Sorry once more

[EMAIL PROTECTED]

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



[PHP-DB] Re: Mail problem

2003-11-24 Thread Kim Steinhaug
Well, i've developed such a system, MarketMAX.

And ill just give you a little tip here :

1. Dont use BCC field, it look bad and your not able to populate
the emails from your database, eg. Dear %username%
Ofcourse if your bulksend the same message, always, then
BCC could spare your from headache.
2. THE TIMEOUTS!
Be aware, very aware, not only do you need to account for
php timeout, you also should be very aware of standard sendmail
configuration regarding spam. Most installations ive encountered
does not like say. 500 emails dumped at them during a few seconds.
They will probably detect you as spam, and all the mails are deleted.
The best part, all cases Ive encountered, you dont get an error so you
think everyuthing is swell - It isnt!

What you need to do is a) create a cron job that bulk sends. eg. 50
emails each 10 second or such. My sollutions was to create a batch
system that pulls the 50 last entries from the batch list, prints out
the
html page with a 5sec meta refresh. This keeps looping till there is no
emails left.

You might be lucky to be on a system that doesnt care how many emails
sendmail spews out, but this is in fact bad. If this is happening, you
probably
will experience someone taking advantage of the system resulting in the
server IP getting blacklisted - and this is very bad for all users.
But if you do it right, and also create a lot of what if scenarios, you
should
be just fine.

Happy programming!

-- 
Kim Steinhaug
---
There are 10 types of people when it comes to binary numbers:
those who understand them, and those who don't.
---


Craig Roberts [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 It might be a good idea to set a cron job to send say, 100 at a time over
 the space of a few hours, to avoild killing the mail server or the server
 blocking connections from you.

 Also - use the BCC field to send the mail, this means only one connection
 will need to be made to the mail server per batch of addresses, as opposed
 to a connection per address (saves bandwidth and mail server!). The mail
 server will then send the messages where they need to go and hide all the
 other recipents.

 Craig Roberts


 Mak [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  Beware though...if there are too many addresses in the db, you may
 encounter
  timeouts, or your browser may crash (very likely). Increase the timeout
  before you do such a mass-mail job.
 
  Also, my comment: If you do not want your receivers to find out who else
 you
  sent the mail to, don't use the CC method. Just:
 
  for(until max. users reached){
  send out new mail to current user
  }
 
  Yours sincerely,
  Mak
 
  Jj Harrison\ [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
  
maybe use a for loop and mail command.
should work
  
   Or put all the addresses in a CC/BCC field maybe sending every 100
 emails
  to
   prevent a mail overload/blockage due to to many recipients etc.
  
   Hint: look here: http://www.php.net/manual/en/language.variables.php
and
  you
   can find a way to append more to an existing variable. Very useful in
 your
   case.
  
  
   --
   JJ Harrison
   [EMAIL PROTECTED]
   www.tececo.com
  
Unknown Sender [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Sorry to be a little bit off topic.
   
I need a tool or script in PHP, that will automaticaly send e-mails
to
receipients taken from database.
For example 1 the same e-mail to 1000 receipients. B
   
Mail server is on different machine.
   
Thanks in advance
   
   
   
  
  
 
 



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



Re: [PHP-DB] PHP problem

2003-11-24 Thread Kim Steinhaug
4 words!

i dont believe you!

-- 
Kim Steinhaug
---
There are 10 types of people when it comes to binary numbers:
those who understand them, and those who don't.
---


Unknown Sender [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Unfortunately, it doesn't work,
 the same situation

   Sorry to be a little bit off topic
   i have code that generates:
   OPTION LABEL=1LONG TEXT 1
 
  use:
  option value=1long text 1/option
 
  mvgr,
  Joffrey van Wageningen
 
  --
  .-[ Joffrey van Wageningen | WoLFjuh | [EMAIL PROTECTED] ]--
  | Networking Event 2000 - www.ne2000.nl - IRCnet:#ne2000, Undernet:#clue
  | PGP:1024D/C6BA5863 - 3B93 52D3 CB91 9CB7 C50D FA79 865F 628A C6BA 5863
  | * We demand guaranteed rigidly defined areas of doubt and uncertainty.
  |   -- Douglas Adams
 
 
  -- 
  PHP Database Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 



 -- 

 Okresl Swoje potrzeby - my znajdziemy oferte za Ciebie!
 [ http://oferty.onet.pl ]


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



Re: [PHP-DB] Extracting values from an array (I think)

2003-11-24 Thread dpgirago
I'm getting the correct output from the following query:


  $selectLabelQuery = SELECT   short_label
 FROM config
 ORDER BY  meter_num;

  $resultSelectLabelQuery = mysql_query($selectLabelQuery) or
 die(can't select short label);


which is processed here:


  $counter = 1;
  while($row=mysql_fetch_assoc($resultSelectLabelQuery))
  {


But the variable variable thing does not seem to be working, either with 
or without the $ for the 'counter' inside the brackets. 


${$sLabel_ . $counter} = $row['short_label'];
$counter++;
  }

When I WATCH  $counter and $row['short_label'], their values are 1 through 
24, and short_label_1 through short_label_24, respectively, so the problem 
is in this part ... ${$sLabel_ . $counter} or even when like this ${$sLabel_ . 
counter}  .

TIA,

David

[PHP-DB] ibase_fetch_object(): request synchronization error

2003-11-24 Thread Ogee
Hi,

   I've got a problem with Firebird 1.0 and PHP 4.3.3 (had same problem 
with older release also). When I want to do ibase_execute() in recursion 
I take an error $subject and I didn't find anything about that in the 
Internet.
  Could you help me. Thanks a lot!
  I have found something, that describe this error for Interbase 5.X 
and there was written that problem could be in recursive trigger. My 
code is in PHP but it is recursion also. It would be very unhappy for 
me, if it wouldn't work, because using ibase_query in my recursion is 
not good idea.

--ogee

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


[PHP-DB] Splitting a CSV file

2003-11-24 Thread Chris Payne
Hi there everyone,

I'm writing an automation system to automatically insert data into a mysql database 
from a CSV file, and it works great - until I try to insert a large file, then it just 
doesn't do anything.

I've set my PHP filesize to 10 Megs so that's not the issue, and a server timeout 
isn't the issue either.  So, is that a way that I can split a CSV file into 2 files if 
it's larger than a certain size so that I can still use the automation I am working on?

Actually, I won't see the files as it's for a company who just wants to be able to 
select their CSV file (No matter what size) and it will insert it automatically, and 
as I said it does work on small files but not large :-(

Any help would really be appreciated.

Chris

[PHP-DB] Re: Send formmail data to Email and Database

2003-11-24 Thread Neil Smth
At 20:04 24/11/2003 +, you wrote:
From: howard gramer [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] Re: Send formmail data to Email and Database
What a sweet way to greet someone on their first post!  Nice to meet you too!
I''m not here to hold your hand or monitor for new group members - we're 
all busy in here.

Some lists want code off the bat and some do not!  Now I know it's ok to 
post it without it being requested.
Fair point. Down to business :

I would attend to your HTML oddly enough, as the PHP doesn't ring any alarm 
bells : Check out your FORM elements, you have two (Don't know if this will 
post right to the list) :

 form action=http://www.friendlyhousebuyers.com/cgi-sys/formmail.pl;
method=POST
followed by

form method=post name=form1 action=?php echo $editFormAction;
?
The first form tag outside the second will kill the form action you think 
you are getting, as it's invalid HTML : Many browsers will treat it in 
different ways and give unpredictable results. You need to dump DW for 
complex forms and head down into the code - leave DW to make light work of 
fidgetty table layouts. It will probably work again if you remove this. 
Else, try printing out a few key things like the SQL statement which is 
produced by the sprintf line.

Hope that helps, Cheers - Neil.

(PS Please do not post to this email address - all mail from hotmail 
addresses is filtered out - house policy, sorry !)

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


[PHP-DB] Re: Subject: Extracting values from an array (I think)

2003-11-24 Thread Neil Smth
Get your array from mysql_fetch_assoc() you can then use as an alternative, 
the extract() function :

http://uk2.php.net/manual/en/function.extract.php

Cheers - Neil.

At 20:04 24/11/2003 +, you wrote:
To: [EMAIL PROTECTED]
MIME-Version: 1.0
From: [EMAIL PROTECTED]
Date: Mon, 24 Nov 2003 12:44:37 -0600
Subject: Extracting values from an array (I think)
Hello All,

I'm familiar and comfortable with selecting and utilizing one record at a
time in my php-mysql gui / application. But now I'm faced with having to
select one field from 24 records and assign the results to 24 different
variables.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Splitting a CSV file

2003-11-24 Thread Matt Babineau
Chris,

If you are on a Redhat machine, you could try running a CLI command on
this.

Try looking up the 'split' command, it may solve your problem if you
combine it with some PHP.

-Matt

On Mon, 2003-11-24 at 19:14, Chris Payne wrote:
 Hi there everyone,
 
 I'm writing an automation system to automatically insert data into a mysql database 
 from a CSV file, and it works great - until I try to insert a large file, then it 
 just doesn't do anything.
 
 I've set my PHP filesize to 10 Megs so that's not the issue, and a server timeout 
 isn't the issue either.  So, is that a way that I can split a CSV file into 2 files 
 if it's larger than a certain size so that I can still use the automation I am 
 working on?
 
 Actually, I won't see the files as it's for a company who just wants to be able to 
 select their CSV file (No matter what size) and it will insert it automatically, and 
 as I said it does work on small files but not large :-(
 
 Any help would really be appreciated.
 
 Chris

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



Re: [PHP-DB] Extracting values from an array (I think)

2003-11-24 Thread John W. Holmes
[EMAIL PROTECTED] wrote:
But the variable variable thing does not seem to be working, either with 
or without the $ for the 'counter' inside the brackets. 
  ${$sLabel_ . $counter} = $row['short_label'];
  $counter++;
${'sLabel_' . $count} = $row['short_label'];

Any reason you're not just doing

$data[] = $row['short_label'];

and loop through that?

or

$data['sLabel_' . $count] = $row['short_label'];

variable variables are just a poor man's array...

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP-DB] strings of variables,php, sql

2003-11-24 Thread George Patterson
On Mon, 24 Nov 2003 21:36:29 -0800 (PST)
Joffrey Leevy [EMAIL PROTECTED] wrote:

 Would appreciate in anyone can help me.
 
 Let's say I do a query in php, eg. $query = select
 shed from structure;  With the mysql_fetch_array
 function and a loop I could see all the values stored
 in the column, shed, using the command: echo $shed;
 
 Let's say now that I am carrying over a variable from
 a form called $form where $form = shed.  I can still
 say $query = select $form from structure; because
 $form = shed.
 
 The problem I have now is with the strings and how do
 I see my column values.
 
 Using echo $$value; or echo $($value) or echo \$$value
 or echo $$value does not give me the values stored
 in the column shed.
 
 Help anyone?
 thanks
 

Joffrey,

First it is easier for us if you just paste the relevant code but I'll
try and assist without.

Before you can fetch a record you must query the database..
$result=mysql_query($query) or die( Bad Query= $query\nbr.
mysql_error() );

The die() function will print an error if there is something wrong with
the query such as database not opened first.

You are fetching a row (or record) from the database.

$row=mysql_fetch_array($result);

therefore the value of shed column will be contained within $row.

It can be accessed by either of the two lines below.

echo $row[0];   #by numeric index..
echo $row[shed];  #or by column name..

If you wish to find out all the column names and values, try

print_r($row);


George Patterson

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