Welcome Guest ( Log In | Register )


Why register for free on WebRadiance?
Welcome to WebRadiance forums! WebRadiance is a place for discussion and help on a large range of web design and development related topics such as HTML, CSS, ASP & .NET, PHP and SEO. It is provided for free, without ads and is a friendly place for beginners and professionals alike. By joining us today you can take part in our rapidly growing community.

Registering enables you to:
  • have your say by posting new messages and taking part in topics and polls
  • keep up to date with the latest news and trends in the web design and development world
  • send private messages to other members
  • have your questions answered by our knowledgeable community
  • add a link to your website in our links area
  • receive emails when someone replies to your posts

Combining CONSTANTS with MySQL queries

 
Reply to this topicStart new topic
> Combining CONSTANTS with MySQL queries,
Beavis
post Jul 30 2008, 10:15 PM
Post #1


W.R. Corporal
Group Icon

Group: Members
Posts: 166
Joined: 24-March 08
Member No.: 883



This is another kind of newbie question that I hope someone can help with.

The following query works fine.

CODE
$getDetails = "SELECT * FROM gallery_item LIMIT 0,6";


as does this

CODE
$getDetails = "SELECT * FROM gallery_item ORDER BY gallery_id DESC";


The idea is to later adapt the script to page through a set of results.
I combined the two with this

CODE
$getDetails = "SELECT * FROM gallery_item ORDER BY gallery_id DESC LIMIT $startRow,$showmax";


where $startRow is dynamically generated and $showmax is derived from a PHP constant
CODE
define('SHOWMAX', 6);
$showmax = SHOWMAX;


but this last bit seems redundant so I was wondering how to insert a PHP constant directly into a MySQL query.
I tried a few options but none seems to work.

This post has been edited by Beavis: Jul 30 2008, 10:39 PM
Go to the top of the page
 
+Quote Post
Rob Kaper
post Jul 31 2008, 02:26 AM
Post #2


W.R. Corporal
Group Icon

Group: Members
Posts: 52
Joined: 19-July 08
From: Rotterdam, NLD
Member No.: 1,069



CODE
// concatenation
$getDetails = "SELECT * FROM gallery_item ORDER BY gallery_id DESC LIMIT ". STARTROW. ",". SHOWMAX;

// or sprintf?
$getDetails = sprintf( "SELECT * FROM gallery_item ORDER BY gallery_id DESC LIMIT %d, %d", STARTROW, SHOWMAX );


(and many many more should work)


--------------------
Go to the top of the page
 
+Quote Post
TJSingleton
post Jul 31 2008, 09:53 AM
Post #3


Allegedly Legendary
Group Icon

Group: Members
Posts: 512
Joined: 31-July 06
From: Winder, GA
Member No.: 11



or prepared statements: http://dev.mysql.com/tech-resources/articl...statements.html


--------------------
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
Tags
No Tag inserted yet

1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 3rd December 2008 - 04:48 PM
Contact Us
Web Design Forum | Web Development Forum | Web Help