and thank you in advance for your great work here, i need help with some coding, i got a web page where i show a list of records of a mysql table, with a hyperlink when you click on it creates a variable like world.php?id=1&xx=1050&yy=300 so when the user clicks it takes him to next page and scroll down and up to the x and y it, works fine in web browsers but not working in mobiles. can you help me? the page world.php has
,)">
this is the code i'm using
echo '<a href="world.php?xx='. $_SESSION['x'] .'&yy='. $_SESSION['y'] .'">';
echo '<b>';
echo $row['usuario_atacante'];
echo '</b>';
echo '</a>';
Can you do something like this ?
Row 5
and make links in your world.php file.
<table>
<tr id="row1"><td><h2>Row 1</h2></td></tr>
<tr id="row2"><td><h2>Row 2</h2></td></tr>
<tr id="row3"><td><h2>Row 3</h2></td></tr>
<tr id="row4"><td><h2>Row 4</h2></td></tr>
<tr id="row5"><td><h2>Row 5</h2></td></tr>
</table>
Use a link like: world.php?x=345&y=200 to scroll to that location.
<?php
if(isset($_GET["x"]) && isset($_GET["y"])) {
$x = $_GET["x"];
$y = $_GET["y"];
}
?>
<!DOCTYPE html>
<html>
<head>
<title>World Map</title>
<script>
function scrollWin() {
window.scrollTo(<?php echo $x.",".$y; ?>);
}
</script>
</head>
<body onload="scrollWin()">
<img src="https://upload.wikimedia.org/wikipedia/commons/e/e2/Geoffroy's_Cat.jpg" />
</body>
</html>
This is just a example to get you started.
Related
Can't get image URL to display in my code; this is my URL: https://production.cdmycdn.com/webpack/renderer/d7285ffbbd0ca6d1d2179f7d22ea1f67.svg
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<!DOCTYPE html>
<html>
<head>
<title>PHP Exercise 1: Links and Variables</title>
</head>
<body>
<h1>PHP Exercise 1: Links and Variables</h1>
<p>Use PHP echo and variables to output the
following link information:</p>
<hr>
<?php
$linkName ='<h1> Codecademy <h1>';
$linkURL = 'codecademy';
$linkImage =
'https://production.cdmycdn.com/webpack/renderer/d7285ffbbd0ca6d1d2179f7d22ea1f67.svg';
$linkDescription = 'Learn to code interactively, for free.';
$my_name = "peter";
echo "<img>" . $linkImage . "</img>";
echo $linkName;
echo "<br>";
echo $linkURL;
echo "<br>";
echo $linkImage;
echo "<br>";
echo $linkDescription;
$linkImage = 'https://production.cdmycdn.com/webpack/renderer/d7285ffbbd0ca6d1d2179f7d22ea1f67.svg';
echo '<img src="data:image/jpeg;base64,">';
?>
</body>
</html>
A link to an image should always be put in the src attribute when you're using the img tag in html.
That means you should be looking for something like "<img src=".$linkImage."></img>" instead of "<img>".$linkImage."</img>"
Of course, that only applies if the problem you're referring to is the fact that there should be an image after the sentence "Learn to code interactively, for free."
Works just fine for me. Try checking php permissions.
I want to hide a div from direct users but showing the same div to those who come from example.com
eg.
example123.com/article.php have below div
<div id="main">Title</div>
(when user click on a hyperlink on example.com
Artile
then show the above div
but when user come directly to example123.com/article.php then don't show the div.
how will I do that using php?
Hi you can use the following code like this.
<?php if (isset($_SERVER['HTTP_REFERER'])){ ?>
<div style="width:200px;height:200px;border:1px solid black">
<?php } ?>
You need to make use of $_SERVER['HTTP_REFERER']
I don't totally follow your question but this code should be enough for you to adapt to your needs:
if(strstr($_SERVER['HTTP_REFERER'],'example.com')) {
echo '<div id="main">Title</div>';
}
So, if the referrer URL contains example.com then echo your div.
If the referral URL didn't contain example.com or was empty (i.e. they arrived directly at your site) then the div won't show.
You can achieve this by passing an argument from the URL. The value of the argument will be null if they access the page directly and only have a value if they use the specific URL. Then your PHP can just check the argument and handle it accordingly.
Example as follows.
index.php
<!DOCTYPE html>
<html>
<head>
<title>Nothing</title>
</head>
<body>
<h1>Nothing 01</h1>
Regular URL
<br />
Argument URL
</body>
</html>
Then you can handle the Arguments in your PHP page containing the div
pagewithdiv.php
<!DOCTYPE html>
<html>
<head>
<title>Nothing</title>
</head>
<body>
<h1>Nothing 02</h1>
<div id="conditional">
<h2>Conditional Div</h2>
</div>
<?php
if (
// check if argument exists
isset($_GET["Condition"])
&&
// check if argument value is true
trim($_GET["Condition"] == true)
) {
echo '<script>';
echo 'document.getElementById("conditional").style.display = "block"';
echo '</script>';
} else {
echo '<script>';
echo 'document.getElementById("conditional").style.display = "none"';
echo '</script>';
}
?>
</body>
</html>
Keep in mind though that this is only hiding the div, it still exists on the page. If you want it to be completely gone then instead of using javascript to change the visibility you can echo the code that makes up the div if the requirements are met.
<!DOCTYPE html>
<html>
<head>
<title>Nothing</title>
</head>
<body>
<h1>Nothing 02</h1>
<?php
if (
// check if argument exists
isset($_GET["Condition"])
&&
// check if argument value is true
trim($_GET["Condition"] == true)
) {
echo '<div id="conditional">';
echo ' <h2>Conditional Div</h2>';
echo '</div>';
}
?>
</body>
</html>
I have the following HTML code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>TestPost</title>
<script src="jquery-2.1.4.min.js"></script>
<script src="more.js"></script>
</head>
<body>
<div class="post1">
This is post one
</div>
<div class="post1">
Another post number one
</div>
<div class="post2">
And this is post two
</div>
<div class="post3">
Last but not least, post three
</div>
</body>
</html>
What i'm looking for is the folowing:
When the text in a div is longer that, lets say, 5 chars, it should cut it off and add ...read more(including a link to a page).
I tried some PHP and some JQuery, but to be honest, I'm not sure anymore what to use.
If I could get the answer, that would be fantastic, but a push in the right direction would be very appreciated as well :)
Edit: The second post1 was added for testing purposes for anyone who's wondering.
Use attribute class instead of id. replace id='post' with class='post'
Use this code into your more.js
var mess_content = $('.post');
mess_content.each(function(){
if ($(this).text().length > 120) {
var obrtext = $(this).text().substr(0,120) ;
$(this).html(obrtext+"<a href='#'>read more</a>") ;
}
});
To do this with PHP, when you ouput your text, run it through a shortening function like this:
function shorten($output, $limit = 5) {
$output = htmlspecialchars($output, ENT_QUOTES, 'UTF-8');
if (strlen($output) > $limit) {
$output = substr($output, 0, $limit) . ' ... read more';
}
echo $output;
}
You can use it then like this:
<div id="post1">
<?php shorten('This is post one'); ?>
</div>
So I'm trying to make a page where i can display results from my database table. You should be able to search and there should be some pagination as there are thousands of results.
I've managed to make a page which just has the search, and works perfect. So now i need to know how would would integrate some pagination into that.
index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="container">
<form action="" method="get">
<input type="text" name="search" id="search" placeholder="Search" />
<input type="submit" />
</form>
<?php include 'process.php'; ?>
</div> <!-- /container -->
<script src="js/jquery.js"></script>
<script src="js/script.js"></script>
</body>
</html>
process.php
<?php include 'dbconfig.php'; ?>
<?php include 'connect.php'; ?>
<?php
$search = $_GET['search'];
$result = mysql_query("SELECT * FROM oantkb WHERE Name LIKE '%$search%' ORDER BY `INDEX` DESC");
echo '<table class="table">';
echo '<thead>';
echo '<tr>';
echo '<th>#</th>';
echo '<th>Pic</th>';
echo '<th>Name</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
while($row = mysql_fetch_assoc($result)) {
$pic = $row['Pic'];
$name = $row['Name'];
echo '<tr>';
echo '<td>#</td>';
echo '<td><img src="'.$pic.'" height="50" width 50"></td>';
echo '<td>'.$name.'</td>';
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
?>
Right now it works like it should. When i search it will say index.php?search=banana, but i need some pagination added so it will say for example index.php?search=banana&?page=2. Or something along those lines. Hope it makes sense...i'm a php newb :)
Include at the end of your sql query the following:
$resultsPerPage=10;
$page = ($_GET["page"]-1)*$resultsPerPage;
$query = $query." LIMIT $page,$resultsPerPage";
mysql_query($query);
By the way the mysql_ library is deprecated in favor of mysqli.
Also the above is susceptible to sql injection attacks because $_GET["page"] isn't first sanitized, but for simplicity I did it this way.
This assumes a paging scheme that starts at 1.
i've been using Pear Pagination for a long time. you can try it.
here is a good tutorial for setting it up
Simple Pagination in PHP tutorial
a good thing to add is clean your variable before using them in your query.
<?php
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=London');
$information = $xml->xpath("/xml_api_reply/weather/forecast_information");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
?>
<html>
<head>
<title>Google Weather API</title>
</head>
<body>
<h1><?php print $information[0]->city['data']; ?></h1>
<h2>Today's weather</h2>
<div class="weather">
<img src="<?php echo 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"?>
<span class="condition">
<?php echo round(conver_f_c($current[0]->temp_f['data'])); ?>° C,
<?php echo $current[0]->condition['data'] ?>
</span>
</div>
<h2>Forecast</h2>
<?php foreach ($forecast_list as $forecast) : ?>
<div class="weather">
<img src="<?php echo 'http://www.google.com' . $forecast->icon['data']?>" alt="weather"?>
<div><?php echo $forecast->day_of_week['data']; ?></div>
<span class="condition">
<?php echo round(conver_f_c($forecast->low['data'])); ?>° C - <?php echo round(conver_f_c($forecast->high['data'])); ?>° C,
<?php echo $forecast->condition['data'] ?>
</span>
</div>
<?php endforeach ?>
</body>
</html>
<?php
function conver_f_c($F){
return $C = ($F − 32) * 5/9;
}
I want Out somthing like this manner of the horizontal ,
Even i tried UL LI WITH display inline but it goes failed,
Tell me some good suggestion for my probme,
I want exactly like horizontal, expecting exactly like screen shot ,
Tell me How to render using php
Thanks
alt text http://img163.imageshack.us/img163/7518/weatherhori.jpg
Above snippet present display out verticly , i want o change that verticle to horizonatal ,
somthing like this screen shot
<table>...</table>
Update
From your latest comment so far:
i know how to fetch array and display
it, but i dont know to fetch and
display in the verticl manner that is
the stuck up
I feel this is going to be a stupid answer but it appears to be what you don't understand...
The web is based in a markup language called HTML. This language has tags (delimited by angle-brackets) that allow you to define the structure of a document. On top of this, you have another language called CSS. This other lang allow you to define how HTML is going to be displayed on screen.
You may argue that you already have a web page and you've written it with the PHP language instead of the two other langs I've mentioned. That's not enterely true: you code in PHP, sure, but you use PHP to generate HTML. And it's HTML what finally reaches the browser (Firefox, Explorer...). PHP is executed in the web server, not in the browser. The browser can only see whatever HTML you've generated.
To sum up: you have to forget about PHP, Google and the whole weather thingy. You first need to write a static HTML document and style it with CSS. Once you've done with it, you can finally replace the parts of the information that are dynamic with values taken from your PHP variables.
And since you seem to need a table to display tabular data, the appropriate HTML tag is <table>:
<table>
<tr>
<th>Web</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
</tr>
<tr>
<td><img src="/path/to/pics/cloudy.png" width="25" height="25" alt="Cloudy"></td>
<td><img src="/path/to/pics/sunny.png" width="25" height="25" alt="Sunny"></td>
<td><img src="/path/to/pics/rainy.png" width="25" height="25" alt="Rainy"></td>
<td><img src="/path/to/pics/cloudy.png" width="25" height="25" alt="Cloudy"></td>
</tr>
<tr>
<td>26ºC</td>
<td>26ºC</td>
<td>22ºC</td>
<td>25ºC</td>
</tr>
<table>
I suggest you find some tutorials about basic HTML and CSS. They'll be of invaluable help.
This is what's done by Google :
http://jsfiddle.net/bW8NA/1