Jump to content

<a href="filename.php?id=


andy_b_1502

Recommended Posts

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.