Jump to content

Dynamic link not working


Revolutsio

Recommended Posts

I have a link that i would like to become dynamic if the column is not blank i have used this code but can not get it to work.

<?php
            if($game['high'] !=="") {
                echo "<a class='knil' href='high.php?id=' .{$game['high']} . '>
                    {$game['high']}</a>";
            }
        ?>    

How can i get this to work?

Link to comment
Share on other sites

21 hours ago, ginerjm said:

    echo "<a class='knil' href='high.php?id={$game['high']}'>{$game['high']}</a>";
 

Thank you for that.

now because I only want to show the link if there is one I have tried using else but does not work it stops the next div from showing on screen

 

Link to comment
Share on other sites

9 minutes ago, dodgeitorelse3 said:

Please show what you tried.

Quote

 

<?php
            if($game['series'] !== "") {
                echo "<a class='knil' href='series.php?id={$game['series']}>{$game['series']}</a>";
            }  
        ?>
<?php
            if($game['series'] !== "") {
                echo "<a class='knil' href='series.php?id={$game['series']}>{$game['series']}</a>";
            }  else {
			echo "";
			}
		
        ?>

         

also swapped the echo's around but still get the same result

Link to comment
Share on other sites

1 hour ago, Barand said:

Perhaps because there apparently is no code to show another div?

What should happen is the if the 'high' is blank then not show the link, else show link

 

<div class="details_title text-shadow box-shadow">Series</div>
        <div class="details_answer text-shadow box-shadow">
        <?php
            if($game['series'] !== "") {
                echo "<div/>";
            }else {
            echo "<a class='knil' href='series.php?id={$game['series']}></a>";
        }
        ?>
        </div>
        <div class="details_title text-shadow box-shadow">Completed Date</div>
        <div class="details_answer text-shadow box-shadow">
        <?php
            if($newDate !== "") {
                echo "<a class='knil' href='complete.php'>
                    {$newDate}</a>";
            }       
        ?>

With this code it does not show the divs after the link.

Link to comment
Share on other sites

Your code says if 'series' is NOT blank don't show a link.

Then your code says if newdate is not blank show a link.

I have no idea what your reference to 'high' is in this conversation for.  And frankly I really don't know what you are trying to tell us.

Take a look at this code and play with the values to see what happens.  See how I kept it in php mode to make it easier to code?

$game['series'] = '';
$newDate = '';
echo "
	<div class='details_title text-shadow box-shadow'>Series</div>"
if($game['series'] == "")
	echo "<div class='details_answer text-shadow box-shadow'>
		<a class='knil' href='series.php?id={$game['series']}'></a></div>";

echo '<div class="details_title text-shadow box-shadow">Completed Date</div>';
if($newDate !== "")
	echo "<div class='details_answer text-shadow box-shadow'>
		<a class='knil' href='complete.php'>$newDate</a></div>";

See how I re-arranged your interior div tags?

Edited by ginerjm
made code changes
Link to comment
Share on other sites

51 minutes ago, ginerjm said:

Your code says if 'series' is NOT blank don't show a link.

Then your code says if newdate is not blank show a link.

I have no idea what your reference to 'high' is in this conversation for.  And frankly I really don't know what you are trying to tell us.

Take a look at this code and play with the values to see what happens.  See how I kept it in php mode to make it easier to code?

$game['series'] = '';
$newDate = '';
echo "
	<div class='details_title text-shadow box-shadow'>Series</div>"
if($game['series'] == "")
	echo "<div class='details_answer text-shadow box-shadow'>
		<a class='knil' href='series.php?id={$game['series']}'></a></div>";

echo '<div class="details_title text-shadow box-shadow">Completed Date</div>';
if($newDate !== "")
	echo "<div class='details_answer text-shadow box-shadow'>
		<a class='knil' href='complete.php'>$newDate</a></div>";

See how I re-arranged your interior div tags?

The high is from another box .

I have added an image of what i what to see when i run the page.

When i add the above code to my page i get an error 'syntax error, unexpected token "if", expecting "," or ";"'

 

I only want the link to show if there is anything in the db from that column

Screenshot 2022-06-30 174631.png

Edited by Revolutsio
more info
Link to comment
Share on other sites

15 hours ago, dodgeitorelse3 said:

How about showing all the code that pertains to this issue? You may have a clear idea what you have tried and want but you are making us pick through incomplete information which is wasting our time.

<?php
include 'includes/config2.php';

    //Check GET request id param
if(isset($_GET['id'])){

    $id = mysqli_real_escape_string($db, $_GET['id']);

    // make sql
    $sql = "SELECT * FROM games WHERE id= $id";

    // get the query result
    $result = mysqli_query($db, $sql);

    // fetch result in array format

    $game = mysqli_fetch_assoc($result);

    mysqli_free_result($result);
    mysqli_close($db);
   
    

}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="/includes/home.css"> 
    <Title>Game Library - Details</Title>
</head>
<body>


<div class="wrapper">
    <div class="span-col-4"><img src="images/logo2.png"></div>
    <div class="span-col-4"><?php include 'includes/navbar.php'; ?></div>
    <div class="span-col-4">
        <div class="text-display text-shadow box-shadow">
            <?php echo htmlspecialchars($game['game']); ?></div>
        </div>
   
  
    <div class="span-col-4">
        <div class="picture_details">
            <?php echo "<img class='img_details box-shadow' src='images/" . $game['image_name'] ."' >"?>
        </div>
        <div class="span-col-4">
    <?php
    $date = $game['finish'];
    $newDate = ($date)?date('d F Y', strtotime($date)):'';
    ?>
    <div class="details_grid">
        <div class="details_title text-shadow box-shadow">ID</div>
        <div class="details_answer text-shadow box-shadow"><?php echo $game['id']; ?></div>
        <div class="details_title text-shadow box-shadow">Year of Release</div> 
        <div class="details_answer text-shadow box-shadow">
            <a class='knil' href="year.php?id=<?php echo $game['release_year']; ?>">
                <?php echo $game['release_year']; ?>
            </a>                
        </div>
        <div class="details_title text-shadow box-shadow">Genre</div>  
        <div class="details_answer text-shadow box-shadow">
            <a class='knil' href='genre.php?id=<?php echo $game['genre']; ?>'>
            <?php echo $game['genre']; ?>
            </a>                        
        </div>
        <div class='details_title text-shadow box-shadow'>Series</div>
        <div class="details_answer text-shadow box-shadow">
        <a class='knil' href='series.php?id=<?php echo $game['series']; ?>'>
            <?php echo $game['series']; ?>
            </a>                        
        </div>
        <div class="details_title text-shadow box-shadow">Completed Date</div>
        <div class="details_answer text-shadow box-shadow">
        <?php
            if($newDate !== "") {
                echo "<a class='knil' href='complete.php'>
                    {$newDate}</a>";
            }       
        ?>
        </div>        
        <div class="details_title text-shadow box-shadow">High Score</div>
        <div class="details_answer text-shadow box-shadow">
        <?php
            if($game['high'] !=="") {
                echo "<a class='knil' href='high.php'>
                    {$game['high']}</a>";
            }
        ?>    
        </div>
        <div class="details_title text-shadow box-shadow">Platform</div>
        <div class="details_answer text-shadow box-shadow">
        <a class='knil' href='platform.php?id=<?php echo $game['platform']; ?>'>
            <?php echo $game['platform']; ?>
            </a>                        
        </div>
        <div class="details_title text-shadow box-shadow">Launcher</div>
        <div class="details_answer text-shadow box-shadow">
        <?php 
            if($game['launcher'] !=="") {
                echo "<a class='knil' href='launcher.php'>
                {$game['launcher']}</a>"; 
            }
        ?>
        </div>
        <div class="details_title text-shadow box-shadow">Achievements</div>
        <div class="details_answer text-shadow box-shadow">
            <?php
            if($game['achieve'] !=="") {
                echo "<a class='knil' href='achieve.php'>
                {$game['achieve']}</a>";
            }
            ?>
            </div>
        <div class="details_title text-shadow box-shadow">Achievements Got</div>
        <div class="details_answer text-shadow box-shadow">
            <?php 
            if($game['won'] !=="") {
            echo "<a class='knil' href='won.php'>
            {$game['won']}</a> "; 
            }
            ?>
            </div>
    </div>
        
</div>
</div>
    <div></div>
    <div class="span-col-3 text text_center box-shadow"><?php include 'includes/footer.php'; ?></div>
     
  


</body>
</html>

That is the code for details page, it gets the game name from another page id=xx

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.