954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help displaying 2 values from a field

Hello,

I hope somone can help me.

I have a form that a user use to search for their pay, and it will dispay it for them as both with dependents and without.

Right now they can search and it will display their pay, but it displays it as two seperat rows. so it will display the pay in both the with and without section for the 'with' and then it does the same for the 'without'.

I have a database that has 2 tables sorted_zipmhaYY and bahwYY.

I would like to have it show 1 record that shows how much they will get with or without dependents. I have tried doing

if ($row['dependents']='with'){ ...}

if ($row['dependents']='without'){ ...}

But this just created a loop.

<div id="search_results">
        <?php


if(isset($_GET['zipcode'])){
    $zipcode =     trim($_POST['zipcode']) ;
$zipcode = mysql_real_escape_string($zipcode);
if(isset($_GET['field_rank'])){
    $rank =     trim($_POST['field_rank']) ;
$rank = mysql_real_escape_string($rank);
if(isset($_GET['YEAR'])){
    $year =     trim($_POST['YEAR']) ;
$year = mysql_real_escape_string($year);



$query = "SELECT $rank, ZIPCODE, Dependents, YEAR FROM sorted_zipmhaYY 
LEFT JOIN bahwYY ON sorted_zipmhaYY.MHA=bahwYY.MHA 
WHERE ZIPCODE='$zipcode' AND YEAR='$year' ORDER BY sorted_zipmhaYY.zipcode ASC";

echo $query;



//echo $query;

$result = mysql_query($query) or die(mysql_error());
if($result){
   /* if(mysql_affected_rows($link)!=0){*/
    
          while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
     echo '<div id="style"><p> <b> <small> Zipcode: </small>'.$zipcode.
     '</div></b></p>
<div id="style"><p> <b> <small> Year: </small>'.$row['YEAR'].
     '</div></b></p>
	 <div id="style"><p> <b> <small> Recomended BAH for a '.$rank.' with dependents: </small>$'.$row[$rank].
     '</div></b></p>
<div id="style"><p> <b> <small> Recomended BAH for a '.$rank.' without dependents Status: </small>'.$row[$rank].
     '</div></b></p> <hr>';
    }
    }else {
        echo 'No Results for Zipcode "'.$_POST['zipcode'].'"';
   /* }
 */
}
}else {
    echo 'Parameter Missing';
}
}
}
?></div>


Any help would be appreciated.

Thanks,

Aaron

AMADH
Light Poster
27 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

for your first code use an elseif which will either display one or the other

if ($row[dependents]=='with'){
...
}elseif($row[dependents]=='without'){
...
}

public-image
Junior Poster in Training
76 posts since Oct 2010
Reputation Points: 10
Solved Threads: 11
 

Hello Public image, thank you, I'm not sure if an if elseif is what I need. Because what I am trying to do is display $row[$rank] for the values that have $row['dependents']==with and $row['dependents']==without.

Do you know how this can be done?

Thanks,

Aaron

for your first code use an elseif which will either display one or the other

if ($row[dependents]=='with'){ ... }elseif($row[dependents]=='without'){ ... }

AMADH
Light Poster
27 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

Hi,

Nevermind, I got it working, sorry I made a newbie mistake.

thanks,

Aaron

Hello Public image, thank you, I'm not sure if an if elseif is what I need. Because what I am trying to do is display $row[$rank] for the values that have $row['dependents']==with and $row['dependents']==without.

Do you know how this can be done?

Thanks,

Aaron

AMADH
Light Poster
27 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: