Selecting php out with JQuery [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
This is a code snippet I have and I would like to be able to select the out of PHP. When I try to grab the PHP output and store it into a variable, I receive "undefined".
<h1 id=<?php echo '$test; ?> class="list-name--original">
My last attempt I tried this code:$("h1.list-name--original")[0].outerHTML);

Why not just put all your PHP output in a variable
<script>
var data = '<?=$test?>';
</script>
You can then set the contents of an H1 tag like this
<h1 id="myid"></h1>
<script>
$('h1#myid').text(data);
</script>

Try
<h1 id="<?php echo $test; ?>" class="list-name--original">
in jQuery
$(".list-name--original").html();
or
$("#<?= $test ?>").html();

Try this:
<?php $test = "Hello world!"; ?>
<h1 id="example" class="list-name--original"><?php echo $test; ?></h1>
<script language="javascript">
$("#example").html();
</script>

Related

Show image only if jsonObj has a value [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
If <?php echo $jsonObj->data->image; ?> has a value, like 1234.jpg I want to show this:
<img src="https://www.example.com/img/<?php echo $jsonObj->data->image; ?>" />
If <?php echo $jsonObj->data->image; ?> has no value, then <img src="https://www.example.com/img/<?php echo $jsonObj->data->image; ?>" /> should remain hidden.
Any help please?
Use php if-else statement for that.
<?php
if(!empty($jsonObj->data->image)) {
?>
<img src="https://www.example.com/img/<?php echo $jsonObj->data->image; ?>" />
<?php
}
?>
You can add else part and do whatever you want.

How to print Table of this format [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have following data in mysql, and I want to echo in this format:
Data:
Name,Image URL,Link
I want to print it dynamically like this : http://screensaver.cf/screensavers.php
I don't know user's screen width, still I want it to appear as much as possible in width.
How can I do this in html and PHP?
My code:
<?php
require("config.php");
?>
<div id="main-wrap">
<div class="container">
<div id="main">
<div id="content"><div id='wsite-content' class='wsite-elements wsite-not-footer'>
<div class="paragraph" style="text-align:left;">
<?php
$sql='SELECT * FROM `games` where 1=1';
$data = mysql_query($sql);
echo '<h4 class="result">Result:</h4>';
while($row = mysql_fetch_row($data)){
$table=WHAT TO DO HERE TO MAKE IT LOOK LIKE THAT???????
echo $table;
echo '<br><br>';
}
?>
</div>
</div>
</div>
</div>
</div>
<?php
include("footer.php");
?>
P.S I know mysql is depreciated and I am constantly working to learn Mysqli, as I am in 8th class, I don't have much time.
<style>.a{float:left;}
</style>
>
in while loop use this
<div class = "a">
<?php <img src='".$row['url']."' width='140' height='140'> ?>
</div>

PHP/Html file into a html file [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am a newbie in coding etc. so I am trying to get some help from you guys. I have to put every single file (.php) in one .html/php file.
Now I got this code:
<html>
<head>
<style type='text/css'>
span {
text-decoration:underline;
color:blue;
cursor:pointer;
}
</style>
<script>
// show the given page, hide the rest
function show(elementID) {
// try to find the requested page and alert if it's not found
var ele = document.getElementById(elementID);
if (!ele) {
alert("no such element");
return;
}
// get all pages, loop through them and hide them
var pages = document.getElementsByClassName('page');
for(var i = 0; i < pages.length; i++) {
pages[i].style.display = 'none';
}
// then show the requested page
ele.style.display = 'block';
}
</script>
</head>
<body>
<p>
Show page
<span onClick="show('Page1');">1</span>,
<span onClick="show('Page2');">2</span>,
<span onClick="show('Page3');">3</span>.
</p>
<div id="Page1" class="page" style="">
Content of page 1
</div>
<div id="Page2" class="page" style="display:none">
Content of page 2
</div>
<div id="Page3" class="page" style="display:none">
Content of page 3
</div>
</body>
So my question is; how do i put my files into the 'Content of page 1/2/3'?
Thanks in advance!
Try include("[path to your file]"); or include_once("[path to your file]");
http://php.net/manual/en/function.include.php
http://php.net/manual/en/function.include-once.php
If you need to combine other PHP files with this HTML file, simply change the name of this file to .php if it isn't already. Then copy/paste your code (in order each file is processed) into the top of this file. Be sure to surround your php with <?php and ?>. The HTML will still display correctly if it's inside a PHP file.
Note: This is not good practice, but it will accomplish what your teacher is requesting.

pull Else if from SQL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need the data to have a different style if the sold = 0 in the mysql table
and when i use the code below the website shows a blank white page
(?=$vehicle-> this is the vehicle reference
and sold is the column withing the sql table
<?php
if (?=$vehicle->sold?!= 1)
{
<div class="foo">
<div class="fboverlay"></div>
<a>
<img src="/media.php?productId=<?=$vehicle->vehicle_id?>&file=<?=$vehicle->main_image?>" />
</a>
</div>
}
else {
<img src="/media.php?productId=<?=$vehicle->vehicle_id?>&file=<?=$vehicle->main_image?>" />
}
?>
You need to learn the PHP from the basics. Learn about operators, PHP and HTML secion, etc..
Anyway, i fixed your code. The condition is if $vehicle->sold is not equal to 1. But i think, (in your OP you mentioned it should be 0) you want this: $vehicle->sold == 0
//Use sytnax like this. See php opeartors.
if ($vehicle->sold != 1) {
?> <!-- Close the php -->
<div class = "foo">
<div class = "fboverlay"></div>
<img src = "/media.php?productId=<?= $vehicle->vehicle_id ?>&file=<?= $vehicle->main_image ?>" />
</div>
<?php
//Open the php again
} else {
?> <!-- close the php -->
<img src = "/media.php?productId=<?= $vehicle->vehicle_id ?>&file=<?= $vehicle->main_image ?>" />
<?php //Open again
}

HTML div mapping [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
If I defined some div in a code like this:
if(...)
{
// code
// code again
if(...)
{
// code
<div> first div </div>
//code code
}
}
<div> second div </div>
So "first div" always appears before the "second div", how can I switch the order of div's displaying? Thanks.
how about this (you need div id's)
$('#secondDiv').insertBefore('#firstDiv').remove();
Change your code to:
if(...)
{
// code
// code again
if(...)
{
// code
<div id='firstDiv'> first div </div>
//code code
}
}
<div id='secondDiv'> second div </div>
You can show the second <div> in a predetermined place by appending it to another div. For example:
HTML:
<div id="fake-second"></div>
<div id="first"> first div </div>
<div id="second"> second div </div>
jQuery:
$("#fake-second").append($("#second").html());
$("#second").hide();
JS Fiddle Demo

Categories