Jump to content

Combining CONSTANTS with MySQL queries

Whether you're a seasoned veteran or a struggling beginner, Web Radiance is the web development and web design forum for you. You'll find answers to all your HTML, CSS, SEO, and Programming needs. Pull up a chair and stay awhile.

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Combining CONSTANTS with MySQL queries Rate Topic: -----

#1 User is offline   Beavis 

  • W.R. Corporal
  • Group: Members
  • Posts: 167
  • Joined: 24-March 08

Posted 30 July 2008 - 10:15 PM

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

The following query works fine.

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


as does this

$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

$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
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: 30 July 2008 - 10:39 PM

0

#2 User is offline   Rob Kaper 

  • W.R. Corporal
  • Group: Members
  • Posts: 97
  • Joined: 19-July 08
  • Gender:Male
  • Location:Rotterdam, NLD

Posted 31 July 2008 - 02:26 AM

// 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)
Rob Kaper - Rotterdam
0

#3 User is offline   TJSingleton 

  • Allegedly Legendary
  • Group: Members
  • Posts: 517
  • Joined: 31-July 06
  • Location:Winder, GA

Posted 31 July 2008 - 09:53 AM

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users