Code changes array value it's not supposed to or crashes

I have a bit of code for my website that is changing a value when I add it to the page.

Initial code is as follows:

$sql = "SELECT * FROM `Locations`";
$result = dbquery ($sql,$conn);
$locations = dbfetcharray($result);
foreach ($locations as $location) {
	Print '<p><a href="'.$location['Link'].'">'.$location['Name'].'</a><br>'.$location['Address'].'<br>'.$location['City'].', '.$location['State'].' '.$location['Zip'].'<br>'.$location['Phone'].'<br>'.$location['DateThere'].'<br></p>';
}

This works almost perfectly, except that there are two entries where there is no link in the DB the code is retrieving from. A link is created that redirects back to the page itself. So I want to add a it of code that looks to see if there is no link (currently shown as “none” in the DB cell).

foreach ($locations as $location) {
            if ($location['Link' = "None") {
                 $linkedname = $location['Name'];
            } else {
                 $linkedname = '<a href="'.$location['Link'].'">'.$location['Name'].'</a>';
            }
	Print '<p>'.$linkedname.'<br>'.$location['Address'].'<br>'.$location['City'].', '.$location['State'].' '.$location['Zip'].'<br>'.$location['Phone'].'<br>'.$location['DateThere'].'<br></p>';
}

Now I would think that this would then make the name of a store that does not have a link in the DB print as just text as opposed to the ones that do have a link in the db printing as a hyperlink. However the page is crashing, and I don’t know why.

For reference here is the page with the working code.
http://games.theweyr.net/Locations.php

There is an error in that…

Sometimes it is the stupidest little things. thanks. I saw it as soon as i read your post and was thinking i must have mistyped it into the post. but nope it was in the file. However, while the page no longer crashes, now all the links are removed.

NM, figured it out. I needed to use == and not =

Thanks for the help

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service