PDA

View Full Version : not sure how to add css to this switch case hyperlink


nanny
02-18-2008, 02:13 AM
Hi I have been trying but not able to give my link a css class. I am showing the page as on hover and the correct page will show. I am sure it is really simple!!!
This a page for a user to see their contact details and the link to the page that has the banner. This what I have so far:

switch($x) {
case $x === "sitefront":
echo "<a href=\"index.php\">Banner</a>";
break;
case $x === "directory":
echo "b";
break;
case $x === "jobs":
echo "<a href=\"../index.php\"> - To Look At The Banner Page </a>";
break;
case $x === "news":
echo "b";
break;
}


Where the

echo "<a href=\"../index.php\"> - To Look At The Banner Page </a>";


if I place a class e.g.

<a class="screen" href=\"../index.php\"> - To Look At The Banner Page </a>";


Is this because I should echo it separately? I don't think that would work, unless I echo an include screen.css as a separate css.
Is this the wrong way to go about it?

Cheers

davidj
02-18-2008, 06:36 AM
your switch is incorrect

should be...

switch($x) {
case "sitefront":
echo "<a href=\"index.php\">Banner</a>";
break;
case "directory":
echo "b";
break;
case "jobs":
echo "<a href=\"../index.php\"> - To Look At The Banner Page </a>";
break;
case "news":
echo "b";
break;
}

nanny
02-18-2008, 07:41 AM
Thanks I thought I had to do it separately because of being an enum in the database.
I fixed that up, but do you know how I can include a css class to the hyperlink? I have tried but nothing works.

Congrats on the number of posts by the way.

davidj
02-18-2008, 07:42 AM
how I can include a css class to the hyperlink?

explain abit more

nanny
02-18-2008, 08:02 AM
case "jobs":
echo "<a class="screen" href=\"../index.php\"> - To Look At The Banner Page </a>";
break;

davidj
02-18-2008, 08:10 AM
so depending on the case you want to change the link or style

nanny
02-18-2008, 08:15 AM
No it will occur for all what it is basically like a:hover and an information box with the page from the hyperlink so the user can see their banner on the page before sending me an email on changes etc.

davidj
02-18-2008, 09:15 AM
sorry

please give a senario and an examples of what changes dynamically

domedia
02-18-2008, 01:56 PM
No it will occur for all what it is basically like a:hover and an information box with the page from the hyperlink so the user can see their banner on the page before sending me an email on changes etc.
Rephrase please, that didn't make much sense ;)
Do you want the same CSS class on all links in your code above? The code you used above is completely valid as far as assigning a CSS class to the links.

nanny
02-19-2008, 09:22 AM
No this is what I get - I think you are forgetting it is php string not html. It is in a td of a form but is pure php:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\webserver\www\salonspa\d\update_b2.php on line 261


$x = $row_updatep2['whereto'];
switch($x) {
case "sitefront":
echo "<a href=\"index.php\">Banner</a>";
break;
case "directory":
echo "b";
break;
case "jobs":
echo "<a class="info" href=\"../index.php\"> - To Look At The Banner Page</a>";
break;
case "news":
echo "b";
break;
}


Cheers.

davidj
02-19-2008, 09:33 AM
No this is what I get - I think you are forgetting it is php string not html. It is in a td of a form but is pure php:

im lost

I think you are forgetting it is php string not html

what does that mean

in your example you have this which is HTML
echo "<a href=\"index.php\">Banner</a>";

the error ...
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\webserver\www\salonspa\d\update_b2.php on line 261

probably means that you have forgotten a semicolon on line 260

nanny
02-19-2008, 09:44 AM
Hi davidj
the line is the one above placing the class
case "jobs":
and it shouldn't have semicolon
I can add a style in a search page like this:

echo str_replace($SearchString, "<strong style='background-color:yellow;color:black;'>$SearchString</strong>" ,$row_rssearch['inv_addr2']);

davidj
02-19-2008, 11:36 AM
cant you just define a number of classes within your style sheet then assign your style to a $class variable from the switch


switch($value){
case 'a' $class = "class1"; break;
case 'b' $class = "class2"; break;
case 'c' $class = "class3"; break;
case 'd' $class = "class4"; break;

}


then have a span or a div wrapped around your value...

<span class="<?php echo $class ?>" > data </span>

nanny
02-21-2008, 08:16 AM
Hi davidj
Just wondering where the hyperlink would be on the above?
This is from the database:

echo $row_updatep2['whereto'];
$x = $row_updatep2['whereto'];
switch($x) {
case "sitefront":
echo "<a href=\"index.php\">Banner</a>";
break;
case "directory":
echo "b";
break;
case "jobs":
echo "<a href=\"../index.php\"> - To Look At The Banner Page</a>";
break;
case "news":
echo "b";
break;
}


putting the class that way will work but not for the hyperlink.

davidj
02-21-2008, 08:45 AM
so what your saying there is

pseudo code...

if $x == "sitefront" echo "<a href=\"index.php\">Banner</a>";

if $x == "directory" echo "b";

if $x == "news" echo "b";


why are you echoing b

I dont understand the logic of your switch

nanny
02-22-2008, 08:50 AM
Don't worry about that they will all be similar to this:

if $x == "sitefront" echo "<a href=\"index.php\">Banner</a>";

davidj
02-22-2008, 09:01 AM
right

god you can confuse a gent with your examples

im going.... "eh B whats B all about"..... [begins ripping hair out].

///

ok

look at this logically

inside an <a tag there are only a number of variables which could change. The Attribute values are what your looking to change so use your switch to change them accordingly

You can change the class value and the link value using this method



switch($x) {

case "sitefront":

$path = "index.php";
$class = "style1";
break;

case "directory":

$path = "page2.php";
$class = "style2";
break;

case "jobs":

$path = "page3.php";
$class = "style3";
break;

case "news":

$path = "page4.php";
$class = "style4";
break;
}


ok

you will have your html links hard coded in the page as normal

<a href="<?php echo $path; ?>" class=="<?php echo $class; ?>" >Banner</a>;

nanny
02-24-2008, 11:05 PM
Thanks davidj
Your method makes sense to me - I can already get the link to show to a new page using this:

echo $row_updatep2['whereto'];
$x = $row_updatep2['whereto'];
switch($x) {
case "sitefront":
echo "<a href=\"index.php\">Banner</a>";
break;
case "directory":
echo "<a href=\"../index.php\"> - To Look At The Banner Page</a>";
break;
case "jobs":
echo "<a href=\"../index.php\"> - To Look At The Banner Page</a>";
break;
case "news":
echo "<a href=\"../index.php\"> - To Look At The Banner Page</a>";
break;
}

When the user clicks on the

echo $row_updatep2['whereto'];


Sorry about the confusing "b".........

The link isn't hard coded onto the page as you normally would. How will I define the $class because I reckon that would work as another echo before the break. The class is the same for all links it is to make the link show up as a page within an info box. I am triallling this out the css is:

a.info {
font: bold Verdana, Arial, Sans-Serif;
text-decoration:none;
position:relative;
color: #666;
border : 1px dashed #C30;
}
a.info span {
display:none;
}
a.info:hover {

cursor:help;
}
a.info:hover .infobox {
display:block;
position:absolute;
top:20px;
left:0;
width:640px;
height:auto;
border: 1px solid #1a773a;
background: #fff;
color:#000;
text-align:left;
font : 76% Verdana, Arial, Helvetica, sans-serif;
margin: 0px;
padding-left:9px;
padding-right:3px;
padding-top:10px;
padding-bottom:5px;
}


Hope that makes sense.

davidj
02-24-2008, 11:22 PM
assign the class to a variable

and echo the class in the attribute value

nanny
02-25-2008, 05:17 AM
Thanks davidj I did that and the link had the css but the info box will not contain the web page inside.
All that effort but now I know how to do a switch case now and assign css variables.
I am slowly learning css as well.
Thanks for helping me learn.
I can also see now there are various ways of doing a switch case.

davidj
02-25-2008, 06:43 AM
so are you sorted with this

nanny
02-26-2008, 10:58 PM
yes thanks davidj
what I wanted to do was have the hyperlink either open up in another page - which it does - or have on hover or click that it the other page is in the info box.
But the info box only uses an anchor link not a hyperlink. I used the css and it works on the hyperlink without the hyperlink working.
I wasn't a hundred percent sure if it would work but it was worth a try. Still learning css.
I let the user know to use the back button on the browser tool bar to get back to the page once they have finished looking at the correct page for their banner image. The session isn't unset at that time.

domedia
02-27-2008, 02:19 PM
But the info box only uses an anchor link not a hyperlink.All hyperlinks are anchor links..
<a href="page.html">This is a hyperlink. Hyperlinks are made with the anchor tag.</a>

nanny
03-08-2008, 12:17 AM
This is how the info box works:

<p>
<span class="info"><a class="info" href="#nogo"><img src="pics/help.gif" alt="help" width="20" height="20" border="0" />Info for pricing hover here <span class="infobox"><strong class="msg2"><br />
$33 AU </strong>text Job Ad or <strong class="msg2">$55 AU </strong>text &amp; image Job Ad per month.<br />
Alternatively can pay for a yearly option <strong class="msg2">$330 AU </strong>and you may place unlimited Job Ad's.<br />
<br />
<strong class="msg2">Job Match: </strong>Search jobseekers CV's/resumes for full time, part time, student placement or temporary/contract/self-employed using the CV Search Facility.<br />
<strong class="msg2">More on Job Matching Online: </strong>Our jobseekers use their full CV/Resume when they have the interview with you. What we have provided on our creative job network is a form for the jobseeker to complete designed to match suitable candidates. The form requests contact details, language, availability, pay rate(contract/self-employed) for temping staff, skills, knowledge, education, experience and references. <br />
So you can search and filter immediately and check references prior to contacting persons. A more efficient and effective way of recruiting.</span></a></span> </p>

the css:

a.info {
font: bold Verdana, Arial, Sans-Serif;
text-decoration:none;
position:relative;
color: #666;
border: 1px dashed #C30;
}
a.info span {
display:none;
}
a.info:hover {

cursor:help;
}
a.info:hover .infobox {
display:block;
position:absolute;
top:20px;
left:0;
width:440px;
height:auto;
border: 1px solid #1a773a;
background: #fff;
color:#000;
text-align:left;
font : 76% Verdana, Arial, Helvetica, sans-serif;
margin: 0px;
padding-left:9px;
padding-right:3px;
padding-top:10px;
padding-bottom:5px;
}



I was wanting the link to open up as a new page within the info box but it won't. I just thought I could be creative.
The links work as a conditional on the users page and opens a new page accordingly I wanted it to be a hover on the link and they see the page instead of having to hit the back button to get back.

davidj
03-08-2008, 07:09 AM
are you wanting a tool tip here which displays data

like a layer that appears onmouseover and then disapear onmouseout

nanny
03-08-2008, 10:45 PM
You nailed it that was the original idea from each link that shows from the conditional depending upon the users details I was wanting the link to be like a tooltip and have that link basically contain the page on mouseover. It was simply for the user to have a quick peek that the details were correct as they may have a few links that have images on different pages.

davidj
03-09-2008, 11:23 AM
have you looked at the show hide layer behavior in DW