Solved

Why aren't all queries taken care of?

Posted on 2014-03-16
7
170 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 108

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 108

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
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 …

914 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now