Sitemap not working empty page show - php

My sitemap not working its not showing any url or data when i run my sitemap its showing blank empty page
Here is my code for sitemap and keywords is main table name and check image for my table
<?php
require dirname(__FILE__) . ("/includes/includes.php");
header("Content-Type: text/xml");
print "<?xml version='1.0' encoding='utf-8'?>";
$pageLimit = 50000;
$base = "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
$base = substr($base,0,strrpos($base,"/")+1);
$link = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db($db_name,$link);
if (isset($_GET["page"]))
{
print "<urlset xmlns='http://www.google.com/schemas/sitemap/0.84' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd'>";
$page = intval($_GET["page"]);
$from = (($page-1)*$pageLimit);
$sql = "SELECT * FROM keywords LIMIT ".$from.",".$pageLimit;
$result = mysql_unbuffered_query($sql,$link);
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
print "<url>";
print "<loc>".genSearchUrl(implode('-',array_filter(explode('-', str_replace(' ', '-', xmlentities(iconv("utf-8", "utf-8//ignore", $row["keyword"])))))))."</loc>";
print "</url>";
}
print "</urlset>";
}
else
{
print "<sitemapindex xmlns='http://www.google.com/schemas/sitemap/0.84' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/siteindex.xsd'>";
$sql = "SELECT count(*) as count FROM keywords";
$result = mysql_query($sql,$link);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$pages = ceil($row["count"] / $pageLimit);
for($i=1;$i<=$pages;$i++)
{
print "<sitemap>";
$loc = $base."sitemap.php?page=".$i;
print "<loc>".$web_path."sitemap_".$i.".xml</loc>";
print "</sitemap>";
}
print "</sitemapindex>";
}
exit();
function xmlentities($text)
{
$search = array('&','<','>','"','\'');
$replace = array('&','<','>','"','&apos;');
$text = str_replace($search,$replace,$text);
return $text;
}
?>

Related

Display only 20 characters from content? Display paragraphs?

I have separate question really which I need help. I only want to display say 20 characters from 'content'.
<?php
$output = '';
if(isset($_GET['q']) && $_GET['q'] !== ' ') {
$searchq = $_GET['q'];
$q = mysqli_query($db, "SELECT * FROM article WHERE title LIKE '%$searchq%' OR content LIKE '%$searchq%'") or die(mysqli_error());
$c = mysqli_num_rows($q);
if($c == 0) {
$output = 'No search results for <strong>"' . $searchq . '"</strong>';
} else {
while($row = mysqli_fetch_array($q)) {
$id = $row['id'];
$title = $row ['title'];
$content = $row ['content'];
$output .= '<a href="article.php?id=' .$id. '">
<h3>'.$title.'</h3></a>'.$content.'';
}
}
} else {
header("location: ./");
}
print("$output");
mysqli_close($db);
?>
i will answer your first question:
insert this line after:
$content = $row ['content'];
if(strlen($content)>20) $content=substr ($content,0,19);

php generating rssfeed filename from field in a table?

SOLUTION
<?php
include("authenticate.php");
$user = $_SESSION['UserName'];
$initialdata = $result = mysql_query("SELECT * FROM ccregisterfeed WHERE username = '$user'");
while($row = mysql_fetch_assoc($initialdata)){
$filename = $row["feedlink"];
// var_dump ($filename);
}
$initdata = mysql_fetch_assoc($initialdata);
$result = mysql_query("SELECT * FROM ccshowcontent JOIN ccaudio ON ccshowcontent.id = ccaudio.id WHERE ccshowcontent.username = '$user' ORDER BY ccshowcontent.id DESC")
or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
$items[] = $row;
}
$rss = createXML($items,$initdata);
//echo "feed updated!";
$filename = ($filename);
file_put_contents($filename,$rss);
header("Location: ccupload.php?message=".urlencode("Show saved and feed updated"));
?>
FULL SCRIPT
<?php
include("authenticate.php");
$user = $_SESSION['UserName'];
$initialdata = $result = mysql_query("SELECT * FROM ccregisterfeed WHERE username = '$user'");
$initdata = mysql_fetch_assoc($initialdata);
$result = mysql_query("SELECT * FROM ccshowcontent JOIN ccaudio ON ccshowcontent.id = ccaudio.id WHERE ccshowcontent.username = '$user' ORDER BY ccshowcontent.id DESC")
or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
$items[] = $row;
}
function createXML($items,$data){
$xml = "<?xml version='1.0' encoding='UTF-8'?>
<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>
<channel>
<atom:link href='".$data['feedlink']."'
rel='self' type='application/rss+xml' />
<title>".$data['feedtitle']."</title>
<link>".$data['websitelink']."</link>
<category domain=''>".$data['category']."</category>
<copyright>".$data['copyright']."</copyright>
<pubDate>".date("D, d M Y H:i:s O", strtotime($data['pubdate']))."</pubDate>
<language>en-us</language>
<description>".$data['feeddescription']."</description>
<image>
<title>".$data['feedtitle']."</title>
<link>".$data['websitelink']."</link>
<url>".$data['imagelink']."</url>
<description>".$data['imagetitle']."</description>
</image>";
$audiodir = "http://thetradingcardgenerator.com/MP3/";
foreach($items as $key => $item){
$path = $audiodir.$item['path'];
$pdate = strtotime($item['pubdate']);
$date = date("D, d M Y H:i:s O", $pdate);
$xml .="
<item>
<title>".$item['title']."</title>
<link>".$path."</link>
<guid>".$path."</guid>
<pubDate>".$date."</pubDate>
<description><![CDATA[".$item['description']."]]></description>
</item>";
}
$xml .="
</channel>
</rss>";
return $xml;
}
$rss = createXML($items,$initdata);
//echo "feed updated!";
$filename = '$feedlink' . ".xml";
file_put_contents($filename,$rss);
header("Location: ccupload.php?message=".urlencode("Show saved and feed updated"));
?>
FIRST ENTRY
I've wrote a script to generate an rss feed from data entered in a table. I want to generate the filename from a field in the table, which I created as follows :
$path = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$feedtitle = str_replace(" ", "", $feedtitle);
$feedtitle = str_replace("_", "", $feedtitle);
$feedtitle = str_replace("-", "", $feedtitle);
$feedtitle = strtolower($feedtitle);
$path = substr($path, 0, strrpos($path, "/"));
$feedlink = "$feedtitle" . '.xml';
Thus if $feedtitle was Last Nights Television the value of $feedlink would be
lastnightstelevision.xml
I've tested the script by specifying the filename and it works, data is pulled from the tables and a feed is created. This is the last part of the script :
$rss = createXML($items,$initdata);
$filename = 'myfeed.xml';
file_put_contents($filename,$rss);
header("Location: uploadcontent.php?message=".urlencode("Show saved and feed updated"));
?>
Which creates a feed name myfeed.xml on my server.
However I want the filename of the feed to be the value of $feedlink. I know this is probably something basic but I can't figure out how to do it.
I tried :
$filename = ".$feedlink";
$filename = ".$feedlink[feedlink]";
And many other combinations.
If you're trying to get that filename from RSS, try this
$attribute = $rss->channel->children("atom", true)->link->attributes();
$filename = $attribute["href"];
Or this, if you want to get it from results returned from your first query
$filename = $initdata['feedlink'];
The result above is a whole path, so if you need only the filename from that path, use this
$feedlink = "http://mywbsite/mydir/lastnightstelevision.xml";
$filename = basename($feedlink);
Output:
lastnightstelevision.xml
Working demo

How to use parameters in url php?

I have a number pages namely
change=1.php
change=2.php
change=3.php
They all have similar coding but leaving 1 or 2 variable values.
And I know its a very bad idea! How can I make a link work like below:
change.php?id=1
change.php?id=2
change.php?id=3
http://oi62.tinypic.com/708gfm.jpg
<?php
include 'connection.php';
session_start();
include 'details.php';
/*$pkmn_id = $_SESSION['pkmn_id'];
$poke = $_SESSION['path'];*/
$data = mysql_query(" SELECT * FROM user_pokemon_db WHERE team = 1 AND user_id = '".$id."' ");
while($rows = mysql_fetch_array($data))
{
$rep_id = $rows[0];
$pkmn_id = $rows['pkmn_id'];
$path = mysql_query(" SELECT * FROM pokemons WHERE pk_id = '".$pkmn_id."' ");
$poke = mysql_result($path, 0, "path");
echo $poke;
echo "<br />";
$level = $rows['level'];
echo $level;
echo "<br />";
$exp = $rows['exp'];
echo $exp;
echo "<br />";
echo "<br />";
}
$data = mysql_query(" SELECT * FROM user_pokemon_db WHERE user_id = '".$id."' AND team = 0");
while($rows = mysql_fetch_assoc($data))
{
$db_id = $rows['id'];
$array[] = $db_id;
$level = $rows['level'];
$array1[] = $level;
$exp = $rows['exp'];
$array2[] = $exp;
$pkmn_id = $rows['pkmn_id'];
$data1 = mysql_query(" SELECT * FROM pokemons WHERE pk_id = '".$pkmn_id."' ");
while($rows = mysql_fetch_assoc($data1))
{
$poke = $rows['path'];
$array3[] = $poke;
}
}
$team = 1;
$_SESSION['team'] = $team;
$_SESSION['rep_id'] = $rep_id;
?>
My PHP code.
You probably want to use GET variables, for which you need to combine all the files into one, named change.php. In this file you need the line $foo = $_GET["id"] which will get the value of the variable "id" in the url change.php?id=1.
if (isset($_GET["id"])) {
$foo = $_GET["id"];
//your code here
}else{
echo 'ERROR!!! No id in URL';
}
You can have several variables in the URL like this: change.php?id=1&a=bar&b=toofoo
You can get current script's file name and parse integer.
__FILE__
gives current script's name. Then,
$myStr = preg_replace('/\.php$/', '', __FILE__);
$result = preg_replace('/change=$/', '', $myStr);
echo $result; // it's your id

varifying json response on nested ajax call

I tested my jsno example here:
data.php
<?php
ob_start();
echo "string1";
$div1 = ob_get_clean();
ob_start();
echo "string2";
$div2 = ob_get_clean();
$resultArray = array("resultOne" => $div1,"resultTwo" => $div2);
echo json_encode($resultArray);
?>
start.php
xmlhttp.onreadystatechange=function()
{
var div1=document.getElementById("myDiv1");
var div2=document.getElementById("myDiv2");
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var data=JSON.parse(xmlhttp.responseText);
//document.getElementById("myDiv1").innerHTML=xmlhttp.responseText;
div1.innerHTML=data['resultOne'];
div2.innerHTML=data['resultTwo'];
}
}
This gives correct result and show data.
Now I tried to implement on my actual application.
login.php (verify user login, if success) -> start.php (loaded into login.php through ajax) -> data.php (returns json array values as in above case)
just difference is data.php is in following manner:
<?php
$url = $_POST['url'];
$user_id = $_POST ['userid'];
if(isset($_POST['rate']))
{
$rate =$_POST['rate'];
}
else
$rate = 0;
$data = file_get_contents($url);
function get_title($html)
{
return preg_match('!<title>(.*?)</title>!i', $html, $matches) ? $matches[1] : '';
}
function get_logo($html)
{
preg_match_all('/\bhttps?:\/\/\S+(?:png|jpg)\b/', $html, $matches);
//echo "mactch : $matches[0][0]";
return $matches[0][0];
}
function plaintext($html)
{
// remove comments and any content found in the the comment area (strip_tags only removes the actual tags).
$plaintext = preg_replace('#<!--.*?-->#s', '', $html);
// put a space between list items (strip_tags just removes the tags).
$plaintext = preg_replace('#</li>#', ' </li>', $plaintext);
// remove all script and style tags
$plaintext = preg_replace('#<(script|style)\b[^>]*>(.*?)</(script|style)>#is', "", $plaintext);
// remove br tags (missed by strip_tags)
$plaintext = preg_replace("#<br[^>]*?>#", " ", $plaintext);
// remove all remaining html
$plaintext = strip_tags($plaintext);
return $plaintext;
}
function trim_display($size,$string)
{
$trim_string = substr($string, 0, $size);
$trim_string = $trim_string . "...";
return $trim_string;
}
$title = get_title($data);
$logo = get_logo($data);
$title_display = trim_display(30,$title);
$content = plaintext($data);
$Preview = trim_display(100,$content); //to Show first 100 char of the web page as preview
function MakeTinyUrl($url)
{
return md5($url);
}
$hash = MakeTinyUrl($url);
ob_start();
$con = mysqli_connect('127.0.0.1', 'root', '', 'mysql');
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
return;
}
$content=mysqli_real_escape_string($con,$content);
$Preview=mysqli_real_escape_string($con,$Preview);
$title_display=mysqli_real_escape_string($con,$title_display);
$result = mysqli_query($con,"SELECT COUNT(*) as val FROM post_data WHERE url ='".$url."' and userid='".$user_id."'");
$bool= mysqli_fetch_assoc($result);
if($bool['val'])
{
echo '<div style="clear:both;"><i>You have already worked on this url..</i> </div>';
}
else
{
$insertQuery = "INSERT INTO post_data(`userid`, `url`, `desc`, `preview`, `img_url`, `title` ,`hash`) VALUES ('".$user_id."','".$url."','".$content."','".$Preview."','".$logo."','".$title_display."','".$hash."')";
if (!mysqli_query($con,$insertQuery))
{
die('Error: ' . mysqli_error($con));
}
}
$result = mysqli_query($con,"SELECT * FROM post_data WHERE userid ='".$user_id."' and url='".$url."'");
//This will fetch only one row from db
while ($row = #mysqli_fetch_array($result))
{
$title = $row['title'];
$url = $row['url'];
$preview = $row['preview'];
$image = $row['img_url'];
}
//Update Rate value in table
$update = "update post_data set rate='".$rate."' where url='".$url."'";
if (mysqli_query($con, $update))
{
//echo "updated";
}
else
{
//echo "Not updated";
}
?>
<html>
<body>
<a class="fragment" href="google.com">
<div>
<span id='close' onclick='this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode); return false;'>x</span>
<img src ="<?php echo $image ?>" height="116" width="116" alt="some description"/>
<h3><?php echo $title ?></h3>
<h4><?php echo $url ?> </h4>
<p class="text"> <?php echo $preview ?>
</p>
</div>
</a>
<?php
$div1 = ob_get_clean();
ob_start();
$result = mysqli_query($con,"SELECT * FROM post_data WHERE userid ='".$user_id."'");
echo "Records for user : $user_id"; echo "<br/>";
while ($row = #mysqli_fetch_array($result))
{
$title = $row['title'];
$url = $row['url'];
$preview = $row['preview'];
$image = $row['img_url'];
echo "Title: $title"; echo '<br/>';
echo "URL: $url"; echo '<br/>';
echo "Preview : $preview"; echo '<br/>';
echo "Image url: $image"; echo '<br/>';
//echo '</br>';
}
$div2 = ob_get_clean();
$resultArray = array("resultOne" => $div1,"resultTwo" => $div2);
echo json_encode($resultArray);
?>
</body>
</html>
I get error message:
SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data
var data=JSON.parse(xmlhttp.responseText);
You can validate your json responses using below url, so that you can conclude your results some point,
$resultArray = array("resultOne" => $div1,"resultTwo" => $div2);
echo json_encode($resultArray);
Ref: http://jsonformatter.curiousconcept.com/#jsonformatter

Grabbing All of MYSQL Rows Using Array

Hi I'm trying to output all of the rows and information from my table :
id,Symbol,entry,exit,openclosed,entrydate,longshort,target_one,target_two,target_three,notes
This is through this script I'm working on to get this functionality. Right now I'm only outputting one of the database entries. This entry of course being the last one. For reference the last entry symbol is GLD. I'd like it to continue with the next symbols, but can't seem to get it to output. The outputted data for quote_0,quote_1 ect. come from yahoo as an array.
<?php
error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors", 1);
//begin
include "storescripts/connect_to_mysql.php";
$sql = mysql_query("SELECT * FROM stockpicks ORDER BY id LIMIT 100");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
// get all the product details
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$symbol = $row["symbol"];
}
}
mysql_close();
//end
if(empty($symbol)) {
echo nothing;
}
else {
$open = fopen("http://quote.yahoo.com/d/quotes.csv?s=$symbol&f=sl1d1t1c1ohgv&e=.csv", "r");
$quote = fread($open, 1000);
fclose($open);
$quote = str_replace("\"", "", $quote);
$quote = explode(",", $quote);
$quote_0 = ($quote[0]);
$quote_1 = ($quote[1]);
$quote_2 = ($quote[2]);
$quote_3 = ($quote[3]);
$quote_4 = ($quote[4]);
$quote_5 = ($quote[5]);
$quote_6 = ($quote[6]);
$quote_7 = ($quote[7]);
$quote_8 = ($quote[8]);
echo "<div class='symbol'><div class='quote'>Company: $quote_0</div></div>";
echo "<div class='leftofStocks'><div class='row'><div class='quote'>Last trade: $$quote_1</div>";
echo "<div class='quote'>Date: $quote_2</div>";
echo "<div class='quote'>Time: $quote_3</div>";
echo "<div class='quote'>From Previous: $$quote_4</div></div>";
echo "<div class='row'><div class='quote'>Open: $$quote_5</div>";
echo "<div class='quote'>High: $$quote_6</div>";
echo "<div class='quote'>Low: $$quote_7</div>";
echo "<div class='quote'>Volume: $quote_8</div></div>";
}
?>
You have to more your output into the while loop to get access to each of the values in your table.
<?php
error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors", 1);
//begin
include "storescripts/connect_to_mysql.php";
$sql = mysql_query("SELECT * FROM stockpicks ORDER BY id LIMIT 100");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
// get all the product details
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$symbol = $row["symbol"];
if(empty($symbol)) {
echo nothing;
}
else {
$open = fopen("http://quote.yahoo.com/d/quotes.csv?s=$symbol&f=sl1d1t1c1ohgv&e=.csv", "r");
$quote = fread($open, 1000);
fclose($open);
$quote = str_replace("\"", "", $quote);
$quote = explode(",", $quote);
$quote_0 = ($quote[0]);
$quote_1 = ($quote[1]);
$quote_2 = ($quote[2]);
$quote_3 = ($quote[3]);
$quote_4 = ($quote[4]);
$quote_5 = ($quote[5]);
$quote_6 = ($quote[6]);
$quote_7 = ($quote[7]);
$quote_8 = ($quote[8]);
echo "<div class='symbol'><div class='quote'>Company: $quote_0</div></div>";
echo "<div class='leftofStocks'><div class='row'><div class='quote'>Last trade: $$quote_1</div>";
echo "<div class='quote'>Date: $quote_2</div>";
echo "<div class='quote'>Time: $quote_3</div>";
echo "<div class='quote'>From Previous: $$quote_4</div></div>";
echo "<div class='row'><div class='quote'>Open: $$quote_5</div>";
echo "<div class='quote'>High: $$quote_6</div>";
echo "<div class='quote'>Low: $$quote_7</div>";
echo "<div class='quote'>Volume: $quote_8</div></div>";
}
}
}
mysql_close();
//end
?>
you should start using the msqli functions instead of mysql sinc eit is deprecated.
if everything else is correct in your code the only change you need to do is in the while clause.
while ($row = mysql_fetch_assoc($sql)){
$id[]=$row['id'];
$symbol[] =$row['symbol'];
}

Categories