I tried many type of codes but neither worked. Last one that I tried is this : Change content of div when clicking on link/button
I have 2 buttons that need to execute script. One is to get dynamic content on page that is not working. Second is to logout of site and that one is working.
Here is part of my main page code :
<?php
echo '<p></p>';
echo '<p></p>';
echo '<div style="width:300px;float:left;">';
echo '<button type="buton" id="loyaltybut" onclick="loyalty()" style="background:#8C8C8C;width:300px;margin-bottom:1px;margin-top:7px;" href="#">But1</button>';
echo '<button type="buton" id="logoutbut" onclick="logout()" style="background:#8C8C8C;width:300px;margin:1px auto;">But2</button>';
#Loyalty report - script
echo '<script type="text/javascript">';
echo 'function loyalty() {';
echo '$("#loyaltybut").click(function(){';
echo '$("#data").load("localhost/data #article1");';
echo '}';
echo '}';
echo '</script>';
#Logout - script
echo '<script>';
echo 'function logout() {';
echo 'window.location.replace("localhost/logout/");';
echo '}';
echo '</script>';
echo '</div>';
echo '<div id="data" style="width:750px;float:right;">';
echo '</div>';?>
My data script :
<?php
echo '<div id="article1">';
echo '<b>ARTICLE 1</b> This is my first article';
echo '</div>';
?>
What can I do to make it work ?
Thanks in advance
To Work with Jquery you have to import jquery.js
<script src="http://www.mneye.com/scripts/jquery172.js" type="text/javascript"></script>
Related
I am currently beginning in php mysqli connections and such, and I'm working on a real estate website design prototype.
As of now I've managed to create a search form which displays every single house available for purchase listed in the mysql database.
Now my task is that when the user clicks one of the homes it activates another .php form which shows a more detailed page.
I'm trying to figure out the proper way to do this.
I'm guessing when the user clicks the div he wants, the php form should get a unique value from said div to query the database for that specific property but I'm at a loss here.
This is the Code for the listed available homes:
<?php
echo "<div id='parent'>";
echo "<section class='responsive HomeBox filterDiv' id='";
echo $resultados['tipo']."";
echo "'>";
echo "<div class='HomeBoxImg'>";
echo "<img class='img-thumbnail img-responsive' alt='Forest'
src='img/propiedades/";
echo $resultados['nombre']."";
?>
/1.jpg' onerror="this.src='img/default.jpg'">
<?php
echo "</div>";
echo "<div class='HomeBoxInfo'>";
echo "<h1>";
echo $resultados['direccion']."";
echo "<h2>";
echo $resultados['estructura']."";
echo "- ";
echo $resultados['tipo']."";
echo "</h2>";
echo "</h1>";
echo "<hr style='width:100%;'>";
echo "<div class='homeboxdetailboxes'>";
echo "<img src='img/icons/bed.png'' alt='Dormitorios'>";
echo "<h4>Dormitorios</h4>";
echo "<h5>";
echo $resultados['dormitorios']."";
echo "</h5>";
echo "</div>";
echo "<div class='homeboxdetailboxes'>";
echo "<img src='img/icons/rooms.png'' alt='Ambientes'>";
echo "<h4>Ambientes</h4>";
echo "<h5>";
echo $resultados['ambientes']."";
echo "</h5>";
echo "</div>";
echo "<div class='homeboxdetailboxes'>";
echo "<img src='img/icons/toilet.png'' alt='Baños'>";
echo "<h4>Baños</h4>";
echo "<h5>";
echo $resultados['baños']."";
echo "</h5>";
echo "</div>";
echo "<div class='homeboxdetailboxes'>";
echo "<img src='img/icons/price.png'' alt='Precio'>";
echo "<h4>Precio</h4>";
echo "<h5>";
echo $resultados['precio']."";
echo "</h5>";
echo "</div>";
echo "</div>";
echo "</section>";
echo "</div>";
?>
So what I'm missing would be the php form for displaying a whole new page based on an id or something provided by the user clicking on of these items.
You can use Javascript/JQuery here, like you can add following
echo '<div id="parent" class="number_<?php echo $resultados['nombre']; ?>">';
then to get specific elements id you can use:
var unique_id = document.getElementById('#parent').className.split('_')[1] //Javascript
var unique_id = $('#parent').attr('class').split('_')[1]; //Jquery
than you can use Ajax request or you can use javascript to change url of current page like:
window.location.href = 'https://www.some_url/'+unique_id;
or you can even wrap each estate item inside , and inside this form put hidden input element like:
<input type="hidden" name="unique_number" value="<?php echo $resultados['nombre']; ?>">
and hook on click event on Javascript or JQuery to submit the form.
i have made a form using php this is my code
<?php
echo "<div class='error_msg'>";
echo validation_errors();
echo "</div>";
echo form_open('user_authentication/new_user_registration');
echo form_label('Create Username : ');
echo"<br/>";
echo form_input('username');
echo "<div class='error_msg'>";
if (isset($message_display)) {
echo $message_display;
}
echo "</div>";
echo"<br/>";
echo form_label('Email : ');
echo"<br/>";
$data = array(
'type' => 'email',
'name' => 'email_value'
);
echo form_input($data);
echo"<br/>";
echo"<br/>";
echo form_label('Password : ');
echo"<br/>";
echo form_password('password');
echo"<br/>";
echo"<br/>";
echo form_submit('submit', 'Sign Up');
echo form_close();
?>
the form is supposed register new users
how can i style this form using css given that there is no html in the code.
The echo(); function you are using essentially prints HTML, this HTML can be styled by including a style sheet (Google CSS basics and you will quickly find out how to do this).
I would advise running this script and using the web inspector of your chosen browser to look at the HTML code you have created using your PHP code. Again, if your not familiar with the web inspector Google how to open it on your chosen browser.
Hope this clarifies things a bit :)
I apologize for any misuse of terminology...I'm a noob...
I have a dynamically created page that contains a dynamic link. I added an IF/ELSE statement to display a different word based on the number of items in the variable $rowsphoto.
The different words display correctly, but the URL that is generated contains all of the PHP instead of generating the correct URL.
This is the original code, which works fine:
<?php if($portfolioid != 0) { ?>
<div class="extrafield">Additional works in Portfolio:</div>
This is the code I have after adding the IF/ELSE statement:
<?php if($portfolioid != 0) { ?>
<div class="extrafield">
<?php
if ($rowsphoto <= 4){
echo "Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=<?php echo $artistid;?>&pid=<?php echo $portfolioid; ?>&album=<?php echo $albumid;?>&id=<?php echo $photoidd; ?>&Itemid=105' class='portfoliocol'>Edition:</a>";
} else {
echo "Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=<?php echo $artistid;?>&pid=<?php echo $portfolioid; ?>&album=<?php echo $albumid;?>&id=<?php echo $photoidd; ?>&Itemid=105' class='portfoliocol'>Portfolio:</a>";
}
?>
</div>
I ran the code through a couple syntax checks and they all came back with no errors. What am I doing wrong? Is this even possible?
You'd be better off using it correctly like this:
<?php if($portfolioid != 0): ?>
<div class="extrafield">
<?php if($rowsphoto <= 4): ?>
Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=<?php echo $artistid; ?>&pid=<?php echo $portfolioid; ?>&album=<?php echo $albumid; ?>&id=<?php echo $photoidd; ?>&Itemid=105' class='portfoliocol'>Edition:</a>
<?php else: ?>
Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=<?php echo $artistid; ?>&pid=<?php echo $portfolioid; ?>&album=<?php echo $albumid; ?>&id=<?php echo $photoidd; ?>&Itemid=105' class='portfoliocol'>Portfolio:</a>
<?php endif; ?>
</div>
<?php endif; ?>
You're mixing html and php very badly. You should be separating them to keep your code clean and concise.
Your issue with it displaying the php instead of the correct variables is because (as #scrowler said):
You can't use PHP tags inside PHP, you just need to escape the string
bounds and use the . concatenation operator instead of trying to open
new PHP tags, e.g. echo "String here" . $varname; as opposed to echo
"String here"
While Darren's answer is correct, alternatively you can just stay inside of php
<?php
if($portfolioid != 0) {
echo '<div class="extrafield">';
if ($rowsphoto <= 4){
echo "Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=$artistid&pid=$portfolioid&album=$albumid&id=$photoidd&Itemid=105' class='portfoliocol'>Edition:</a>";
} else {
echo "Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=$artistid&pid=$portfolioid&album=$albumid&id=$photoidd&Itemid=105' class='portfoliocol'>Portfolio:</a>";
}
echo '</div>';
}
?>
I want to generate a php page which contains HTML and some php commands. Problem is that when I submit the code below, I get this output
<?php echo '$stfromyearErr '?><?php echo '$stfrommonthErr '?><?php echo '$stfromdayErr '?> <?php echo '$sttoyearErr '?><?php echo '$sttomonthErr '?><?php echo '$sttodayErr '?>
rather than php commands. How do I fix this??
Thanks!!
<?php
$page = "<html lang='en'> <head> <meta charset='utf-8' /> </head>
<body><table width='990' border='0' align='center'><tr><td width='54%' colspan='2'>
<span class='error'><?php echo '\$stfromyearErr ';?><?php echo '\$stfrommonthErr
';?><?php echo '\$stfromdayErr ';?> <?php echo '\$sttoyearErr ';?
><?php echo '\$sttomonthErr ';?><?php echo '\$sttodayErr ';?></span></td>
</tr></table> </body></html>";
echo $page;
?>
You're echoing out your PHP tags as <?php, and then presumably displaying that in a browser. It will LOOK like php code in a browser, because the browsers will render < as < but it's NOT PHP code. it's just some text.
PHP is not recursively executable, e.g.
<?php
echo "<?php echo 'foo '; ?>";
?>
would echo out <, ?, p, etc..., not just foo.
You can do stuff like
<?php
$foo = "<?php echo 'hello world!'; ?>";
file_put_contents('hello.php', $foo);
?>
without any issues. As long as the file you're producing actually gets executed by PHP (e.g. don't name it "hello.html"), then PHP will not know (or even care) that the script was produced by some OTHER php code.
You are encapsulating your variables in single-quotes, therefore they get output as plain text, simply remove the commas on any of your echo statements to fix this.
<?php echo $stfromyearErr; ?>
When you want to output PHP code including tag and even syntax highlighting, you can use the function highlight_string(). Documentation here
<?php
highlight_string("<?php echo '$stfromyearErr '?><?php echo '$stfrommonthErr '?><?php echo '$stfromdayErr '?> <?php echo '$sttoyearErr '?><?php echo '$sttomonthErr '?><?php echo '$sttodayErr '?>");
?>
There are two things, first remove the quotes:
<?php
$page = "<html lang='en'> <head> <meta charset='utf-8' /> </head>
<body><table width='990' border='1' align='center'><tr><td width='54%' colspan='2'>
<span class='error'><?php echo $stfromyearErr ?><?php echo $stfrommonthErr
?><?php echo $stfromdayErr ?> <?php echo $sttoyearErr ?
><?php echo $sttomonthErr ?><?php echo $sttodayErr ?></span></td>
</tr></table> </body></html>";
echo $page;
?>
However, this will give you:
<?php echo your_var_1 ?><?php echo your_var_2 ?><?php echo your_var_3 ?> <?php echo your_var_4 ? ><?php echo your_var_5 ?><?php echo your_var_6 ?>
This is because the php tags are redundant: you have already started php and are echoing these out within php.
If this is unavoidable, try replacing them like this:
echo str_replace(" ?>", "", str_replace("<?php echo", "", $page));
Hello I have this src path in codeigniter
src="<?php echo base_url();?>photos/<?php echo $data1; echo '"/>';?>
The problem is that when i'm going to continue my code it seems that all the below code is inside an echo ""; it looks like the echo is still open.. For example i want to continue my code with a html divand thediv` is still on an echo area.. Thanks
I think you are inside of quotes of src-property.
src="<?php echo base_url();?>photos/<?php echo $data1;?>" />
try this
src="<?php echo base_url();?>photos/<?php echo $data1;?>" />
try this
<?php echo 'src="'.base_url().'photos/'.$data.'" />'; ?>
or
<?php echo '<img src="'.base_url().'photos/'.$data.'" />'; ?>
it seems like you haven't closed the last echo . tyr this
src="<?php echo base_url();?>photos/<?php echo $data1;?>" />
there is more better way of doing this in codeigniter. pass the url as the arguement to the base_url function
src="<?php echo base_url('photos/'.$data1);?>" />
try it. for more details: click