SunQuest
           WAP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreWAP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old April 23rd, 2006, 03:45 PM
TheBoosht TheBoosht is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 9 TheBoosht User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 57 m 40 sec
Reputation Power: 0
Need Help With HTML conversion

Hi there guys, im new to the boards. Theres some really good info here thanks for having a forum on WAP, theres still life in it yet! Anyways im having trouble converting a HTML/PHP script 2 wml. Im creating a tourist information site and also doing a wap version.The php scripts works perfectly im having trouble with the code syntax. Im new to WML so speak in english please. I changed a few of the printf statements 2 echo. Is there anywhere i can learn about creating an update form for my wap site so a user can add details into my database e.g there house or retaurant?

PHP Code:
accomadation.php
<wml>
<
card id="Accomadation" title="Accomadation">
<
p align="left">
<?
php
// format and output date 
$the_date date("M d Y"); 

echo 
$the_date;
?>
<br>
<p>Please Select</P> 
<p>From the following Accomadation options.
</p>

<form action="search1result.php" method="POST">
<?php

require($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");
$connection mysql_connect($db_host$db_user$db_password) or die("error connecting");
mysql_select_db($db_name$connection);


?>

<select name = 'prem_type'>
<option value ="0">Select Premises Type</option>
<?
$query 
"SELECT * FROM premises_type";
$result mysql_query($query$connection);
for (
$i 0$i mysql_num_rows($result); $i++)
{
$prem_type mysql_result($result$i,"prem_type");
$prem_type_id1 mysql_result($result$i,"prem_type_id");
if (
$prem_type_id == $prem_type_id1)
{
echo(
"<option selected value =%s>%s</option>",$prem_type_id,$prem_type);
}
else echo(
"<option value =%s>%s</option>",$prem_type_id1,$prem_type);
}
?>
</select><br>

</select>

<select name = 'town'>
<option value ="0">Select Town</option>
<?
$query 
"SELECT * FROM town";
$result mysql_query($query$connection);
for (
$i 0$i mysql_num_rows($result); $i++)
{
$town_name mysql_result($result$i"town_name");
$town_id mysql_result($result$i"town_id");
echo(
"<option value =%s>%s</option>",$town_id,$town_name);
}
?>


</select>
<input type="submit" value="Go!">
</form>
</p>
<br>
<p align="center">
<a href="home.php">Back</a>
</p>

</card>

</wml> 



PHP Code:
search1result.php
<wml>
<?
php

require($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");
$connection mysql_connect($db_host$db_user$db_password) or die("error connecting");
mysql_select_db($db_name$connection);

if(isset(
$_POST['prem_type'])&&isset($_POST['town']))
{
echo(
"Here are your results:<br>
<p><br>
"
);

$prem_type $_POST['prem_type'];
$town $_POST['town'];

$query"SELECT * FROM premises_details WHERE prem_type_id='$prem_type' AND town_id='$town'";
$result mysql_query($query$connection);
$num mysql_num_rows($result);
if(
$num 0){
for (
$i 0$i mysql_num_rows($result); $i++)
{
$prem_name mysql_result($result$i,"prem_name");
$address mysql_result($result$i,"address");
$county mysql_result($result$i,"county");
$contact_number mysql_result($result$i,"contact_number");
$email_address mysql_result($result$i,"email_address");


echo(
"$prem_name<br>
"
);
echo(
"$address<br>
"
);
echo(
" $county<br>
"
);
echo(
"$contact_number<br>
"
);
echo(
" $email_address<br>
"
);
echo(
"<br>
"
);
}
}
else{
echo(
"Sorry No Results to display");
}

?>
</card>
</wml> 

Last edited by jabba_29 : April 23rd, 2006 at 08:31 PM. Reason: Put code into highlight tags

Reply With Quote
  #2  
Old April 23rd, 2006, 08:21 PM
jabba_29's Avatar
jabba_29 jabba_29 is offline
Back in HEL
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Feb 2002
Location: Finland
Posts: 8,670 jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)  Folding Points: 57777 Folding Title: Beginner FolderFolding Points: 57777 Folding Title: Beginner FolderFolding Points: 57777 Folding Title: Beginner Folder
Time spent in forums: 3 Months 3 Weeks 4 Days 6 h 4 m 26 sec
Reputation Power: 1618
Send a message via ICQ to jabba_29 Send a message via AIM to jabba_29 Send a message via MSN to jabba_29 Send a message via Yahoo to jabba_29 Send a message via Google Talk to jabba_29 Send a message via Skype to jabba_29
Facebook
Hi, Welcome to Dev Shed.

A few things to note. WML is based on xml, so the syntax / mark-up needs to be absolutely correct or is just won't display on a mobile device. This means that tags need to be in lower case and properly nested. So, this is wrong for example.
PHP Code:
 ?>
<br>
<p>Please Select</P> 
I too would never use PHP short-tags as the PHP parser may confuse them with the xml tags
PHP Code:
<?
$query 
// etc
// change to 
<?php
$query 
// etc


Take a look at the wap resources sticky, there are a couple of excellent sites to learn the mark-up required. Forms in wml are a bit different than in html. Build your form, and make postfields accordingly.

Good luck.
__________________
Cheers,

Jamie


# skiFFie | Home of the 'accessibility module' for Drupal
# Jamie Burns [me] Accessibility Module [drupal]
# guidelines | search | wap resources | not getting help | fold to cure

# Any form of employment is strictly prohibited ......


__________________

Let the might of your compassion arise to bring a quick end
to the flowing stream of the blood and tears .....
Please hear my anguished words of truth.

__________________

Reply With Quote
  #3  
Old April 24th, 2006, 05:59 AM
TheBoosht TheBoosht is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 9 TheBoosht User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 57 m 40 sec
Reputation Power: 0
Ok thanks for that. Im starting to build my form from scratch again. so far ive used all the basics. Is my form action right though? Now to query my database. When writing php SQL commands in is there many changes to be made? for example i want to insert the HTML PHP SQL query into my wml script so it brings a dropdown list off all towns in the area...

sql query for towns

php Code:
Original - php Code
  1. <?php
  2.       $query = "SELECT * FROM town";
  3.       $result = mysql_query($query, $connection);
  4.       for ($i = 0; $i < mysql_num_rows($result); $i++)
  5.       {
  6.           $town_name = mysql_result($result, $i, "town_name");
  7.           $town_id = mysql_result($result, $i, "town_id");
  8.           echo("<option value =%s>%s</option>",$town_id,$town_name);
  9.       }
  10.       ?>
  11.  
  12.  
  13. <wml>
  14. <card id="Accomadation" title="Accomadation">
  15. <p align="left">
  16.  
  17. <br>
  18. <b>Please Select</b>
  19. <b>From the following Accomadation options.</b>
  20.  <go method="get" href="search1result.php">
  21. </p>
  22.  
  23. <select name = 'prem_type'>
  24. <option value ="0">Select Premises Type</option>
  25.  
  26.         </select><br>
  27.  
  28. </select>
  29.  
  30. <select name = 'town'>
  31. <option value ="0">Select Town</option>
  32. </select>
  33.        </go>
  34.         Submit Data
  35.       </anchor>
  36. </form>
  37. </p>
  38. <br>
  39. <p align="center">
  40. <a href="home.php">Back</a>
  41. </p>
  42.  
  43. </card>
  44.  
  45. </wml>


Mod comment: Please use the BBcode tags provided,
PHP Code:
 PHP 
or
whatever Code:
Original - whatever Code
    highlight
- it makes coding so much easier to read.

Last edited by jabba_29 : April 24th, 2006 at 08:15 AM. Reason: Code tags again

Reply With Quote
  #4  
Old April 24th, 2006, 07:30 AM
jabba_29's Avatar
jabba_29 jabba_29 is offline
Back in HEL
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Feb 2002
Location: Finland
Posts: 8,670 jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)  Folding Points: 57777 Folding Title: Beginner FolderFolding Points: 57777 Folding Title: Beginner FolderFolding Points: 57777 Folding Title: Beginner Folder
Time spent in forums: 3 Months 3 Weeks 4 Days 6 h 4 m 26 sec
Reputation Power: 1618
Send a message via ICQ to jabba_29 Send a message via AIM to jabba_29 Send a message via MSN to jabba_29 Send a message via Yahoo to jabba_29 Send a message via Google Talk to jabba_29 Send a message via Skype to jabba_29
Facebook
Quote:
Is my form action right though?
Well you are using get now. But did you actually read any of the links provided, you have no postfields - this is essential to pass data in a form.

You also have no DTD and are not, visibly at least forcing the content-type.

Here is a little demo, maybe help you a little.
PHP Code:
wml.php
<?php
header
('Content-Type: text/vnd.wap.wml, true');
echo 
'<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" 
"http://www.wapforum.org/DTD/wml_1.1.xml">'
;
?>

<wml>
<card id="Accomodation" title="Accomodation">
<p align="left">

<?php
if (isset($_POST['prem_type'])):
print_r($_POST);
else:
?>

<b>Please Select</b><br />
<b>From the following Accomodation options.</b><br />

    <select name="prem_type">
    <option value="0">Select Premises Type</option>
    <option value="1">House</option>
    <option value="2">Flat</option>
    </select>

    <select name ="town">
    <option value="0">Select Town</option>
    <option value="1">Edinburgh</option>
    <option value="2">Glasgow</option>
    </select>



<do type="accept">
  <go href="wml.php" method="post">
    <postfield name="town" value="$(town)"/>    
      <postfield name="prem_type" value="$(prem_type)"/>    
  </go>
</do>
</p>

<p align="center">
<a href="wml.php">Back</a>
<?php
endif;
?>
</p>
</card>
</wml>

Reply With Quote
  #5  
Old April 24th, 2006, 08:55 AM
TheBoosht TheBoosht is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 9 TheBoosht User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 57 m 40 sec
Reputation Power: 0
Hi again, thanks for the help its very useful.I apologise for being a newbie,i havent developed WML before. I tried inputting the postfield tags earlier but it wasnt displaying properly. I was told that i didnt need the content header as ive some othe wml pages using php tags which works fine without them e.g echo time etc. The options are now in place and all names are apperaing correcty. I would prefer if it was displaying in a dropdown list as opposed to a long list on the screen.. There is no submit button apperaing under the option table so it wont display results?

Code:
accomadation.php

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


<wml>
<card id="Accomadation" title="Accomadation">
<p align="left">

<?php
      // connect to mysql database
      require($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");
  $connection = mysql_connect($db_host, $db_user, $db_password) or die("error connecting");
  mysql_select_db($db_name, $connection);
  ?>

<?php 
if (isset($_POST['prem_type'])): 
print_r($_POST); 
else: 
?> 



<br>
<b>Please Select</b>
<b>From the following Accomadation options.</b>

</p>

<select name = 'prem_type'>
<option value ="0">Select Premises Type</option>
<?
      $query = "SELECT * FROM premises_type";
      $result = mysql_query($query, $connection);
      for ($i = 0; $i < mysql_num_rows($result); $i++)
      {
          $prem_type = mysql_result($result, $i,"prem_type");
          $prem_type_id1 = mysql_result($result, $i,"prem_type_id");
          if ($prem_type_id == $prem_type_id1)
          {
           printf("\n<option selected value =%s>%s</option>",$prem_type_id,$prem_type);
          }
          else   printf("\n<option value =%s>%s</option>",$prem_type_id1,$prem_type); 
      }
      ?>
        </select><br>

</select>


<select name = 'town'>
<option value ="0">Select Town</option>
   <?
      $query = "SELECT * FROM town";
      $result = mysql_query($query, $connection);
      for ($i = 0; $i < mysql_num_rows($result); $i++)
      {
          $town_name = mysql_result($result, $i, "town_name");
          $town_id = mysql_result($result, $i, "town_id");
          printf("\n<option value =%s>%s</option>",$town_id,$town_name);
      }
      ?>
</select></select><br>

<do type="accept"> 
  <go href="result.php" method="post"> 
    <postfield name="town" value="$(town)"/>     
      <postfield name="prem_type" value="$(prem_type)"/>     
  </go> 
</do> 
</p> 

<p align="center"> 
<a href="home.php">Back</a> 
<?php 
endif; 
?> 
</p> 
</card> 
</wml>

Reply With Quote
  #6  
Old April 24th, 2006, 09:04 AM
TheBoosht TheBoosht is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 9 TheBoosht User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 57 m 40 sec
Reputation Power: 0
I have results now displaying on the screen. thanks for all your help

Reply With Quote
  #7  
Old April 24th, 2006, 09:24 AM
jabba_29's Avatar
jabba_29 jabba_29 is offline
Back in HEL
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Feb 2002
Location: Finland
Posts: 8,670 jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)  Folding Points: 57777 Folding Title: Beginner FolderFolding Points: 57777 Folding Title: Beginner FolderFolding Points: 57777 Folding Title: Beginner Folder
Time spent in forums: 3 Months 3 Weeks 4 Days 6 h 4 m 26 sec
Reputation Power: 1618
Send a message via ICQ to jabba_29 Send a message via AIM to jabba_29 Send a message via MSN to jabba_29 Send a message via Yahoo to jabba_29 Send a message via Google Talk to jabba_29 Send a message via Skype to jabba_29
Facebook
What are you viewing this in? On a phone or in a web browser?

Not gone over your code completely, but <br> must be <br /> or <br/>. Also,
PHP Code:
snippet
<?php
           printf
("\n<option selected value =%s>%s</option>",$prem_type_id,$prem_type);
// should be
           
printf("\n<option selected=\"selected\" value =\"%s\">%s</option>",$prem_type_id,$prem_type);
?>
and you have closed non-existent <select>'s too.

This may or may not help you, but I am in a good mood today
php Code:
Original - php Code