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

From: Binay (binay_at_oliveinternet.com)
Date: 10/23/03


To: "P M" <pmelist@home.se>, <php-general@lists.php.net>
Date: Thu, 23 Oct 2003 17:45:37 +0530

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" <pmelist@home.se>
To: <php-general@lists.php.net>
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 "<tr><td>";
    print $r["authorf"];
    print "</td><td>";
    print $r["authorl"];
    print "</td><td>";
    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



Relevant Pages

  • Ordering on Hierarchical Dot Notation
    ... I have a SQL database (MySql) containing a table with a key column which ... The problem is that this column is proving very difficult to sort naturally ... users still want to query the database using the natural representation. ...
    (comp.lang.java.databases)
  • Ordering on Hierarchical Dot Notation
    ... I have a SQL database (MySql) containing a table with a key column which ... The problem is that this column is proving very difficult to sort naturally ... users still want to query the database using the natural representation. ...
    (comp.lang.java.programmer)
  • Re: Access Table Sorting/Query Last Function
    ... I've put in a number of test entries to ensure it works, ... of the Lastin your totals query. ... I've been designing a database that basically works off two tables. ... I've done this so that I can pull the last entered ...
    (microsoft.public.access.tablesdbdesign)
  • SQL Server - Very long query time with OpenJPA and Hibernate
    ... I have a table with close to a million entries. ... Query Analyzer to obtain results within say 3 seconds. ... That's on a production server, ... that the program is the only thing accessing the database server. ...
    (comp.lang.java.databases)
  • Re: C client to load binary data to MySQL
    ... to the C standard you're only allowed to compare pointers pointing ... Since one is unlikely to be constructing a query string anywhere even close to 30000 characters long I would say this makes it safe for all implementations without being any harder to read. ... To the OP, if you need further help with the MySQL parts of this, such as the load_image function and connecting to the database, please take it to a suitable group, possibly one with mysql or database in its name, or the MySQL mailing lists. ...
    (comp.lang.c)