• 0

WML, PHP & MySQL


Question

Hi there,

I'm putting together a small wap site - basically a WML version of my weblog.

I have a page which displays the most recent entries, but can't get the individual entries to display on their own using a weblogs.wml#ViewEntry?id=10 sort of thing. If I hard code the MySQL query it works just fine and will return an individual entry. When I put in the '$id' instead of (say) 10, it stops working.

I made a quick script which does exactly what I want and works fine in PHP, but when I change the script to be the same in the WML file it just returns nothing. The page is all there, but where $row[title] should be there's nothing.

Any ideas? Is there something else I should be doing, it being WML?

Many thanks!

Link to comment
https://www.neowin.net/forum/topic/426447-wml-php-mysql/
Share on other sites

4 answers to this question

Recommended Posts

  • 0
  PRSBOY said:

could you show us the code?

I was putting the part of the code which showed an individual entry in the same wml file as the one which displayed the list, so when the link was used it wasn't reloading the page with the ID, just going down to the next card.

Seems to be working now, but here's the code anyway. :)

weblogs.wml

<?php
header("Content-type: text/vnd.wap.wml");
echo "<?xml version=\"1.0\"?>";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\""
. " \"http://www.wapforum.org/DTD/wml_1.1.xml\">?>

<wml>

<card id="Home" title="Mediantenne">
<p>
View weblogs
</p>

<p>
<a href="#All">Most recent (all)</a>
</p>


<p>
------------
<br />
&lt;a href="index.wml#Home">Home</a>opyright 2006&lt;br /&gt;
&lt;a href="index.wml#About">Aboutsite&lt;/a&gt;
&lt;/p&gt;
&lt;/card&gt;

	&lt;card id="All" title="Weblogs"&gt;
		&lt;p&gt;
		&lt;?php
	  // connect to mysql database
	   include("connect.php");
	  // select information from db
		$query = "select id, owner, title, date_format(added, '%e %b') as formatted_date from weblog_entries order by id desc limit 10";
		$result = @mysql_query($query);

		print "&lt;b&gt;Recent entries:&lt;/b&gt; &lt;br /&gt;";
	  // if information fitting the query is found,
	  // format and display it to the screen.
		if (mysql_num_rows($result) &gt; 0) :
			while ($row = mysql_fetch_array($result)) :
			print "&lt;a href=\"weblogs-ve.wml?id=$row[id]\"&gt;$row[title]&lt;/a&gt; &lt;br /&gt;$row[formatted_date] - $row[owner]&lt;br /&gt;&lt;br /&gt;";
			endwhile;
	  // if no information fitting the query is found,
	  // display relevant message.
		else:
			print "No current results.";
		endif;

		?&gt;
		&lt;/p&gt;
	&lt;/card&gt;

&lt;/wml&gt;

weblogs-ve.wml

&lt;?php
header("Content-type: text/vnd.wap.wml");
echo "&lt;?xml version=\"1.0\"?&gt;";
echo "&lt;!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\""
. " \"http://www.wapforum.org/DTD/wml_1.1.xml\">?&gt;

&lt;wml&gt;

	&lt;card id="ViewEntry" title="Weblogs"&gt;
		&lt;p&gt;
		&lt;?php

		function nl2p($str)
{
  return str_replace('&lt;p&gt;&lt;/p&gt;', '', '&lt;p&gt;' . preg_replace('#\n|\r#', '&lt;/p&gt;$0&lt;p&gt;', $str) . '&lt;/p&gt;');
}

	  // connect to mysql database
	   include("connect.php");
	  // select information from sports db



		$id = $_REQUEST['id'];

		$query = "select id, owner, title, entry, date_format(added, '%e %b') as formatted_date from weblog_entries WHERE id = '$id'";
		$result = @mysql_query($query);


	while($row=@mysql_fetch_array($result))
   {


	  //make the content

	  echo "&lt;b&gt;$row[title]&lt;/b&gt;&lt;br /&gt;$row[formatted_date] - $row[owner]&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;";
	  echo nl2p($row[entry]);


	  }


		?&gt;

&lt;p&gt;
------------
&lt;br /&gt;
&lt;a href="index.wml#Home">Home</a>opyright 2006&lt;br /&gt;
&lt;a href="index.wml#About">Aboutsite&lt;/a&gt;
&lt;/p&gt;


	&lt;/card&gt;

&lt;/wml&gt; 

Link to comment
https://www.neowin.net/forum/topic/426447-wml-php-mysql/#findComment-587128820
Share on other sites

  • 0

I wanted to find out more about WAP, and make it accessible to everyone with a WAP 1.0 phone. Not sure if I could have gone right ahead with PHP, but followed some tutorials then did the above.

There seems to be a big lack of info on WAP/WML, and some are saying it's a dead format. It works just fine on my Nokia 6600, so I'm happy with it at the moment. As there's more to go on the WAP version I'll probably have a rethink. :)

As more phones have XHTML that will probably be easier to do?

Link to comment
https://www.neowin.net/forum/topic/426447-wml-php-mysql/#findComment-587128850
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.