Re: [PHP] Problem with SELECT statement and reference material wanted..

2003-10-23 Thread Binay
remove ' '(single quotes) around variable name..

cheers
binay
- Original Message -
From: P M [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, October 23, 2003 5:27 PM
Subject: [PHP] Problem with SELECT statement and reference material wanted..


Hi all!

I'm having trouble retrieving a selection of my database contents. The
problem is when I search for entries that exactly match a search criteria,
see below:

(database connection established successfully here..)

  $result = mysql_query(select * from complete where authorf =
'$authorf');

  if ( $r = mysql_fetch_array($result) )
  {
   echo Found entries:ul;
   echo table border=1;

   do
   {
print trtd;
print $r[authorf];
print /tdtd;
print $r[authorl];
print /tdtd;
print $r[title];
print /td/tr;
   } while ($r = mysql_fetch_array($result));

   echo /table;
   mysql_free_result($result);
  }

Now, I know for sure that there's nothing wrong with the code within the
do-loop, because if I change the SQL query to the following:

$result = mysql_query(select * from complete);

..I will get all entries from the database, nicely output to the page.

(QUESTION 1)
So what is wrong here? I've tried playing with the single quotation marks
(') as well as using the LIKE parameter with the SELECT statement, but
nothing turns out to work. See below for an example of the latter..

$result = mysql_query(select * from complete where authorf like
'$authorf%');

This returns all table entries, just as the previous example. Perhaps there
is something about the '%' sign but I have no good reference available.. :-/

I also had an idea about the HTML form item names (such as text boxes) being
required to be named as the column names in the MySQL table, but that failed
miserably also (this is what I used in the examples below - substituting
form item names doesn't change anything..)

Now I'm sure that the error is a simple one, which tends to be make me even
more frustrated (I¨m practically bald now from tearing my tufts of hair all
night long :-) ). Thanks for any input here!

(QUESTION 2)
Also, another question relevant to PHP/SQL RDBMS's interfacing: Does anyoone
know where I can find thorough documents on PHP commands for this purpose?
Some texts which tangents database modelling and optimization would be
optimal, since I'm interested in those areas also!
Due to my current location in the Balkans with a crappy modem connection and
a bad selection of book stores I'd prefer online texts, but any tips are
welcome! Thanks in advance!

Video Populares et Optimates

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



Re: [PHP] Problem with SELECT statement and reference material wanted..

2003-10-23 Thread Marek Kilimajer
$authorf is empty, I guess register_globals is off, you should use
select * from complete where authorf = '$_POST[authorf]'
or
select * from complete where authorf = '$_GET[authorf]'
depending if you use get or post variable.
P M wrote:

Hi all!

I'm having trouble retrieving a selection of my database contents. The problem is when I search for entries that exactly match a search criteria, see below:

(database connection established successfully here..)

  $result = mysql_query(select * from complete where authorf = '$authorf');

  if ( $r = mysql_fetch_array($result) )
  {
   echo Found entries:ul;
   echo table border=1;
   do
   {
print trtd;
print $r[authorf];
print /tdtd;
print $r[authorl];
print /tdtd;
print $r[title];
print /td/tr;
   } while ($r = mysql_fetch_array($result));
   echo /table;
   mysql_free_result($result);
  }
Now, I know for sure that there's nothing wrong with the code within the do-loop, because if I change the SQL query to the following:

$result = mysql_query(select * from complete);

..I will get all entries from the database, nicely output to the page.

(QUESTION 1)
So what is wrong here? I've tried playing with the single quotation marks (') as well 
as using the LIKE parameter with the SELECT statement, but nothing turns out to work. 
See below for an example of the latter..
$result = mysql_query(select * from complete where authorf like '$authorf%');

This returns all table entries, just as the previous example. Perhaps there is something about the '%' sign but I have no good reference available.. :-/

I also had an idea about the HTML form item names (such as text boxes) being required to be named as the column names in the MySQL table, but that failed miserably also (this is what I used in the examples below - substituting form item names doesn't change anything..)

Now I'm sure that the error is a simple one, which tends to be make me even more frustrated (I¨m practically bald now from tearing my tufts of hair all night long :-) ). Thanks for any input here!

(QUESTION 2)
Also, another question relevant to PHP/SQL RDBMS's interfacing: Does anyoone know 
where I can find thorough documents on PHP commands for this purpose? Some texts which 
tangents database modelling and optimization would be optimal, since I'm interested in 
those areas also!
Due to my current location in the Balkans with a crappy modem connection and a bad 
selection of book stores I'd prefer online texts, but any tips are welcome! Thanks in 
advance!
Video Populares et Optimates



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


Re: [PHP] Problem with SELECT statement and reference material wanted..

2003-10-23 Thread Binay
Sorry for my previous post ..
no need of removing ' '(single quotes)

echo you query and then run it on mysql and see u getting the desired
result..

Binay
- Original Message -
From: P M [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, October 23, 2003 5:27 PM
Subject: [PHP] Problem with SELECT statement and reference material wanted..


Hi all!

I'm having trouble retrieving a selection of my database contents. The
problem is when I search for entries that exactly match a search criteria,
see below:

(database connection established successfully here..)

  $result = mysql_query(select * from complete where authorf =
'$authorf');

  if ( $r = mysql_fetch_array($result) )
  {
   echo Found entries:ul;
   echo table border=1;

   do
   {
print trtd;
print $r[authorf];
print /tdtd;
print $r[authorl];
print /tdtd;
print $r[title];
print /td/tr;
   } while ($r = mysql_fetch_array($result));

   echo /table;
   mysql_free_result($result);
  }

Now, I know for sure that there's nothing wrong with the code within the
do-loop, because if I change the SQL query to the following:

$result = mysql_query(select * from complete);

..I will get all entries from the database, nicely output to the page.

(QUESTION 1)
So what is wrong here? I've tried playing with the single quotation marks
(') as well as using the LIKE parameter with the SELECT statement, but
nothing turns out to work. See below for an example of the latter..

$result = mysql_query(select * from complete where authorf like
'$authorf%');

This returns all table entries, just as the previous example. Perhaps there
is something about the '%' sign but I have no good reference available.. :-/

I also had an idea about the HTML form item names (such as text boxes) being
required to be named as the column names in the MySQL table, but that failed
miserably also (this is what I used in the examples below - substituting
form item names doesn't change anything..)

Now I'm sure that the error is a simple one, which tends to be make me even
more frustrated (I¨m practically bald now from tearing my tufts of hair all
night long :-) ). Thanks for any input here!

(QUESTION 2)
Also, another question relevant to PHP/SQL RDBMS's interfacing: Does anyoone
know where I can find thorough documents on PHP commands for this purpose?
Some texts which tangents database modelling and optimization would be
optimal, since I'm interested in those areas also!
Due to my current location in the Balkans with a crappy modem connection and
a bad selection of book stores I'd prefer online texts, but any tips are
welcome! Thanks in advance!

Video Populares et Optimates

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



Re: [PHP] Problem with SELECT statement and reference material wanted..

2003-10-23 Thread Eugene Lee
On Thu, Oct 23, 2003 at 01:57:38PM +0200, P M wrote:
: 
: I'm having trouble retrieving a selection of my database contents. The
: problem is when I search for entries that exactly match a search
: criteria, see below:
: 
: (database connection established successfully here..)
: 
:   $result = mysql_query(select * from complete where authorf = '$authorf');

Try changing this to:

$result = mysql_query(select * from complete where authorf = '
. mysql_escape_string($authorf) . ');

: (QUESTION 2)
: Also, another question relevant to PHP/SQL RDBMS's interfacing: Does
: anyoone know where I can find thorough documents on PHP commands for
: this purpose? Some texts which tangents database modelling and
: optimization would be optimal, since I'm interested in those areas
: also!

If you're using MySQL, be sure to be familiar with PHP's MySQL functions.
And the User Contributed Notes is also a valuable source of information.

http://www.php.net/manual/en/ref.mysql.php

As for database optimizations, that more of a MySQL thing.  So you should
familiar yourself with MySQL's optimization documentation:

http://www.mysql.com/doc/en/MySQL_Optimisation.html

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