andy_b_1502 Posted August 4, 2012 Share Posted August 4, 2012 Hello phper's. I have a peice of code i would like to change for it to do something else if it can. The code as is, makes an image (within search results) clickable. The target is whoever's profile that image belongs to. <?php <a href="view00.php?id=<?PHP echo $row['id']; ?>"><img src="images/thumbs/<?PHP echo $row['upload']; ?>" alt="logo"/></a> ?> view00.php being the users profile with id. What i wanted to do was only have certain images clickable; currently there are 3 levels of approval (which are set by admin) levels; 0 = no display 1 = basic display 2 = intermediate display 3 = full display - these are the ones i want clickable ONLY. this approved field in my mySQL database is set like: $approved = $row['approved']; SWITCH ($approved) { case 0: break; case 1: ?> in my while loop. Is it just a case of defining $approved in my search.php page something like this: <?php while($row = mysql_fetch_array($result02)) { $approved = $row['approved']; ?> SWITCH ($approved) { case 0: break; case 1: ?> <?php if($error>0) { echo $error_message; }else{ ?> <?php } ?> <?PHP echo $row['company_name']; ?> <?PHP echo $row['postcode']; ?> <a href="view00.php?id=<?PHP echo $row['id']; ?>"><img src="images/thumbs/<?PHP echo $row['upload']; ?>" alt="logo"/></a> <?php } ?> By the above i take it that only approved=1 will show as clickable logos? OR will only approved=1 show at all? Any ideas guys? the sites live so don't really want to go swapping and changing if it's going to give parse errors, many thanks in advance. Andy. Quote Link to comment https://forums.phpfreaks.com/topic/266671--/ Share on other sites More sharing options...
cpd Posted August 4, 2012 Share Posted August 4, 2012 Your switch loop isn't inside php tags so wouldn't work in that instance. I also think you need to understand switch loops better as it appears, to me, your confused. A switch loop is like a massive else if, else if, else if string of statements. $num = 2; if($num == 1){ } elseif($num == 2){ } elseif($num == 3){ } elseif($num == 4){ } else { } This can be changed into a switch statement by creating cases for each possability. $num = 2; switch($num){ case 1: // Code break; case 2: // Code break; case 3: // Code break; case 4: // Code break; case 5: case 6: // Code break; default: // Code } The term "break" is merely to break out of the switch statement and prevent any code after that case being executed. Similarly, it can be used to break out of a for or while loop. As long as the value being compared matches one of the cases, the code between the case and break statement will be executed. If no match is found, the default will be executed however, default is not required. You can also combine cases as I've shown with 5 & 6. With your issue just use the switch statement as you kind of already are and print out the HTML to make something click-able. Quote Link to comment https://forums.phpfreaks.com/topic/266671--/#findComment-1366756 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.