ramone_johnny Posted April 13, 2013 Share Posted April 13, 2013 Can someone tell me if this is right? $r2=query_wrapper("SELECT * FROM tblphotos WHERE tblph_shareID = ?",$rstDBEdit["share_ID"]). " ORDER BY tblph_shareID DESC LIMIT 1"; I'm getting the following error.... Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in (line 35) ....which is if($rstDBEdit2=mysql_fetch_assoc($r2)) Here's the code in it's entirity $r2=query_wrapper("SELECT * FROM tblphotos WHERE tblph_shareID = ?",$rstDBEdit["share_ID"]). " ORDER BY tblph_shareID DESC LIMIT 1"; if($rstDBEdit2=mysql_fetch_assoc($r2)) { $fname = $rstDBEdit2["tblph_filename"]; $id = $rstDBEdit2["tblph_shareID"]; $image = $blogpath.$rstDBEdit["tblph_ID"]."/small_".$fname; $virtualPath = $shareurl.$rstDBEdit["tblph_ID"]."/small_".$fname; Quote Link to comment Share on other sites More sharing options...
requinix Posted April 13, 2013 Share Posted April 13, 2013 (edited) Putting aside the fact that you put the ORDER BY stuff in the wrong place (you're concatenating it with the share_ID, not with the query), apparently query_wrapper() returned a string. Why is that? What does the function do? What's the code? [edit] And to answer the question in the title and not in your post... not even close to what's in your post... T-SQL's TOP N is equivalent to MySQL's LIMIT N. As it seems you've found out. Edited April 13, 2013 by requinix Quote Link to comment Share on other sites More sharing options...
ramone_johnny Posted April 13, 2013 Author Share Posted April 13, 2013 Would you mind helping me get this query right? My background is ASP/MSSQL. This is what I currently have. $share_ID = $rstDBEdit["share_ID"];$r2=query_wrapper("SELECT * FROM tblphotos WHERE tblph_shareID = ", $share_ID. " ORDER BY tblph_ordering ASC LIMIT 1"); Quote Link to comment Share on other sites More sharing options...
ramone_johnny Posted April 13, 2013 Author Share Posted April 13, 2013 By the way, I was asking about TOP because I'm trying to conver this MSSQL query. strSQL2 = "SELECT TOP 1 * FROM tblphotos WHERE tblph_shareID = " & SQLNumber(rstDBEdit("share_ID")) & " ORDER BY tblph_ordering ASC" Quote Link to comment Share on other sites More sharing options...
requinix Posted April 13, 2013 Share Posted April 13, 2013 (edited) Yeah, you've got the right overall query, but look at that function call more carefully. query_wrapper("SELECT * FROM tblphotos WHERE tblph_shareID = ", $share_ID. " ORDER BY tblph_ordering ASC LIMIT 1")You're passing two arguments. The first one is SELECT * FROM tblphotos WHERE tblph_shareID = and the second one (if $share_ID=123) is 123 ORDER BY tblph_ordering ASC LIMIT 1. That's surely not how the function is supposed to work. However the function returns a string. That's odd. What does the function do and how is it supposed to work? Edited April 13, 2013 by requinix Quote Link to comment Share on other sites More sharing options...
ramone_johnny Posted April 13, 2013 Author Share Posted April 13, 2013 Sorry, I'm working with someone elses code. I'm not sure what the function does. Quote Link to comment Share on other sites More sharing options...
ramone_johnny Posted April 13, 2013 Author Share Posted April 13, 2013 Where do I put the order by????? $r2=query_wrapper("SELECT * FROM tblphotos ORDER BY tblph_shareID DESC LIMIT 1 WHERE tblph_shareID = ?", $share_ID); Quote Link to comment Share on other sites More sharing options...
requinix Posted April 13, 2013 Share Posted April 13, 2013 (edited) You had the right order before, it just wasn't all together. SELECT * FROM tblphotos WHERE tblph_shareID = ? ORDER BY tblph_shareID DESC LIMIT 1If that doesn't work, please post the code for query_wrapper(). [edit] Third edited post in a row Your query is wordier than it needs to be: you're searching by the shareID so there's no point sorting by it. SELECT * FROM tblphotos WHERE tblph_shareID = ? LIMIT 1And if the tblph_shareID is unique in the table then you don't even need the LIMIT. Edited April 13, 2013 by requinix Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.