astralaaron Posted February 2, 2010 Share Posted February 2, 2010 I've been looking for some information on the {} in an SQL statement. will someone explain them to me? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 2, 2010 Share Posted February 2, 2010 Where have you seen that used? Link to comment Share on other sites More sharing options...
astralaaron Posted February 2, 2010 Author Share Posted February 2, 2010 mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB");$page = intval($_GET );if ($page < 1) $page = 1;$per_page = 5;$start = (($page - 1) * $per_page);$sql="SELECT * FROM $tbl_name ORDER BY id DESC LIMIT {$start}, {$per_page}";// OREDER BY id DESC is order result by descending $result=mysql_query($sql); This is obviously just part of the code, but the SQL is there. Someone from this forum wrote the code for me a few years back.It was really helpful, and works perfectly. But, I would like to understand the brackets in there. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 2, 2010 Share Posted February 2, 2010 Those characters aren't part of the SQL, that's part of the PHP. If you print $sql you'll see what I mean. That's the way to embed a variable in a string in PHP. Link to comment Share on other sites More sharing options...
astralaaron Posted February 3, 2010 Author Share Posted February 3, 2010 Those characters aren't part of the SQL, that's part of the PHP. If you print $sql you'll see what I mean. That's the way to embed a variable in a string in PHP.ok, I see that now. but can you clarify for me why in this line:$sql="SELECT * FROM $tbl_name ORDER BY id DESC LIMIT {$start}, {$per_page}";$tble_name doesn't need this as well? variables usually display fine within a double quote string.Is it so that it is still looked at as an integer instead of a string? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 4, 2010 Share Posted February 4, 2010 A regular variable doesn't need the brackets, it's just good practice to use them. Some types of variables or situations do require them. Link to comment Share on other sites More sharing options...
astralaaron Posted February 4, 2010 Author Share Posted February 4, 2010 A regular variable doesn't need the brackets, it's just good practice to use them. Some types of variables or situations do require them.thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.