PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old June 19th, 2002, 07:53 PM
ivan8r ivan8r is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 ivan8r User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to ivan8r
My query keeps failing... need help

I'll start off by letting you all know that I am a newbie and I'm still trying to understand PHP. I've got a query which looks simple enough, but it keeps failing...

$record= "SELECT MAX (id) FROM quickbooks";
$query = "SELECT * FROM quickbooks WHERE id=$record";
$result = mysql_query($query) or die("Select Failed!");

In this case, I keep getting Select Failed! as my result instead of the data I'm trying to get. What did I do wrong?

Ivan8r

Reply With Quote
  #2  
Old June 19th, 2002, 08:05 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: My query keeps failing... need help

The problem on this one is that mysql does not support nested select statements. You can redo the query like this though:

$query = "SELECT * FROM quickbooks ORDER BY id DESC LIMIT 1"

that should get you the row with the max id..


Reply With Quote
  #3  
Old June 20th, 2002, 01:55 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
RE: My query keeps failing... need help

The previous post is absolutely correct and you should follow his/her advise.

However, I just want to clarify somethings for you.

The doesn't work because you _NEVER_ queried the db for the max id. All you did is create a variable holding the query string. The overall logic that you are using is fine you just need to learn some more syntax.

You could also get this to work using the logic that you first came up with like this:

// Get the MAX(id)
$query_maxId = "select max(id) from quickbooks";
$result_maxId = mysql_query($query_maxId);
$row_maxId = mysql_fetch_array($result_maxId);

// Now you have the MAX(id), get remaining info
$query = "select * from quickbooks where id='".$row_maxId['id']."'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

As you can see, using the previous post is easier/quicker/faster. But since you said you were new to this and that yu tried using $record, just thought I would explain why yours did not work in more detail.

Hope that helps.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > My query keeps failing... need help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway