Weird php hyperlink issue - php

This is kinda tricky as I'm using php to output my content and it's a lot of code.
If you go to http://www.nunchycrut.com#nav=resources&rsc=articles&year=2014 you should see articles listed for 2014 - there is only one called memory lane.
When you mouseover the link it doesn't seem to work as it should. the link is underlined on a mouseover but it seems you have to click the actual horizontal underline to follow the link, if you click on the text it won't work.
All of the other links (in orange) on the page are created using the same class this only appears to be happening in the article listings.
Here's the section of php that is outputting the article link:
<div
style='position: relative; float: left; margin-top: 0px; margin-left: 4px;'
onclick='showArticle(\"" . $strY ."\", \"" . $arrLines[4] . "\");'
>
<b>" . $arrLines[1] . " -- </b>
<a
href='#nav=resources&rsc=articles&year=" . $strY . "&art=" . $arrLines[4] . "'
>
" . $arrLines[0] . "
</a>
</div>
$arrLines[0] holds the actual article name (memorylane). I've been playing about with this for a while trying to figure it out, it's the fact that other links are working fine. I've never seen this before with a hyperlink, anyone any clues?
I can post the css class code but I don't think that's the issue here as like I said, the class is being used all over without problems (the 2014 and 2015 article archive links for example).
It's not a huge problem on a browser but I tested it with my phone and it's quite difficult to open that particular link due to this issue/
I did try using the onclick='' attribute in the actual hyperlink like:
<a
href='#nav=resources&rsc=articles&year=" . $strY . "&art=" . $arrLines[4] . "'
onclick='showArticle(\"" . $strY ."\", \"" . $arrLines[4] . "\");'
>
" . $arrLines[0] . "
</a>
But it's still doing the same thing. Happening in all browsers, any ideas or solutions would be appreciated.
Thanks.

You need to make 2 changes (remove float:left):
<p class="ContentReg" style="position: relative; margin-top: 0px; margin-left: 4px;" onclick="showArticle("2014", "memorylane");">
<b>November 12, 2014
-- </b>
<a href="#nav=resources&rsc=articles&year=2014&art=memorylane">
A trip down memory lane.
</a>
</p>
and change (remove position:relative)
<p class="ContentSmall" style="float: right; margin-top: 8px; margin-left: 10px; margin-right: 4px; text-align: right;">
By <font color="#6495ED">Nunchy
</font>
</p>

Remove position: relative in your inline style for paragraph tag.
<p class="ContentSmall" style="/* position: relative; */ float: top; margin-top: 8px; margin-left: 10px; margin-right: 4px; text-align: right;">

Your hyperlink needs to go from:
href='#nav=resources&rsc=articles&year=" . $strY . "&art=" . $arrLines[4] . "'
to:
href='#?nav=resources&rsc=articles&year=$strY&art=$arrLines[4]'
When you use a double quote (") with an echo it will echo the variable, however if you use a single quote (') with an echo it will echo the text as is.
When constructing a hyperlink for PHP you should keep in mind:
- where on the page to go
? - indicates you're setting page variables

Related

"void space" in a <li> with images

I'm kind of stuck on this. I have to put an horizontal list of different states of some services I'm working on. I have 3 different states ( Green, Orange, Red ), and I want to "go back to the line" whenever the state changes. I have the feeling I need to write something like "you go xx pixels down" to correctly have my lists in order, but it still keeps packing weirdly. I don't really know if I'm clear.
Here's part of the code :
$brequest = 1;
echo "<ul>\n";
foreach($arrstate as $sun){
for($x=1 ; $x<4 ; $x++){
if($sun[1] == $x){
if($brequest != $x){
$brequest = $x;
echo "</ul><ul>\n"; //Note that it's just a try here
}
$affichage=" <img src=\"images/" . $images[$x] . ".svg\" title=\"" . $texte_alt[$x] . "\" alt=\"" . $texte_alt[$x] . "\" height=\"40px\" style=\"vertical-align:middle\"";
$comment="<br /><br />".$sun[2]."<br /><br/>Last Updated : ".$sun[3]."<br /><br />By ".$sun[4]."</li>\n";
echo "<li style=\"background-color: " . $couleur_etat[$x] . "\">" . $sun[0] . $affichage. $comment;
}
}
}
echo "</ul>";
The array is sorted by states, and the <style> part is :
<style>
ul { list-style-type: none;}
li {
display: inline;
margin: 1em;
float: left;
padding: 1em;
border: 1px solid black;
border-radius: 15px;
width: 15em;
min-height: 3em;
font-weight: bold;
}
</style>
Feel free to ask me anything about the code. Thank you in advance for your answer !
Answering my own question to help.
I just had to clear:left every <ul> I use, this way the float will stop putting images at the same row. It goes like this :
echo "</ul><ul style=\"clear:left\">";
I know CSS in line is not that much appreciated, but I began HTML PHP & CSS Yesterday. So, let's run with it for the moment !
( And sorry for the bad example, I'll give more attention to details next time. Thank you ! )

echo css background image url not functioning causes no display

I'm encountering other form of problem regarding background-image url in css.
The destination of my image is in includes/img/messaging.png. my problem is i put css on echo so here is my code
logs.php
echo '<div style="width: auto; margin-left: 250px;
margin-right: 5px; padding-right:8px; border-bottom: 2px solid;
border-top: 2px solid; border-color: #ebebeb; border-radius: 8px;
padding-bottom: 10px; padding-top: 10px; padding-left: 15px; text-align:left; font-size:0.8em; color:#FFFFFF; background-image: url("../includes/img/messaging.png");">' .
'<div style="font-weight:bold;">' . "You" . "</div>message: " . $messages->msg . "<br>" . '<div style="font-size: 0.6em;">'. "Sent : " . $messages->dt . "</div>" . '</div>';
as you can see the destination of my image was right. But why it doesn't display something. i have 2 folders pages and includes. logs.php is located at pages/logs.php and the images is in includes/img/messaging.php so my echo was in right directory accessing the image
Write your line as below:-
background-image: url(\'../includes/img/messaging.png\');
and if you are a linux user then make sure you have given permission to image.
Hope this will help you :)

applying style to html dynamically from user input

I have a form that the user fills out with various items, including choosing a background. When they press a button to preview the form, I send them to another .php page which pops up an iframe and assembles all the form parts into a letter. My problem is getting the background to populate. Here is how I am trying to get the background to display ($stationery is whatever the user asked for, with input cleaned up). I'm close, because if I cheat and code
<div style="width: 550px; height: 550px; padding: 15px; background-image:url(images/stationery/birthday.jpg);">
It works fine. But, as I said, that's cheating :-)
$final = "url(images/stationery/" . $stationery . ".jpg);" ;
<div style="width: 550px; height: 550px; padding: 15px; background-image:" . $final . ";>"
<h3>Message Preview</h3>
.......
but the background doesn't show and I'm not getting any errors. Firebug however, looks horrendous:
<div <h3="" "="" ";="" $final;="" .="" background-image:\"="" 15px;="" padding:="" height:="" 550px;="" style="\"width:">
Can someone point me in the right direction? Thanks
<?php
$final = "url('images/stationery/" . $stationery . ".jpg');";
?>
<div style="width: 550px; height: 550px; padding: 15px; background-image: <?php print $final; ?>">
<h3>Message Preview</h3>
<!--Don't forget to close the div-->
</div>
Or if you want it all to be ran through the PHP interpreter:
<?php
$final = "url('images/stationery/" . $stationery . ".jpg');";
print '<div style="width: 550px; height: 550px; padding: 15px; background-image: ' . $final . '">';
print '<h3>Message Preview</h3>';
// Don't forget to close the div...
print '</div>';
?>
Better yet:
<div style="width: 550px; height: 550px; padding: 15px; background-image: url('images/stationery/<?php print $stationery; ?>.jpg');">
<h3>Message Preview</h3>
<!--Don't forget to close the div-->
</div>

Learning PHP - Is there a better way to do this?

I'm a new learner of PHP. I have written the following two files which do seem to work.
I'd like to know if I can achieve the effect with just one script.
I'd like to know if there's a better way to do this.
The dox.php has to redirect to index.php every time, can I do away with the redirection?
To summarize the content of both files in words:
Index.php creates a page with 8 images on it. All these 8 images have alternate versions which indicate that the image/button is active or not. Click on the button and the action is performed, click on it again and the action performed is reversed. (XOR function is used) - The current condition of the image/button is dictated by an external variable. (kind of like a feedback system)
Contents of: index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<link rel="stylesheet" type="text/css" href="style2.css" />
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>Project ARC: Adeel's Room Controller</title>
</head><body>
<h1>Welcome to Project ARC</h1>
<?php $curx_val=shell_exec('sudo pin 0x378');
$curx_val=decbin($curx_val);
$curx_val=str_pad($curx_val,8,0,STR_PAD_LEFT);
//echo "$curx_val";
$bit_array=str_split($curx_val,1);
//echo "$bit_array[7]";
echo '<img style="border: 0px solid ; width: 20px; height: 100px;" alt="bit0" src="images/bit' . $bit_array[0] . '.png"> ';
echo '<img style="border: 0px solid ; width: 20px; height: 100px;" alt="bit0" src="images/bit' . $bit_array[1] . '.png"> ';
echo '<img style="border: 0px solid ; width: 20px; height: 100px;" alt="bit0" src="images/bit' . $bit_array[2] . '.png"> ';
echo '<img style="border: 0px solid ; width: 20px; height: 100px;" alt="bit0" src="images/bit' . $bit_array[3] . '.png"> ';
echo '<img style="border: 0px solid ; width: 20px; height: 100px;" alt="bit0" src="images/bit' . $bit_array[4] . '.png"> ';
echo '<img style="border: 0px solid ; width: 20px; height: 100px;" alt="bit0" src="images/bit' . $bit_array[5] . '.png"> ';
echo '<img style="border: 0px solid ; width: 20px; height: 100px;" alt="bit0" src="images/bit' . $bit_array[6] . '.png"> ';
echo '<img style="border: 0px solid ; width: 20px; height: 100px;" alt="bit0" src="images/bit' . $bit_array[7] . '.png"> ';
?><br>
<br>
</body></html>
Contents of dox.php
<html>
<title>PrimaryCommander</title>
<body>
<?php
//Variable Declaration
$set_val=$_REQUEST["setvalue"]; //Which light to switch on
$cur_val=shell_exec('sudo pin 0x378'); //Current lights which are ON
settype($set_val,"integer");
$xor_result=$set_val^$cur_val;
shell_exec('sudo parashell 0x378 '.$xor_result);
header( 'Location: index.php' ) ;
?>
</body>
</html>
Edit1: This script interfaces with the parallel port - thus the shell_exec command. The command 'sudo parashell 0x378 0' sets all pins of parallel port to 0.
Edit2: I understand that once the page has been rendered, it cannot be changed. But can I make the page so as to reflect live changes? (Somewhat like the facebook live feed feature?)
I won't retype all of your code, but something like this would do the trick:
<?php
// retrieve the current bit settings.
$curx_val = shell_exec('sudo pin 0x378');
$curx_val = decbin($curx_val);
$curx_val = str_pad($curx_val,8,0,STR_PAD_LEFT);
$bit_array = str_split($curx_val,1);
if (isset($_GET['setvalue'])) {
... change the bit settings here
}
?>
... display the page and current bit settings here
<img style="border: 0px solid ; width: 20px; height: 100px;" alt="bit0" src="images/bit <?php echo $bit_array[7] ?>.png">
Using this, the first time you visit the page, setvalue won't be present in the script's query line, so the whole "change the bits" portion is avoided. The current bit settings are retrieved
and displayed. Note that the link points at index.php instead now.
Note that if this page is for general public use, then you'll have to be extraordinarily careful with how you do your shell_exec call, especially since you're using sudo. You're executing the 'pin' program with root privileges, so any malicious data submitted by the user can totally destroy your server. Consider the case where someone crafts a query that gets through your XOR calculation and produce ; rm -rf / &. Your script will now happily delete everything on the server.

HTML/CSS question: Part of div being floated to next line, I want it on the same line

I am loading names/grades from a database which happens perfectly... however, the grade assosciated with the person is for some reason getting floated down to the next line and I can't figure out why, as you can see in this picture: http://i.stack.imgur.com/rqhjp.png
I want that number grade to be on the same line, aligned on the right, but I cant figure out why it's getting pushed down to the next line. Here is my php:
echo '<div class = "name">' . $firstname . " " . $lastname . "<strong>" . '<p align="right">' . $avg . '</p></strong></div>';
And the CSS it refers to:
}
#content .name{
background: #FFF;
float:left;
width: 220px;
padding: 0px;
position: relative;
margin: 0px;
font-size: 1.4em;
border: 2px solid #CCC;
border-radius: 10px;
}
Instead of using p and align, put the grade in a span and float it to the right. You can see it working in this fiddle.
'p' is a block element and takes, by default, 100% width.
You can either set a width on the p tag or float right.
I think that if you want to display every person you should use table instead of divs

Categories