GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Tech Row with no contents, how to remove in output? (https://gfy.com/showthread.php?t=1354046)

Publisher Bucks 04-11-2022 12:40 PM

Row with no contents, how to remove in output?
 
So I have a table that has a row of URLs in it, some of the rows do not have any data in them.

When outputting the data to a page, how can I make it so that the code where that url should appear dissapears from the page?

This is the code I'm using:

Quote:

<strong><a href="<?php echo $One; ?>">One</a></strong> |
<strong><a href="<?php echo $Two; ?>">Two</a></strong> |
<strong><a href="<?php echo $Three; ?>">Three</a></strong> |
<strong><a href="<?php echo $Four; ?>">Four</a></strong></p>
One, Two, Three & Four are all links to our product on a specific online store, I'm thinking its something to do with either and "if" or an "echo" statement(?) but I cant seem to figure out the right code to get it working.

Basically, if the row for 'Two' has no data in it, how do i get it to just vanish from the 4 options?

So instead of:

One | Two | Three | Four

It shows:

One | Three | Four

The data calls are in an array at the top of the page if that helps any?

NatalieK 04-11-2022 01:25 PM

no, my bad, what i said was wrong from what iŽd read...


bounce for you, good luck :thumbsup

zerovic 04-11-2022 03:31 PM

Hi,

You can put a simple IF before each row

Quote:

<?php if($One) { ?> <strong><a href="<?php echo $One; ?>">One</a></strong> | <?php } ?>
<?php if($Two) { ?> <strong><a href="<?php echo $Two; ?>">Two</a></strong> | <?php } ?>
<?php if($Three) { ?> <strong><a href="<?php echo $Three; ?>">Three</a></strong> | <?php } ?>
etc

You can also use trim($var) and strlen($var) > 0 if there is a chance that your DB has rows with only spaces by mistake.

'The data calls are in an array at the top of the page if that helps any?'

If you have everything in your array, you can simply use the function implode() and you are good to go.

Show me a print_r of your array and I can help you further.

Cheers,
z

Publisher Bucks 04-11-2022 05:47 PM

Quote:

Originally Posted by zerovic (Post 22990590)
Show me a print_r of your array and I can help you further.

This is literally all the code I have in the page (its real basic).

Quote:

<?php

$id=intval($_GET['id']);

if($id==0)

{

header( "Location: /search" ); //or any other page like 404

exit;

}

$pdo=hookitup();

$table = "ProductLibrary";

$sql="select * from " . $table . " where ID=" . $pdo->quote($id);

//echo "sql=" . $sql . "<br>";

$stmt=$pdo->query($sql);

//echo "rows back=" . $stmt->rowcount() . "<br>";

$row=$stmt->fetch(PDO::FETCH_ASSOC);

$id = $row['ID'];
$Category = $row['Category'];
$Name = $row['Name'];
$One = $row['One'];
$Two = $row['Two'];
$Three = $row['Three'];
$Four = $row['Four'];

?>
Im just echo'ing the data onto the page where I need to display it from the array.

Publisher Bucks 04-11-2022 05:50 PM

Quote:

Originally Posted by zerovic (Post 22990590)
Hi,

You can put a simple IF before each row

That will work even if all im pulling into the page from the database is the URL itself?

Publisher Bucks 04-11-2022 06:01 PM

That IF statement works perfectly for what I needed, thank you so much for the code 👍

zerovic 04-12-2022 12:47 AM

Yeah, looking at your code, the IF function is what you are looking for :)

k0nr4d 04-12-2022 04:57 AM

Quote:

Originally Posted by zerovic (Post 22990590)
Hi,

You can put a simple IF before each row



etc

You can also use trim($var) and strlen($var) > 0 if there is a chance that your DB has rows with only spaces by mistake.

'The data calls are in an array at the top of the page if that helps any?'

If you have everything in your array, you can simply use the function implode() and you are good to go.

Show me a print_r of your array and I can help you further.

Cheers,
z

You have to use isset() or empty() now, otherwise it throws a fatal error in PHP8

Clown 04-12-2022 12:06 PM

Quote:

Originally Posted by k0nr4d (Post 22990794)
You have to use isset() or empty() now, otherwise it throws a fatal error in PHP8

Correct. Proper error checking is a must for PHP.

zerovic 04-13-2022 02:06 AM

Quote:

Originally Posted by k0nr4d (Post 22990794)
You have to use isset() or empty() now, otherwise it throws a fatal error in PHP8

Yeah, you are right. :)


All times are GMT -7. The time now is 02:30 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123