473,748 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sticking "if" or changes within a mySQL "where" array?

LRW
I'm not exactly sure how to even ask the question, and I know my terminology
is not good as I'm a SQL beginner, but, here goes.

I need to find a way to make an if statement within an array...or, the
"while" portion of a recordset.

The best way I can ask is show what I mean.
http://oscarguy.mechphisto.net/awardbrowse.php
If you go there and select an award (like Best Picture), leave the year
field alone, and select YES and submit, you'll see a lot of results. And I
have HR's dividing each entry.

What I need to do is group all the entries of the same year, or at least
only put HR's between the blocks of years.
So, I'd have all the entries for 2002, an HR, then all for 2001, an HR, etc.

Here at the bottom I'll include my PHP code I'm using so far.
But I have no idea where to even start looking for an answer...if it's even
possible.
If someone can just give me the name of the function or process or
technique, then I can go Web/book searching myself...I just need a direction
of where to go.

Thanks for any help!!
Liam
PHP:------------------------------------------------------------------------
------
$query_RS_award = "SELECT * FROM $award WHERE id != '1' ORDER BY year DESC,
w DESC";
//$query_RS_award = "SELECT * FROM $award WHERE year =
\"$year\"";
$RS_award = @mysql_query($q uery_RS_award, $connection) or
die("Couldn't query: " . mysql_error());
$totalRows_RS1 = mysql_num_rows( $RS_award);
while ($row_RS_award = mysql_fetch_ass oc($RS_award)) {
$award_id = $row_RS_award['id'];
$award_tblid = $row_RS_award['tblid'];
$award_award = $row_RS_award['award'];
$award_year = $row_RS_award['year'];
$award_category = $row_RS_award['category'];
$award_won = $row_RS_award['w'];
$award_film = $row_RS_award['film'];
$award_nominee = $row_RS_award['nominee'];
$award_note = $row_RS_award['note'];
if (!($award_categ ory)) {
$award_category = "n/a";
} else {
$award_category = $award_category ;
}
if ($award_won == "1") {
$award_won = " - Award Winner";
} else {
$award_won = "";
}
$display_block_ Award .= "YEAR:&nbsp;<sp an
class='normalTe xt12White'>$awa rd_year</span><br>FILM:& nbsp;<span
class='normalTe xt12White'>$awa rd_film</span><br>CATEGO RY:&nbsp;<span
class='normalTe xt12White'>$awa rd_category</span><br>NOMINE E:&nbsp;<span
class='normalTe xt12White'>$awa rd_nominee</span><span
class='normalTe xt12BoldWhite'> $award_won</span><br><block quote><span
class='normalTe xt12White'>$awa rd_note</span></blockquote><hr> ";
}
Jul 17 '05 #1
9 4399
On 2004-01-14, LRW <dr***@NOSPAHMc elticbear.com> wrote:
I need to find a way to make an if statement within an array...or, the
"while" portion of a recordset. What I need to do is group all the entries of the same year, or at least
only put HR's between the blocks of years.
So, I'd have all the entries for 2002, an HR, then all for 2001, an HR, etc.


// do the query
$year = '';

while ($row = mysql_fetch_ass oc($result)) {
if ($row['year'] != $year) {
echo '<hr/>';
$year = $row['year'];
}
// do other stuff
}
--
http://home.mysth.be/~timvw
Jul 17 '05 #2
LRW wrote:

I'm not exactly sure how to even ask the question, and I know my terminology
is not good as I'm a SQL beginner, but, here goes.

I need to find a way to make an if statement within an array...or, the
"while" portion of a recordset.

The best way I can ask is show what I mean.
http://oscarguy.mechphisto.net/awardbrowse.php
If you go there and select an award (like Best Picture), leave the year
field alone, and select YES and submit, you'll see a lot of results. And I
have HR's dividing each entry.

What I need to do is group all the entries of the same year, or at least
only put HR's between the blocks of years.
So, I'd have all the entries for 2002, an HR, then all for 2001, an HR, etc.

Here at the bottom I'll include my PHP code I'm using so far.
But I have no idea where to even start looking for an answer...if it's even
possible.
If someone can just give me the name of the function or process or
technique, then I can go Web/book searching myself...I just need a direction
of where to go.

Thanks for any help!!
Liam

PHP:------------------------------------------------------------------------
------
$query_RS_award = "SELECT * FROM $award WHERE id != '1' ORDER BY year DESC,
w DESC";
//$query_RS_award = "SELECT * FROM $award WHERE year =
\"$year\"";
$RS_award = @mysql_query($q uery_RS_award, $connection) or
die("Couldn't query: " . mysql_error());
$totalRows_RS1 = mysql_num_rows( $RS_award);
while ($row_RS_award = mysql_fetch_ass oc($RS_award)) {
$award_id = $row_RS_award['id'];
$award_tblid = $row_RS_award['tblid'];
$award_award = $row_RS_award['award'];
$award_year = $row_RS_award['year'];
$award_category = $row_RS_award['category'];
$award_won = $row_RS_award['w'];
$award_film = $row_RS_award['film'];
$award_nominee = $row_RS_award['nominee'];
$award_note = $row_RS_award['note'];
if (!($award_categ ory)) {
$award_category = "n/a";
} else {
$award_category = $award_category ;
}
if ($award_won == "1") {
$award_won = " - Award Winner";
} else {
$award_won = "";
}
$display_block_ Award .= "YEAR:&nbsp;<sp an
class='normalTe xt12White'>$awa rd_year</span><br>FILM:& nbsp;<span
class='normalTe xt12White'>$awa rd_film</span><br>CATEGO RY:&nbsp;<span
class='normalTe xt12White'>$awa rd_category</span><br>NOMINE E:&nbsp;<span
class='normalTe xt12White'>$awa rd_nominee</span><span
class='normalTe xt12BoldWhite'> $award_won</span><br><block quote><span
class='normalTe xt12White'>$awa rd_note</span></blockquote><hr> ";
}


To group results by year add "GROUP BY year" to your sql query. To insert <HR>s
between years, do it as you're printing the HTML code. Something like:

if ($currentyear != $previousyear)
echo "<HR>";

Also, be careful inputting your HTML variables directly into your SQL queries.
You may be exposing your server to SQL injection attacks. The following link
explains them, though not with PHP.

http://www.sitepoint.com/article/794

Regards,
Shawn
--
Shawn Wilson
sh***@glassgian t.com
http://www.glassgiant.com

I have a spam filter. Please include "PHP" in the
subject line to ensure I'll get your message.
Jul 17 '05 #3
LRW wrote:
I'm not exactly sure how to even ask the question, and I know my terminology
is not good as I'm a SQL beginner, but, here goes.

I need to find a way to make an if statement within an array...or, the
"while" portion of a recordset.

The best way I can ask is show what I mean.
http://oscarguy.mechphisto.net/awardbrowse.php
If you go there and select an award (like Best Picture), leave the year
field alone, and select YES and submit, you'll see a lot of results. And I
have HR's dividing each entry.

What I need to do is group all the entries of the same year, or at least
only put HR's between the blocks of years.
So, I'd have all the entries for 2002, an HR, then all for 2001, an HR, etc.

Here at the bottom I'll include my PHP code I'm using so far.
But I have no idea where to even start looking for an answer...if it's even
possible.
If someone can just give me the name of the function or process or
technique, then I can go Web/book searching myself...I just need a direction
of where to go.

Thanks for any help!!
Liam
PHP:------------------------------------------------------------------------
------
$query_RS_award = "SELECT * FROM $award WHERE id != '1' ORDER BY year DESC,
w DESC";
//$query_RS_award = "SELECT * FROM $award WHERE year =
\"$year\"";
$RS_award = @mysql_query($q uery_RS_award, $connection) or
die("Couldn't query: " . mysql_error());
$totalRows_RS1 = mysql_num_rows( $RS_award);
while ($row_RS_award = mysql_fetch_ass oc($RS_award)) {
$award_id = $row_RS_award['id'];
$award_tblid = $row_RS_award['tblid'];
$award_award = $row_RS_award['award'];
$award_year = $row_RS_award['year'];
$award_category = $row_RS_award['category'];
$award_won = $row_RS_award['w'];
$award_film = $row_RS_award['film'];
$award_nominee = $row_RS_award['nominee'];
$award_note = $row_RS_award['note'];
if (!($award_categ ory)) {
$award_category = "n/a";
} else {
$award_category = $award_category ;
}
if ($award_won == "1") {
$award_won = " - Award Winner";
} else {
$award_won = "";
}
$display_block_ Award .= "YEAR:&nbsp;<sp an
class='normalTe xt12White'>$awa rd_year</span><br>FILM:& nbsp;<span
class='normalTe xt12White'>$awa rd_film</span><br>CATEGO RY:&nbsp;<span
class='normalTe xt12White'>$awa rd_category</span><br>NOMINE E:&nbsp;<span
class='normalTe xt12White'>$awa rd_nominee</span><span
class='normalTe xt12BoldWhite'> $award_won</span><br><block quote><span
class='normalTe xt12White'>$awa rd_note</span></blockquote><hr> ";
}


The previous two responses are great. The only thing I have to add is
that the 10-cent name for the process you're describing is:
"Control-Break Processing." =)

A couple of links:
http://courses.dsu.edu/cis251/contro...nformation.htm
http://www.cs.uleth.ca/~huali/COBOL/Ch10_h.ppt
(That's a PowerPoint presentation.)

Regards,

- Dan
http://www.dantripp.com/
Jul 17 '05 #4
LRW
"Dan Tripp" <th*******@MyEM ailAddress.com> wrote in message
news:x4******** **********@news svr25.news.prod igy.com...
The previous two responses are great. The only thing I have to add is
that the 10-cent name for the process you're describing is:
"Control-Break Processing." =)

A couple of links:
http://courses.dsu.edu/cis251/contro...nformation.htm
http://www.cs.uleth.ca/~huali/COBOL/Ch10_h.ppt
(That's a PowerPoint presentation.)


Thanks guys!! I really appreciate the help!!
I'll give the suggestions a try, and look deeper into "Control-Break
Processing."
Thanks again!
Liam
Jul 17 '05 #5
On Wed, 14 Jan 2004 15:14:49 -0400, Shawn Wilson
<sh***@glassgia nt.com> wrote:
To group results by year add "GROUP BY year" to your sql query. To insert <HR>s
between years, do it as you're printing the HTML code. Something like:
GROUP BY is only necessary if you're using any of the aggregate
functions, for example, if you wanted to find out how many awards were
presented in each year.

For "control break processing", DESC and your code:
if ($currentyear != $previousyear)
echo "<HR>";


is fine.

--
David ( @priz.co.uk ). <http://www.priz.co.uk/ipdb/>
The Tarbrax Chronicle: <http://www.tarbraxchro nicle.com/>
"You too will eventually die and become a ghost. It may be in 50
years; it may be tomorrow; it may even be today."
Jul 17 '05 #6
LRW
"Tim Van Wassenhove" <eu**@pi.be> wrote in message
news:bu******** ****@ID-188825.news.uni-berlin.de...
// do the query
$year = '';

while ($row = mysql_fetch_ass oc($result)) {
if ($row['year'] != $year) {
echo '<hr/>';
$year = $row['year'];
}
// do other stuff
}


Huzzah! It works!
Thank you thank you! =)
Liam
Jul 17 '05 #7
LRW
"Shawn Wilson" <sh***@glassgia nt.com> wrote in message
news:40******** *******@glassgi ant.com...
Also, be careful inputting your HTML variables directly into your SQL queries. You may be exposing your server to SQL injection attacks. The following link explains them, though not with PHP.

http://www.sitepoint.com/article/794


Thanks for the tip! I had no idea!
That's some good info. But I have a questions...doe s mySQL use storedprocs
like "xp_cmdshel l" likeMS-SQL?

Thanks!
Liam
Jul 17 '05 #8
On Thu, 15 Jan 2004 16:09:51 GMT, "LRW" <dr***@NOSPAHMc elticbear.com>
wrote:
"Shawn Wilson" <sh***@glassgia nt.com> wrote in message
news:40******* ********@glassg iant.com...
Also, be careful inputting your HTML variables directly into your SQL

queries.
You may be exposing your server to SQL injection attacks. The following

link
explains them, though not with PHP.

http://www.sitepoint.com/article/794


Thanks for the tip! I had no idea!
That's some good info. But I have a questions...doe s mySQL use storedprocs
like "xp_cmdshel l" likeMS-SQL?


MySQL does not yet support stored procedures, but it depends on what
you want to do.

E.g., in SQL Server, sp_tables retutrns a list of tables, MySQL allows
you to use SHOW TABLES to accomplish the same thing.

Whatever you are doing with xp_cmdshell is probably possible by other
means. The only reason xp_cmdshell exists is as a back-door for the
SQL Server client tools.

--
David ( @priz.co.uk )
Jul 17 '05 #9
LRW
"David Mackenzie" <me@privacy.net > wrote in message
news:3l******** *************** *********@4ax.c om...
On Thu, 15 Jan 2004 16:09:51 GMT, "LRW" <dr***@NOSPAHMc elticbear.com>
wrote:

MySQL does not yet support stored procedures, but it depends on what
you want to do.

E.g., in SQL Server, sp_tables retutrns a list of tables, MySQL allows
you to use SHOW TABLES to accomplish the same thing.

Whatever you are doing with xp_cmdshell is probably possible by other
means. The only reason xp_cmdshell exists is as a back-door for the
SQL Server client tools.


OK, I was just concerened because one of the threats that article points out
is default stored procs in MS-SQL, and suggesting removing a couple like
xp_cmdshell. I just didn't know if I needed to beware of a similar threat in
mySQL.
Thanks again!!
Liam
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
11121
by: lawrence | last post by:
Google can't find me a good example of how to use the "if exists" syntax in MySql. Is it right that to use it this way: INSERT INTO IF EXISTS tMyTable VALUES("xxlk", "lkjlkjlkjljk") I want to insert into a table but only if the table exists. How does one, in general, from PHP, test for the existence of a table, without getting an error message?
5
6694
by: Jason Charalambides | last post by:
I set a program to automatically load values from a temporary file. However, there is a chance that the specific temporary file "C:\Temp\TU.tmp" may not exist at all. In that case I want that specific routine to be skipped. I guess this is a simple If (that file exists) Open "C:\Temp\TU.tmp" For Input As #3 etc....... Else GoTo
0
4099
by: Yann GAUTHERON | last post by:
Hi, ID_LOGIN is an integer Can anyone say me if this : WHERE index1=ID_LOGIN OR index2=ID_LOGIN must be slower than those 2 queries :
40
3038
by: Steve Juranich | last post by:
I know that this topic has the potential for blowing up in my face, but I can't help asking. I've been using Python since 1.5.1, so I'm not what you'd call a "n00b". I dutifully evangelize on the goodness of Python whenever I talk with fellow developers, but I always hit a snag when it comes to discussing the finer points of the execution model (specifically, exceptions). Without fail, when I start talking with some of the "old-timers"...
145
6319
by: Sidney Cadot | last post by:
Hi all, In a discussion with Tak-Shing Chan the question came up whether the as-if rule can cover I/O functions. Basically, he maintains it can, and I think it doesn't. Consider two programs: /*** a.c ***/
35
2731
by: David Cleaver | last post by:
Hello all, I was wondering if there were some sort of limitations on the "if" statement? I'm writing a program which needs to check a bunch of conditions all at the same time (basically). And I'm pretty sure the rest of the program is working just fine. The only thing I could think might be wrong is that the if statement can only hold so many values in itself? Let me show what I'm doing: if (table001]>>5]&b&0x1f] != 0 &&
13
2819
by: andro | last post by:
Hi everybody! I have several tables from which I want to exract the SAME value (along with other referenced data). All the values are in the same column within the tables. How can I achieve this? TIA. Andro
37
3977
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as a function
33
3275
by: Snis Pilbor | last post by:
With the "as if" rule in play, doesn't that effectively render the "register" keyword completely useless? Example: I make a silly compiler which creates code that goes out of its way to take a full 10 minutes every time a "register" declared variable is read from or written to. Besides this lag, everything else runs as expected. Then my compiler is still C compliant, aye? If so, then it is unwise for any programmer to ever use the...
0
8822
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9528
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9236
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8235
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6792
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4592
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3298
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.