?
Solved

Why aren't all queries taken care of?

Posted on 2014-03-16
7
Medium Priority
?
185 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

771 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