Jump to content

PHP Ifs...


danposs86

Recommended Posts

I have a panel, which if you are logged on it is displayed.Now what i want to do (see the code after the "//test" comment.If the user has added their car details and the field 'approved' equal 'n' i want it to tell them their car is not approved yet, if 'y' then display the link 'edit your car' and anything else ask them to add their car details, getting an error about an unexpected error.

<?phpif (isset($member_id) && $pass_hash == $member['password']){			$sql = "SELECT name, g_title, g_id FROM ibf_members m LEFT JOIN ibf_groups g ON ( g.g_id = m.mgroup) WHERE id='$member_id'";						$query = mysql_query($sql);		while($row = mysql_fetch_array($query)) {				echo "<div class='login_box_2'>";		echo "Welcome ".$row['name'];		if ($row['g_id'] == "4") {			echo " | <a href='admin.php' class='loglink'>Admin Panel</a>";			}						//test					$sql = "SELECT user, approved FROM site_cars m LEFT JOIN ibf_members g ON ( g.name = m.user)";		$query = mysql_query($sql);		while($row = mysql_fetch_array($query)) {		if ($row['user'] == $row['name']) {			if ($row['approved'] == "y") {				echo " | <a href='member_upload_car.php'>Edit Your Car</a>";				} else {			if ($row['approved'] == "n") {				echo " | Car Details Not Yet Approved";				}				}		} else {			echo " | <a href='member_upload_car.php'>Add Your Car</a>";			}						//end test		echo " | <a href='member_upload_car.php' class='loglink'>Add Your Car</a>";		echo " | <a href='logout.php' class='loglink'>Log Out</a>";		echo "</div>"; } } else { 		echo "<div class='login_box'>";		echo "You are not logged in, <a href='forum/login.php' class='loglink'>click here to login.</a>";		echo "</div>"; }?>

if you get what i mean, help :) lol

Link to comment
Share on other sites

First of all can you let us know the exact error and maybe a line number. The error could be occurring anywhere so it's useful to track down exactly where.Once you get the error sorted here are some comments.If approved is either y or n then try to simplify your if else statements. The first says:If 'y' then do this else if 'n' do that.But if approved is either y or n then there's no need to have the second if statement. It will be:If 'y' do this else do that.Also, you have it in a while statement. If the user is enquiring about a car it will (should) only return one row so perhaps get rid of the while which will help lose one level of {} brackets and make everything a bit less complicated.Going back to the y/n. Instead of using if/else why not look at case/switch? Something like this:$status=$row['approved'];switch ($status){case "y": do this; break;case "n": do that; break;default: do this if neither the above;}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...