Revolutsio Posted June 29, 2022 Share Posted June 29, 2022 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? Quote Link to comment https://forums.phpfreaks.com/topic/314972-dynamic-link-not-working/ Share on other sites More sharing options...
ginerjm Posted June 29, 2022 Share Posted June 29, 2022 echo "<a class='knil' href='high.php?id={$game['high']}'>{$game['high']}</a>"; 1 Quote Link to comment https://forums.phpfreaks.com/topic/314972-dynamic-link-not-working/#findComment-1597708 Share on other sites More sharing options...
Barand Posted June 29, 2022 Share Posted June 29, 2022 If you look at the page source to see the code you are generating it should become obvious. Quote Link to comment https://forums.phpfreaks.com/topic/314972-dynamic-link-not-working/#findComment-1597709 Share on other sites More sharing options...
Revolutsio Posted June 30, 2022 Author Share Posted June 30, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/314972-dynamic-link-not-working/#findComment-1597752 Share on other sites More sharing options...
dodgeitorelse3 Posted June 30, 2022 Share Posted June 30, 2022 Please show what you tried. Quote Link to comment https://forums.phpfreaks.com/topic/314972-dynamic-link-not-working/#findComment-1597754 Share on other sites More sharing options...
Revolutsio Posted June 30, 2022 Author Share Posted June 30, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/314972-dynamic-link-not-working/#findComment-1597755 Share on other sites More sharing options...
Barand Posted June 30, 2022 Share Posted June 30, 2022 3 hours ago, Revolutsio said: does not work it stops the next div from showing on screen Perhaps because there apparently is no code to show another div? Quote Link to comment https://forums.phpfreaks.com/topic/314972-dynamic-link-not-working/#findComment-1597757 Share on other sites More sharing options...
Revolutsio Posted June 30, 2022 Author Share Posted June 30, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/314972-dynamic-link-not-working/#findComment-1597761 Share on other sites More sharing options...
ginerjm Posted June 30, 2022 Share Posted June 30, 2022 (edited) 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 June 30, 2022 by ginerjm made code changes Quote Link to comment https://forums.phpfreaks.com/topic/314972-dynamic-link-not-working/#findComment-1597764 Share on other sites More sharing options...
dodgeitorelse3 Posted June 30, 2022 Share Posted June 30, 2022 The first if statement says if value is not blank then close div. Yet have that closing div after the else part if that if statement. Quote Link to comment https://forums.phpfreaks.com/topic/314972-dynamic-link-not-working/#findComment-1597765 Share on other sites More sharing options...
Revolutsio Posted June 30, 2022 Author Share Posted June 30, 2022 (edited) 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 Edited June 30, 2022 by Revolutsio more info Quote Link to comment https://forums.phpfreaks.com/topic/314972-dynamic-link-not-working/#findComment-1597767 Share on other sites More sharing options...
dodgeitorelse3 Posted June 30, 2022 Share Posted June 30, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/314972-dynamic-link-not-working/#findComment-1597768 Share on other sites More sharing options...
ginerjm Posted June 30, 2022 Share Posted June 30, 2022 Look at the error message and follow what it tells you! Quote Link to comment https://forums.phpfreaks.com/topic/314972-dynamic-link-not-working/#findComment-1597769 Share on other sites More sharing options...
ginerjm Posted June 30, 2022 Share Posted June 30, 2022 The error was mine. Missing semi before an if line. Quote Link to comment https://forums.phpfreaks.com/topic/314972-dynamic-link-not-working/#findComment-1597773 Share on other sites More sharing options...
Revolutsio Posted July 1, 2022 Author Share Posted July 1, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/314972-dynamic-link-not-working/#findComment-1597799 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.