This topic is locked
[SOLVED]

 Issue with if/else statement.

4/22/2011 6:09:05 PM
PHPRunner General questions
S
santonivich author

Hello! I'm trying to write data to an XML file based on values given in a dropdown. I have the following code inserted in AFTER RECORD ADDED EVENT:
if ($values["category"] == "SOMETHING")

{

$chan_title = "TITLE";

$chan_desc = "DESC";

$chan_link = "http://www.xxx.com/"'>http://www.xxx.com/";;

$image_url = "https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=16875&image=1&table=forumtopics";;
$db_user = 'xxx';

$db_pass = 'xxx';

$db_host = 'localhost';

$db_database = 'xxx';

$db = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());

mysql_select_db($db_database);
$query = "SELECT FROM xxx where category='SOMETHING' ORDER BY entered DESC";

$result = mysql_query($query) or die(mysql_error());

if (mysql_num_rows($result) < 1) {

die("No records");

}
$items = '';

while ($row = mysql_fetch_assoc($result)) {

$item_title = $row["xxx"];

$item_link = $row["xxx"];

$item_desc = $row["xxx"];

$database_date = $row["xxx"];

$file = $row["xxx"];

$thedate = strftime("%a, %d %b %Y %T %Z", strtotime($database_date));
$items .= <<<ITEM

<item>

<title>$item_title</title>

<link>$item_link</link>

<description>$item_desc</description>

<pubDate>$thedate</pubDate>

<source url="http://www.xxx.com">xxx</source>'>http://www.xxx.com">xxx</source>;

<enclosure url="$file" type="audio/mpeg" />

</item>
ITEM;

}
$content = <<<CONTENT

<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0">

<channel>

<title>$chan_title</title>

<link>$chan_link</link>

<image>$image_url</image>

<description>$chan_desc</description>

<pubDate>$thedate</pubDate>

<image>

<title>$chan_title</title>

<url>$image_url</url>

<link>$chan_link</link>

</image>
$items

</channel>

</rss>
CONTENT;
header("Content-type: application/rss+xml");

print $content;
$myFile = "something.xml";

$fh = fopen($myFile, 'w') or die("can't open file");

fwrite($fh, $content);

fclose($fh);
}

else if

($values["category"] == "SOMETHING ELSE")

{

$chan_title = "xxx";

$chan_desc = "xxx";

$chan_link = "http://www.xxx.com/"'>http://www.xxx.com/";;

$image_url = "https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=16875&image=2&table=forumtopics";;
$db_user = 'xxx';

$db_pass = 'xxx';

$db_host = 'xxx';

$db_database = 'xxx';

$db = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());

mysql_select_db($db_database);
$query = "SELECT
FROM podcasts where category='SOMETHING ELSE' ORDER BY entered DESC";

$result = mysql_query($query) or die(mysql_error());

if (mysql_num_rows($result) < 1) {

die("No records");

}
$items = '';

while ($row = mysql_fetch_assoc($result)) {

$item_title = $row["podcast_name"];

$item_link = $row["file_name"];

$item_desc = $row["podcast_description"];

$database_date = $row["entered"];

$file = $row["file_name"];

$thedate = strftime("%a, %d %b %Y %T %Z", strtotime($database_date));
$items .= <<<ITEM

<item>

<title>$item_title</title>

<link>$item_link</link>

<description>$item_desc</description>

<pubDate>$thedate</pubDate>

<source url="http://www.xxx.com">xxx</source>'>http://www.xxx.com">xxx</source>;

<enclosure url="$file" type="audio/mpeg" />

</item>
ITEM;

}
$content = <<<CONTENT

<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0">

<channel>

<title>$chan_title</title>

<link>$chan_link</link>

<image>$image_url</image>

<description>$chan_desc</description>

<pubDate>$thedate</pubDate>

<image>

<title>$chan_title</title>

<url>$image_url</url>

<link>$chan_link</link>

</image>
$items

</channel>

</rss>
CONTENT;
header("Content-type: application/rss+xml");

print $content;
$myFile = "something else.xml";

$fh = fopen($myFile, 'w') or die("can't open file");

fwrite($fh, $content);

fclose($fh);
}
I can't seem to get this to work....and I am not getting an error's that I see. Do you notice anything I could be doing wrong....or is there an easier way to accomplish my goal?

S
santonivich author 4/23/2011

No ideas? I'm really at a loss....



Hello! I'm trying to write data to an XML file based on values given in a dropdown. I have the following code inserted in AFTER RECORD ADDED EVENT:
if ($values["category"] == "SOMETHING")

{

$chan_title = "TITLE";

$chan_desc = "DESC";

$chan_link = "http://www.xxx.com/"'>http://www.xxx.com/";;

$image_url = "https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=57837&image=1&table=forumreplies";;
$db_user = 'xxx';

$db_pass = 'xxx';

$db_host = 'localhost';

$db_database = 'xxx';

$db = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());

mysql_select_db($db_database);
$query = "SELECT FROM xxx where category='SOMETHING' ORDER BY entered DESC";

$result = mysql_query($query) or die(mysql_error());

if (mysql_num_rows($result) < 1) {

die("No records");

}
$items = '';

while ($row = mysql_fetch_assoc($result)) {

$item_title = $row["xxx"];

$item_link = $row["xxx"];

$item_desc = $row["xxx"];

$database_date = $row["xxx"];

$file = $row["xxx"];

$thedate = strftime("%a, %d %b %Y %T %Z", strtotime($database_date));
$items .= <<<ITEM

<item>

<title>$item_title</title>

<link>$item_link</link>

<description>$item_desc</description>

<pubDate>$thedate</pubDate>

<source url="http://www.xxx.com">xxx</source>'>http://www.xxx.com">xxx</source>;

<enclosure url="$file" type="audio/mpeg" />

</item>
ITEM;

}
$content = <<<CONTENT

<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0">

<channel>

<title>$chan_title</title>

<link>$chan_link</link>

<image>$image_url</image>

<description>$chan_desc</description>

<pubDate>$thedate</pubDate>

<image>

<title>$chan_title</title>

<url>$image_url</url>

<link>$chan_link</link>

</image>
$items

</channel>

</rss>
CONTENT;
header("Content-type: application/rss+xml");

print $content;
$myFile = "something.xml";

$fh = fopen($myFile, 'w') or die("can't open file");

fwrite($fh, $content);

fclose($fh);
}

else if

($values["category"] == "SOMETHING ELSE")

{

$chan_title = "xxx";

$chan_desc = "xxx";

$chan_link = "http://www.xxx.com/"'>http://www.xxx.com/";;

$image_url = "https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=57837&image=2&table=forumreplies";;
$db_user = 'xxx';

$db_pass = 'xxx';

$db_host = 'xxx';

$db_database = 'xxx';

$db = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());

mysql_select_db($db_database);
$query = "SELECT
FROM podcasts where category='SOMETHING ELSE' ORDER BY entered DESC";

$result = mysql_query($query) or die(mysql_error());

if (mysql_num_rows($result) < 1) {

die("No records");

}
$items = '';

while ($row = mysql_fetch_assoc($result)) {

$item_title = $row["podcast_name"];

$item_link = $row["file_name"];

$item_desc = $row["podcast_description"];

$database_date = $row["entered"];

$file = $row["file_name"];

$thedate = strftime("%a, %d %b %Y %T %Z", strtotime($database_date));
$items .= <<<ITEM

<item>

<title>$item_title</title>

<link>$item_link</link>

<description>$item_desc</description>

<pubDate>$thedate</pubDate>

<source url="http://www.xxx.com">xxx</source>'>http://www.xxx.com">xxx</source>;

<enclosure url="$file" type="audio/mpeg" />

</item>
ITEM;

}
$content = <<<CONTENT

<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0">

<channel>

<title>$chan_title</title>

<link>$chan_link</link>

<image>$image_url</image>

<description>$chan_desc</description>

<pubDate>$thedate</pubDate>

<image>

<title>$chan_title</title>

<url>$image_url</url>

<link>$chan_link</link>

</image>
$items

</channel>

</rss>
CONTENT;
header("Content-type: application/rss+xml");

print $content;
$myFile = "something else.xml";

$fh = fopen($myFile, 'w') or die("can't open file");

fwrite($fh, $content);

fclose($fh);
}
I can't seem to get this to work....and I am not getting an error's that I see. Do you notice anything I could be doing wrong....or is there an easier way to accomplish my goal?

Sergey Kornilov admin 4/23/2011

If you need help with coding post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL. 'Demo Account' button can be found on the last screen in the program. I don't think it possible to tell you what's wrong with this code simply looking at it.