Hi,
I have a table, and I wish to return (for e.g.) row 1 and row 30 from the table, regardless of the index associated with each. In other words, for a given query, I want to return row 1 and 30 into a couple of variables.
I could do this using PHP and using a while() loop and index counter to retrieve rows 1 and 30 for a given query, however this seems to be a bit of an inefficient way of doing it.
Is it possible to do this using a straight query, for a example using LIMIT (a MySQL function I am finding it very difficult to find any online guide to!?)
Many thanks in advance
Mark
MySQL queries - do I need to build a PHP function for this?
Moderator: General Moderators
Code: Select all
SELECT * FROM table LIMIT 5,10; # Retrieve rows 6-15Hi there,
Thanks for your help. Can you tell me what is wrong with the syntax of this query (it's giving me a syntax error towards the end of the query statement).
Many thanks
Mark
Thanks for your help. Can you tell me what is wrong with the syntax of this query (it's giving me a syntax error towards the end of the query statement).
Code: Select all
SELECT * FROM Properties WHERE (ConsultancyID=''1'') ORDER BY PropertyTitle LIMIT 0,1Mark
correct it that
Code: Select all
SELECT * FROM Properties WHERE ConsultancyID='1' ORDER BY PropertyTitle LIMIT 0,1Strange 'Invalid MySQL resource' warning
Code: Select all
$result = mysql_query($query);
if(!$result)
{
do_html_message('Error: Could not perform MySQL query - '.mysql_error());
do_html_footer();
exit();
}
while( $row = mysql_fetch_array( $result ) )
...Any idea what could be causing this? $result is the correct variable returned by mysql_query.
Cheers
Mark