|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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.. |
|
#3
|
|||
|
|||
|
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. |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > My query keeps failing... need help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|