Jump to content

[SOLVED] php variable into <a href> link


gckmac

Recommended Posts

I'm having difficulty turning a php variable into an a href link. 

 

I am trying to place it here ... above the echo <hr/>:

 

<?php

echo '<h1><a href="http://www.maine.info/festivals.php">Maine Events</a> - ' . $month . ' ' . $display_cat . ' </h1>';

echo '<hr />';

 

The variable is $display_cat  (where it could equal "festivals" "music" "theater" etc.)

 

I would like to make the following links (I will list 12 of them for all months):

 

$display_cat in <a href="http://www.maine.info/events/$display_cat/january.php">Jan</a>

etc for additional months

 

Thanks in advance!

gckmac

 

 

 

 

 

 

Link to comment
Share on other sites

OK!  Fixed it with $display_cat=strtolower($display_cat);  Could not have done it without you guys.  See below ... (more months to add)

 

<?php

$display_cat = strtolower($display_cat);

echo '<p><font face="arial" size="1"><a href="http://www.maine.info/events/' . $display_cat . '/january.php">Jan</a> | ';

echo '<a href="http://www.maine.info/events/' . $display_cat . '/february.php">Feb</a></font>';

?>

 

Link to comment
Share on other sites

Good. Let me show you a way to loop through the months, getting rid of the repetitive code:

 

<?php
$display_cat = strtolower($display_cat);
$months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$links = array();
foreach ($months as $month) {
   $links[] = '<a href="http://www.maine.info/events/' . $display_cat . '/' . strtolower($month) . '.php">' . substr($month, 0, 3) . '</a>';
}
echo '<p><font face="arial" size="1">' . implode(' | ', $links) . '</font></p>';
?>

Link to comment
Share on other sites

I will try that looping code. Thank you.

 

My next issue is this:  The following code works, but when inserted where I want it breaks the php code below it:

 

I.e., code that works:

<?php

// $month = date("F") ;

$month = strtolower($month);

 

$month1 = ucfirst($month);

$janlinkclass = ($month1 == "January") ? "current" : "";

$feblinkclass = ($month1 == "February") ? "current" : "";

$marlinkclass = ($month1 == "March") ? "current" : "";

$aprlinkclass = ($month1 == "April") ? "current" : "";

$maylinkclass = ($month1 == "May") ? "current" : "";

$junlinkclass = ($month1 == "June") ? "current" : "";

$jullinkclass = ($month1 == "July") ? "current" : "";

$auglinkclass = ($month1 == "August") ? "current" : "";

$seplinkclass = ($month1 == "September") ? "current" : "";

$octlinkclass = ($month1 == "October") ? "current" : "";

$novlinkclass = ($month1 == "November") ? "current" : "";

$declinkclass = ($month1 == "December") ? "current" : "";

?>

 

<li>

<strong class ="head selected" >Event Control Panel</strong>

<ul>

<li>Events in:

<select id="scity" name="scity">

<option value="-1">Select City...</option>

<?php

$query = "select distinct(city) from maine_festivals where  city <> ''  and state = 'Maine' and (datediff(enddate, current_date) >= 0 or category = 'Festivals') order by city ";

 

$result = mysql_query($query, $link);

if (isset($month)) {

$cat1 = strtolower($cat);

} else {

$cat1 = "festivals";

}

while ($row = mysql_fetch_assoc($result)) {

extract($row);

echo "<option value = '$city'";

if ($city == $gcity) echo " selected ";

echo ">$city</option>\n" ;

}

?>

 

</select>

</li>

 

CODE THAT BREAKS WHEN ABOVE IS INSERTED:

<?php

echo '<hr />';

 

//$startcat = "";

while ($row = mysql_fetch_assoc($result)) {

extract($row);

 

$startdate1_part = substr($startdate1, 0, strlen($startdate1) - 6);

$date = ($startdate1 == $enddate1)? $startdate1: $startdate1_part . "  thru " . $enddate1;   

 

if ($expireddays >= 0) {

$mapurl = '   <a href = "http://www.maine.info/sandbox/maps/map2.php?type=000000001&zoom=13&city=' . $city . '"> Map + Directions</a>    ';

$parastyle = "";

} else {

$mapurl = "" ;

$parastyle = "expired";

}

 

if ($city == "") {

$city = "Multiple Locations";

$mapurl = "" ;

}

 

if ($username == ADMIN || $username == $author) {

$editlink = "  |  <a href = 'http://www.maine.info/users/editevent.php?id=$id'>Edit</a>";

} else {

$editlink = "";

}

 

$no_title = str_replace(" ", "", $title);

$no_title = str_replace("'", "", $no_title);

echo "<a name = '$no_title' ></a>";

if (strlen($linkurl) > 5) {

echo "<h2  class = '$parastyle'><a href = '$linkurl' class = '$parastyle' >$title</a> ";

} else {

echo "<h2 class = '$parastyle'>" . $title;

}

 

echo <<<ENT

</h2>

<p class = "$parastyle"><font face="arial" size="2">

<strong>$date. $city.</strong>

$description $mapurl

  

<!--

<a href = "http://www.maine.info/users/reporterror.php?id=$id&type=event">Report  Update</a>

-->

$editlink

 

</p></font>

 

ENT;

}

?>

</div>

 

Any Thoughts?

Thanks!

gckmac

Link to comment
Share on other sites

Firstly - the month array works great.  (Now I've got to figure out how it does it :)

 

Next, in terms of the breakage.  Yes, when I insert the noted code, it displays the intended function (drop down list of cities), but then the stuff below it no longer displays.  Just blank.

 

For what it should look when working, see www.maine.info/cities/freeport/events.php

 

To view it broken (temporarily), see http://www.maine.info/events/festivals/april.php

 

gckmac

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.