Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,493 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,707 people online right now. Registration is fast and FREE... Join Now!




Select command problem

 
Reply to this topicStart new topic

Select command problem, Select command error

david4u
29 Jan, 2008 - 10:43 AM
Post #1

New D.I.C Head
*

Joined: 26 Apr, 2006
Posts: 38



Thanked: 1 times
My Contributions
Hello,

I am having an error when using select command in my PHP code below:

CODE


if ($find == "")
{
echo "<p>Please enter a search parameter";
exit;
}

// Otherwise we connect to our Database
mysql_connect("database","username","password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());

// We preform a bit of filtering
$find = strtoupper($find);
$find = trim ($find);



//Now we search for our search term, in the field the user specified        

$data = mysql_query("SELECT p.Author_ID,a.Author_Name from
                            PUBLICATION AS p, AUTHORS AS a  where
                            p.Author_ID=a.Author_ID
                            AND
                            a.Author_Name = 'upper($field) LIKE'%$find%''");






Can anyone help with the right command to use for the select. I am trying to call the $find field but nothing shows up.

Could anyone help.

Thanks.

This post has been edited by david4u: 29 Jan, 2008 - 11:27 AM
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Select Command Problem
29 Jan, 2008 - 10:49 AM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 3,994



Thanked: 16 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
are you sure this table/field exists?
What error do you receive?
User is online!Profile CardPM
+Quote Post

dontKnowJava
RE: Select Command Problem
29 Jan, 2008 - 10:49 AM
Post #3

D.I.C Head
**

Joined: 29 Sep, 2007
Posts: 213


My Contributions
try this
CODE

$connect = mysql_connect("mysql.ee.port.ac.uk","cam41606","omop2856") or die(mysql_error());
$select = mysql_select_db("cam41606") or die(mysql_error());

User is offlineProfile CardPM
+Quote Post

baavgai
RE: Select Command Problem
29 Jan, 2008 - 11:09 AM
Post #4

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,031



Thanked: 105 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
A couple things. I'm not sure you can use "tableName as a"; I believe you have to drop the "as" for that.

The "... a.Author_Name = 'upper($field) LIKE'%$find%''" looks odd and probably wont do what you're looking for. Certainly won't work in SQL.

Here's some syntatically correct SQL. See if you can take it from there.

CODE

    SELECT p.Author_ID, a.Author_Name
        from PUBLICATION p
            inner join AUTHORS a
                on p.Author_ID=a.Author_ID
        where upper(a.Author_Name) like '%KIN%'


Hope this helps.

User is offlineProfile CardPM
+Quote Post

david4u
RE: Select Command Problem
29 Jan, 2008 - 11:34 AM
Post #5

New D.I.C Head
*

Joined: 26 Apr, 2006
Posts: 38



Thanked: 1 times
My Contributions
This is the error :


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in test/u_p_s_author.php on line 49



Did I miss anything?

QUOTE(dontKnowJava @ 29 Jan, 2008 - 11:49 AM) *

try this
CODE

$connect = mysql_connect("database","username","password") or die(mysql_error());
$select = mysql_select_db("database") or die(mysql_error());




That's not a problem: The problem is the select command

QUOTE(baavgai @ 29 Jan, 2008 - 12:09 PM) *

A couple things. I'm not sure you can use "tableName as a"; I believe you have to drop the "as" for that.

The "... a.Author_Name = 'upper($field) LIKE'%$find%''" looks odd and probably wont do what you're looking for. Certainly won't work in SQL.

Here's some syntatically correct SQL. See if you can take it from there.

CODE

    SELECT p.Author_ID, a.Author_Name
        from PUBLICATION p
            inner join AUTHORS a
                on p.Author_ID=a.Author_ID
        where upper(a.Author_Name) like '%KIN%'


Hope this helps.





Thanks. But I want to view all authors in the database without select one name after the other. If I have 10 authors, I want select 5 authors with different publication at the same time not selecting them one by one. NO.

Thanks.
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Select Command Problem
29 Jan, 2008 - 11:41 AM
Post #6

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,031



Thanked: 105 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
QUOTE(david4u @ 29 Jan, 2008 - 02:34 PM) *

Thanks. But I want to view all authors in the database without select one name after the other.


CODE
SELECT a.Author_ID, a.Author_Name from AUTHORS a



QUOTE(david4u @ 29 Jan, 2008 - 02:34 PM) *

I want select 5 authors with different publication at the same time not selecting them one by one.


Sorry, only you know your database structure. I was just trying to show something that worked, given the non working example presented.

User is offlineProfile CardPM
+Quote Post

david4u
RE: Select Command Problem
31 Jan, 2008 - 06:11 AM
Post #7

New D.I.C Head
*

Joined: 26 Apr, 2006
Posts: 38



Thanked: 1 times
My Contributions
Thanks, I have corrected it. It is working now

Dav.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 07:55PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month