473,657 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Newbie having trouble finding the good loop

2 New Member
Hello,
First of all please excuse my vocabulary, english isn't my mother tong.
I'm having a hard time trying to do this.
I have two tables in a MySQL db, first one is for members datas, second one if the one for french departments (geography).
I need to have a list of every department followed by the list of members that are living in this department (after it will be parsed to a Flash animation in a dynamic text box).
Here is my code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //getting every department, sorted by name
  3. $variables="SELECT * FROM membres_regions ORDER BY 'Var_flash'";
  4. $resultat=mysql_query ($variables);
  5.  
  6. //as long as we have a department
  7. while( $var=mysql_fetch_array ($resultat) ){
  8.  //getting the variables
  9. $flashvar=$var['Var_flash'];
  10. $region=$var['Region'];
  11. //shows each department
  12. echo "$flashvar=";
  13. //get breeders, sorted by pas Affixe
  14. $query_eleveurs = "SELECT * FROM membres_aacas WHERE Region='$region' AND Publication='Oui' ORDER BY Affixe";
  15.        $result_eleveurs = mysql_query($query_eleveurs);
  16.   while( $eleveurs = mysql_fetch_array($result_eleveurs) ){
  17.  
  18.         $popup=$eleveurs['popup'];
  19.         $affixe=$eleveurs['Affixe'];
  20.         $race=$eleveurs['Race'];
  21.         $chaton=$eleveurs['chatons'];
  22.  
  23.     echo "<a href=\"asfunction:popup,../chatteries/$popup\"><b>$affixe</b></a><br>$race - $chaton<br>";    
  24.     }    
  25. }
  26. mysql_close();
  27. ?> 
My problem is that I get this kind of list:
&ain=breeder xx breed ii
&aisne=
&allier=
&alpesdehautepr ovence=
&alpesmaritimes =breeder yy breed jj

And I would like to have :
&ain=breeder xx breed ii
&aisne=No breeder !
&allier=No breeder !
&alpesdehautepr ovence=No breeder !
&alpesmaritimes =breeder yy breed jj

I know that my second querry is an obstacle to obtain this result because it shows only "true" results : "WHERE Region='$region ' "
But I cant figure out how to get what I need...
If someone here could help, this would be wonderfull... I really am a beginner so please, be patient !
Thank you very much.
Oct 14 '06 #1
2 1509
jonndoe45
3 New Member
Not sure which fields this applies to as you you have specified the field names in your code - and my french is non-existent, so here goes:

Here is your existing code:

$query_eleveurs = "SELECT * FROM membres_aacas WHERE Region='$region ' AND Publication='Ou i' ORDER BY Affixe";
$result_eleveur s = mysql_query($qu ery_eleveurs);
while( $eleveurs = mysql_fetch_arr ay($result_elev eurs) ){

$popup=$eleveur s['popup'];
$affixe=$eleveu rs['Affixe'];
$race=$eleveurs['Race'];
$chaton=$eleveu rs['chatons'];



You have 2 options.

1. instead of doing (for example) $affixe=$eleveu rs['Affixe'];

do:

if ( empty($eleveurs['Affixe']) ){
$affixe = "no breeder" ;}
else {
$affixe=$eleveu rs['Affixe'];}

Explanation:

if the value of the affixe column is empty then set the affixe variable to 'no breeder' otherwise (else) set it to the value of the affixe column

2. or in the SQL you can do:

$query_eleveurs = "SELECT popup, if(length(affix e)>0,affixe, 'no breeder'), race, chatons FROM membres_aacas WHERE Region='$region ' AND Publication='Ou i' ORDER BY Affixe";


Explanation:

each field is specified in the sql statement

for the affixe column we do a test inside the sql statement

if the length of the affixe column is greater than 0 (i.e it has a value) then return the value of the affixe column, otherwise return the user defined value 'no breeder'

just using the affixe column as an example - not sure which ones you want to set to no breeder.

hope this helps
jonndoe45
Oct 15 '06 #2
Damas
2 New Member
Thank you very much JonnDo I finally had what I want using a "if" outside the second "while" :
[php]$popup=$eleveur s['popup'];
$affixe=$eleveu rs['Affixe'];
$reg=$eleveurs['Region'];
$race=$eleveurs['Race'];
$chaton=$eleveu rs['chatons'];

echo "<a href=\"asfuncti on:popup,../chatteries/$popup\"><b>$af fixe</b></a><br>$race - $chaton<br>";
}

if ( $reg <> $region) echo "Il n'y a pas d'&eacute;leveu rs dans votre r&eacute;gion !<br>";
[/php]
I don't really understand why but it gives me exactly the right thing. I will try yours too, I think the right colomn to use is the Region one.
Again, thank you very much !
Oct 15 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1563
by: greenflame | last post by:
I am trying to find a regular expression that returns true in the following cases but no others. 2.0 2.4 2. 324.0e345 234e34 34.e-43 234.673
59
7490
by: Rico | last post by:
Hello, I have an application that I'm converting to Access 2003 and SQL Server 2005 Express. The application uses extensive use of DAO and the SEEK method on indexes. I'm having an issue when the recordset opens a table. When I write Set rst = db.OpenRecordset("MyTable",dbOpenTable, dbReadOnly) I get an error. I believe it's invalid operation or invalid parameter, I'm
3
6201
by: kathleen | last post by:
Hi there, I'm new to this forum & to programming in general, and am really stuck with a piece of buggy code. Can anyone help? I have several problems which may or may not be related. I have written a piece of code in Visual Studio and now have to get it to run under Linux. Here is the problematic section: ifstream* seq_input = new ifstream(fname.c_str()); if(seq_input->is_open()==false) {cerr << "File not found";exit (1);} int i,...
2
1750
by: Jake Barnes | last post by:
I've read over the documentation for these effects: http://wiki.script.aculo.us/scriptaculous/show/CombinationEffectsDemo I want to include them on my page. I tried attaching using onload, but that didn't work. In fact, I can not get them to work even as inline commands. I click on the DIV with the id of newMailList, I only get an errror. This is the HTML:
3
3195
by: jcharth | last post by:
Hello a friend of mine was running phpbb on his site and the site got hacked. I am starting a new forum site and i installed punbb. Phpbb has many many nice features that punbb does not have. I had to adapt advanced poll to my site because i found many threads related to bugs with easy poll. So now i am running punbb with advanced poll. Not very friendly but works. I am wondering if i should switch to Phpbb but i am worried about the...
0
1736
by: James Barrett | last post by:
Hello All, I'm having some trouble with deligates. Any recommendations on good articles/study guides is greatly appreciated. James
5
1300
by: erikcw | last post by:
Hi all, I've created a script that reads in a file, replaces some data (regex), then writes the new data back to the file. At first I was convinced that "w+" was the tool for the job. But now I'm finding that the contents of the file are deleted (so I can't read the data in). f = open('_i_defines.php', 'w+')
24
4200
by: GesterX | last post by:
First of all I'm new to this site but it certainly looks like a place that i will be visiting more often! Onto my problem. I am creating a Hotel Bussiness project in java using BlueJ The classes are as follows: Hotel - Deals with the major functions of the hotel (i.e guests booking in, finding rooms etc.) Room - Used to decide whether a room has a sea view and stores the guest that is in the room. Occupier - For information about the...
5
571
by: rhino | last post by:
I am beginning to learn XML and XSLT from the w3schools tutorial and I'm having a lot more trouble doing something simple than I should be, namely writing a single blank space into a document. I am trying to separate two strings with a space and nothing I'm doing works. Here is my XSLT, which I think you'll agree is really simple:: <?xml version="1.0" encoding="Windows-1252"?> <xsl:stylesheet version="1.0"
0
8403
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8316
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,...
1
8509
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
8610
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...
1
6174
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
4168
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
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2735
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
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.