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 Another quick if statement question & sql query (https://gfy.com/showthread.php?t=1355619)

Publisher Bucks 06-17-2022 10:39 PM

Another quick if statement question & sql query
 
I'm trying to make a data entry from my database bold if it meets the 'yes' criteria in the 'sponsor' field.

I have this so far but, I can't seem to get it working, any help on where/what I am screwing up please?

Quote:

<?php if($statement=='IF(SELECT Name, IF(Sponsor='Yes')
FROM TABLE;){ echo "<strong>";}?>
The text HERE
<?php if($statement=='IF(SELECT Name, IF(Sponsor='Yes')
FROM TABLE;){ echo "</strong>";}?>
Is the above even a 'thing'? :helpme

I think I'm on the right track but screwing up calling the data and IF statement correcty?

The $conn is opened a little further up the page, and closed below where I want this bold text to appear.

OR as an alternative, should I just put <b></b> around the name in the SQL database and just use htmlspecialchars? Any potential issues with doing that?

natkejs 06-17-2022 11:38 PM

Quote:

Originally Posted by Publisher Bucks (Post 23012570)
I'm trying to make a data entry from my database bold if it meets the 'yes' criteria in the 'sponsor' field.

I have this so far but, I can't seem to get it working, any help on where/what I am screwing up please?



Is the above even a 'thing'? :helpme

I think I'm on the right track but screwing up calling the data and IF statement correcty?

The $conn is opened a little further up the page, and closed below where I want this bold text to appear.

OR as an alternative, should I just put <b></b> around the name in the SQL database and just use htmlspecialchars? Any potential issues with doing that?

You are not calling your database at all.

How are you getting the results you are looping through?

You probably have the sponsor column in those results and can just verify against it.

PHP Code:

foreach ( $myResults as $row ) {
$string 'bla bla bla';
if ( 
$row['sponsor'] == 'yes' $string "<strong>$string</strong>";
echo 
$string;



Publisher Bucks 06-18-2022 12:36 AM

Quote:

Originally Posted by natkejs (Post 23012572)
You are not calling your database at all.

It gets opened at the top of the page:

Quote:

<?php

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

if($id==0)

{

header( "Location: ./404/" ); // 404 Ad Directory

exit;

}

$pdo=hookitup();

$table = "Directory";

$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);

$name = $row['Name'];
$street = $row['Street'];
$city = $row['City'];
$state = $row['State'];
$zip = $row['Zip'];
$phone = $row['Phone'];
$email = $row['Email'];
$website = $row['Website'];
$facebook = $row['Facebook'];
$twitter = $row['Twitter'];
$description = $row['Description'];
$category = $row['Category'];
$monday = $row['Monday'];
$tuesday = $row['Tuesday'];
$wednesday = $row['Wednesday'];
$thursday = $row['Thursday'];
$friday = $row['Friday'];
$saturday = $row['Saturday'];
$sunday = $row['Sunday'];
$sponsor = $row['Sponsor'];

?>
Then presently, I'm using an echo to call a specific field of data from the table:

Quote:

<?php echo $name; ?>

natkejs 06-18-2022 12:49 AM

Quote:

Originally Posted by Publisher Bucks (Post 23012578)
It gets opened at the top of the page:



Then presently, I'm using an echo to call a specific field of data from the table:

Ok so the sponsor column has already been extracted into $sponsor.
Instead of printing $name lets print $string which we will add strong tags to in case $sponsor is set to "Yes".

PHP Code:

$string = ( $sponsor == 'Yes' ) ? "<strong>$name</strong>" $name;
echo 
$string

You could also use a full if / else statement together with $name only but I think it's less fancy for some reason.
Though if you want to do more logic in case $sponsor is set to Yes than this would be a better way to go.

PHP Code:

if ( $sponsor == 'Yes' ) {
 echo 
"<strong>$name</strong>";
}
else {
 echo 
$name;




All times are GMT -7. The time now is 11:10 PM.

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