RE: [PHP-DB] Help needed with variable scoping? or mysql problem

2003-08-23 Thread Mike Klein
Oh yeah that's the ticket!

I'd forgotten that I'd removed the mysql_select_db statement when doing
some earlier 'cleanup'. It just so happens that a few of the mysql metadata
calls (like listing fields/etc.) were inadvertently setting the db...but
only for a brief period of time...wierd.

As I mentioned, I just started using php yesterday, so I'm still learning
some tips/tricks.

But...to php's credit, I gotten a fairly functional rdbms
explorer/browser/editor going in under a day. I had initially planned on
'hardcoding' some rdbms master/detail forms, but after doing just one of
them, and seeing the plethora of mysql calls available, I decided to
genericize the code, and now it's a general explorer/etc. for all of my
databases. Seems pretty speedy too.

Now I just need to add result set 'scrolling'. Returning 2000 records is not
nice...


thanks buddy...



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 14, 2003 8:10 AM
To: Mike Klein
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] Help needed with variable scoping? or mysql
problem



best way to tell is to place .'or die(mysql_error())' after any call to
mysql_query() to see what mysql is complaining about.  personally I
sometimes declare the query first so i can echo that as well after the
msyql_error() function, so i can see the query that has just been
excecuted.  helpful with dynamic queries.

$qry = SELECT * FROM $tableName where $fieldName='$fieldValue';
$result = mysql_query($qry, $conn) or die(mysql_error() . $qry);

hth
jeff



  Mike Klein
  [EMAIL PROTECTED]To:
[EMAIL PROTECTED]
  rg  cc:
   Subject:  [PHP-DB] Help
needed with variable scoping? or mysql problem
  08/14/2003 08:58
  AM






I've been using JSP for some time now, and thought I'd write a couple of
rdbms explorers (flat tables, simple master/detail paradigm) using other
technologies, like PHP, Cocoon, etc. Well...it's been fun. I have more
working than not. But now I am hung up. I am getting wierd results in a php
script when I simply change the order of some mysql calls.

I'm using php-4.3.2, rh9, and mysql 3.23.

My error is the following (the first line above the Warning below is a dump
of parameters to the showMaster function which is what's bombing):

conn=Resource id #3 databaseName=info tableName=movies fieldName=title
fieldValue=36th Chamber
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource in /foo/bar/mywebsite/private/database.php on line 107

Line 107 is the first mysql_num_rows call below.

function showMaster($conn, $databaseName, $tableName, $fieldName,
$fieldValue)
{
echo conn=$conn\n;
echo databaseName=$databaseName\n;
echo tableName=$tableName\n;
echo fieldName=$fieldName\n;
echo fieldValue=$fieldValue\n;

This code fails when placed here==
$result = mysql_query(SELECT * FROM $tableName where
$fieldName='$fieldValue', $conn);
$numRows = mysql_num_rows($result);
if(mysql_num_rows($result) == 1)
{
showDetail($conn, $databaseName, $tableName, $fieldName,
$fieldValue, $result);
exit;
}
echo numRows=$numRows\n;


$fields = mysql_list_fields($databaseName, $tableName, $conn);
$numFields = mysql_num_fields($fields);
echo TABLE border=1 width=100%\n;
echo tr;
for($i = 0; $i  $numFields; $i++)
{
printf(td%s/td, mysql_field_name($fields, $i));
}
echo /tr;

The SAME code succeeds when placed here!==
$result = mysql_query(SELECT * FROM $tableName where
$fieldName='$fieldValue', $conn);
$numRows = mysql_num_rows($result);
if(mysql_num_rows($result) == 1)
{
showDetail($conn, $databaseName, $tableName, $fieldName,
$fieldValue, $result);
exit;
}
echo numRows=$numRows\n;


while($myrow = mysql_fetch_array($result))
...rest of method...
}

Any ideas on why this is? When I move the lines above (from
$result=...to...echo 'numRows') down a few lines to just before the
mysql_fetch_array, then everything works. Whazzup?!?


mike klein



--
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] Mysql Query

2003-08-23 Thread Mohammad Saadullah
Hi guys,

I have been working in php/oracle for quite some time now but recently had to shift 
myself to mysql and I am struggling with a particular query here.

Scenario is, certain researchers can submit their proposals and those proposal are 
stored in a table researcher. 
proposals are of 2 types lets say type 1 and type 2.
Later they can view their own submited proposals which is working fine, but there is 
one new condition now.What my client wants is that these researchers can view all 
proposals of type 2 but only those proposals of type 1 should be displayed to a 
researcher whose submit date is greater than a certain date lets say '2003-08-01'. Now 
how do I create a single query which can return me such results. I know there is a way 
with join but cant find a solution, with oracle I would have used sub query but that 
cannot be done on mysql so I need your guys help thanks

Table name: researcher

Concerned fields
pid -- porposal id
rid -- researcher id
ptype --- proposal type
submitd -- submission date.

I would use rid = 42 and for ptype = 1 submitd should be greater than '2003-08-01' and 
there is no restriction of date with ptype =2.

Thanks again.
if there is something not clear feel free to ask

RE: [PHP-DB] It\'s wierd when I\'ve used forms...

2003-08-23 Thread Joe Walker
Thanks, the stripslashes() function worked perfectly!

 -Original Message-
 From: Jacob A. van Zanen [mailto:[EMAIL PROTECTED]
 Sent: Friday, August 22, 2003 5:48 PM
 To: [EMAIL PROTECTED]
 Cc: Joe Walker; [EMAIL PROTECTED]
 Subject: Re: [PHP-DB] It\'s wierd when I\'ve used forms...
 
 I mean in front of special characters off course :-)
 
 Jack
 On Fri, 2003-08-22 at 23:40, Jacob A. van Zanen wrote:
  You'll have to look into stripslashes function (of the top of my
head)
 
  PHP automatically puts slashes around variables
 
 
  Jack
  On Fri, 2003-08-22 at 23:35, Joe Walker wrote:
   I've got a form (for sending mail to a user) and the user input is
in
 an
   html form using the post method to pass:
   textarea name=message rows=10 cols=80 wrap=virtual
   along with some other vars to a php page which sends the message
 using:
   mail([EMAIL PROTECTED], $msgSubject, $message, From:
$addyFrom);
  
   But if you type:
   What's it's problem?  I've got flippin' issues!
  
   In the message box, it comes in e-mail as:
   What\'s it\'s problem?  I\'ve got flippin\' issues!
  
   Escaping every apostrophe.
  
   How do I have this not happen?
  
   Thanks in advance.
   Joe
 
 
 
 --
 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