473,395 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Newbie having trouble finding the good loop

2
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=
&alpesdehauteprovence=
&alpesmaritimes=breeder yy breed jj

And I would like to have :
&ain=breeder xx breed ii
&aisne=No breeder !
&allier=No breeder !
&alpesdehauteprovence=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 1489
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='Oui' ORDER BY Affixe";
$result_eleveurs = mysql_query($query_eleveurs);
while( $eleveurs = mysql_fetch_array($result_eleveurs) ){

$popup=$eleveurs['popup'];
$affixe=$eleveurs['Affixe'];
$race=$eleveurs['Race'];
$chaton=$eleveurs['chatons'];



You have 2 options.

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

do:

if ( empty($eleveurs['Affixe']) ){
$affixe = "no breeder" ;}
else {
$affixe=$eleveurs['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(affixe)>0,affixe, 'no breeder'), race, chatons FROM membres_aacas WHERE Region='$region' AND Publication='Oui' 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
Thank you very much JonnDo I finally had what I want using a "if" outside the second "while" :
[php]$popup=$eleveurs['popup'];
$affixe=$eleveurs['Affixe'];
$reg=$eleveurs['Region'];
$race=$eleveurs['Race'];
$chaton=$eleveurs['chatons'];

echo "<a href=\"asfunction:popup,../chatteries/$popup\"><b>$affixe</b></a><br>$race - $chaton<br>";
}

if ( $reg <> $region) echo "Il n'y a pas d'&eacute;leveurs 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
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
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...
3
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...
2
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...
3
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...
0
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
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...
24
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...
5
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...

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.