Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Why aren't all queries taken care of?

Posted on 2014-03-16
7
Medium Priority
?
188 Views
Last Modified: 2014-03-16
aktuellt.php

This code outputs $SQL1 like this:
SQL1: SELECT * FROM evenemang ORDER BY resanr ASC LIMIT 1
SQL1: SELECT * FROM evenemang ORDER BY resanr ASC LIMIT 1,1
SQL1: SELECT * FROM evenemang ORDER BY resanr ASC LIMIT 1,2
SQL1: SELECT * FROM evenemang ORDER BY resanr ASC LIMIT 1,3
SQL1: SELECT * FROM evenemang ORDER BY resanr ASC LIMIT 1,4
SQL1: SELECT * FROM evenemang ORDER BY resanr ASC LIMIT 1,5
SQL1: SELECT * FROM evenemang ORDER BY resanr ASC LIMIT 1,6
SQL1: SELECT * FROM evenemang ORDER BY resanr ASC LIMIT 1,7
SQL1: SELECT * FROM evenemang ORDER BY resanr ASC LIMIT 1,8
SQL1: SELECT * FROM evenemang ORDER BY resanr ASC LIMIT 1,9
but it does not print the very first line. However. all the other lines are printed.
Could you experts, please, help me to get also the very first line to query and print.
0
Comment
Question by:lericson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39932895
Please post the CREATE TABLE statement and a few rows of test data.  I would like to give you a tested and working example.  Thanks, ~Ray
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39932905
Unrelated, but you might want to consider getting off the MySQL extension.  PHP is doing away with it.  This article explains why and what you must do to keep your scripts running in the future.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0
 
LVL 58

Expert Comment

by:Gary
ID: 39932920
Code makes absolutely no sense!
Why are you selecting all records just to get the number of rows?
Then you have a loop equal to number of records (without using the data) and 'create' sql statements that you never use except for the very last one that is created? Which you could easily get just by doing
$SQL1 = "SELECT * FROM evenemang ORDER BY resanr ASC LIMIT 1,$n";

What are you trying to do?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39932988
Agree with Gary (I usually do) and I hope you can show us the data structure and describe the business objectives in your application.  There are probably good design patterns that can help you, if we can understand the overall goals.
0
 

Author Comment

by:lericson
ID: 39933060
I am trying to achieve the following:

In the database I have n lines of records. I want to display these records one by one, one after the other,
I tried to single them out and present them by using this piece of code:
$SQL100 = "SELECT * FROM evenemang ORDER BY resanr ASC LIMIT 1,$i";
That works for all but the one with the lowest "resanr" value. I trust code like "LIMIT 1,0" does not work. Therefore I tried to grab hold of that record and use the if sentence
if($SQL100 == "SELECT * FROM evenemang ORDER BY resanr ASC LIMIT 1,0")
{
      $SQL1 = "SELECT * FROM evenemang ORDER BY resanr ASC LIMIT 1";
}
to convert it from "LIMIT 1,0" to "LIMIT 1". That doesn't work for one reason or the other.
I wanted to see all the queries produced by the code piece  echo "SQL1: ".$SQL1."<br />";. To my satisfaction also the line with"LIMIT 1" is printed out. But it is not used when listing all the records.
The values used in the test for "$beskrivning" are as follows:

Where resanr equals                       The value for beskrivning is
  1                                                             Resa 1
  2                                                             Resa 2
  3                                                             Resa 3
  ...
  9                                                             Resa 9

I had expected to see an output like the following
Resa 1
Resa 2
Resa 3
...
Resa 9

But instead I get
Resa 2
Resa 3
...
Resa 9
Resa 1 is lacking. I would like to show all the n (in this case n=9) values.
The problem is probably associated with the code "LIMIT 1,$n". But I don't know what code to use so I get all the n records.
0
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 39933065
Why are you limiting if you want all records? Just do

$SQL1 == "SELECT * FROM evenemang ORDER BY resanr ASC")

$ret1 = mysql_query($SQL1);
if (!$ret1) { echo( '[1] '.mysql_error()); }
else {
while ($row = mysql_fetch_array($ret1)) {
// echo our your rows

Open in new window


All the other code is just a waste.
0
 

Author Closing Comment

by:lericson
ID: 39933078
Thanks Gary!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question