Solved

Why aren't all queries taken care of?

Posted on 2014-03-16
7
176 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
  • 3
  • 2
  • 2
7 Comments
 
LVL 109

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 109

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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 109

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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

829 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