473,662 Members | 2,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Rewrite the code using classes

18 New Member
Hi friends, I am populating a drop box from a table jos_qualificati ons. can anybody tell me how to populate a drop box using classes. something like
$db->setQuery( $query );

this is my code which i have written without using classes :::::::::::::
[php]
$result = mysql_query( "SELECT category FROM jos_qualificati ons" )
or die("SELECT Error: ".mysql_error() );
// start the select list
echo '<select name="category" id="category">' ;
echo '<OPTION value="" selected>Select </OPTION>';
// read each row field and build option list
while ($row = mysql_fetch_ass oc($result))
{
$category=$row['category'];
print "<option value='$categor y'>$category</option>";
}
// close the select list
print "</select>";
?>
[/php]

//plz help me out.
Mar 20 '08 #1
3 1356
ronverdonk
4,258 Recognized Expert Specialist
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Mar 20 '08 #2
nathj
938 Recognized Expert Contributor
Hi,

I have an object - called formObject that inturn contains my Data handling object. In my system there are only certain areas where a select box is created from a table.
[php]
function createInputSele ct($pnRetreival Type, $pnReturnType, $pcSelectID, $pnSelection, $plIsReadOnly, $pcExtra, $pcClass)
{
switch($pnRetre ivalType)
{
case 1: // get country codes
$lcSelectStr =
"SELECT
a.ID, a.countryName as description, a.isDefault
FROM countrycode a
ORDER BY a.countryName ASC";
break;
case 2: // get denomination list
$lcSelectStr =
"SELECT
a.ID, a.denomination as description, 0 as isDefault
FROM denomination a
ORDER BY a.denomination ASC";
break;
case 3: // get leader role list
$lcSelectStr =
"SELECT
a.ID, a.role as description, 0 as isDefault
FROM role a
ORDER BY a.role ASC";
}

// execute the select
$laResults = $this->loDataObject->queryGetData(f alse, $lcSelectStr);
$lcItemID = !empty($pcSelec tID)? $pcSelectID : "list" . $pnRetreivalTyp e ;
switch($pnRetur nType)
{
case 1: // write the results into a select input object
$lvReturn = "<select name=" . "'" . $lcItemID . "'" . "id=" . "'" . $lcItemID . "' " ;
if(!empty($pcEx tra))
{
$lvReturn .= $pcExtra . " " ;
}

if(!empty($pcCl ass))
{
$lvReturn .= "class='" . $pcClass ."' " ;
}

$lvReturn.= ">";

foreach($laResu lts as $lcDataLine)
{
$lvReturn .= "<option value=" . $lcDataLine['ID'] . " ";

if($pnSelection >= 0)
{
if($lcDataLine['ID'] == $pnSelection)
{
$lvReturn .= "selected='sele cted'";
}
}
else
{
if($lcDataLine['isDefault'])
{
$lvReturn .= "selected='sele cted'";
}
}
$lvReturn .= ">" . $lcDataLine['description'] ."</option>";
}
$lvReturn .= "</select>";
break;
case 2: // return the array from the query
$lvReturn = $laResults ;
}

return $lvReturn ;
} // end of createInputSele ct
[/php]

The parameters here control what happens, A standard call for me would look like:
[php]
$lcCountrySelec t=$loform->createInputSel ect(1,1,"cbo_co untry", 78, false, "", "")
[/php]

This give the return an ID and a name of 'cbo_country' and defaults to selecting United Kingdom.

I also have functions for generating select controls from ENUM fields and from static lists of data. If you want either of those let me know.

I have assumed you know how to instantiate an object and so on but if you need some help there give me a shout.

Cheers
nathj
Mar 20 '08 #3
Ramu528
18 New Member
thanks nathj

I got it. If any probs i will definitely shout for.

good luck

ramu
Mar 20 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1528
by: Link | last post by:
Hello!I am new to Python and I would like to rewrite the following code to python use to call by C program:// JPython code ======================================= import org.python.util.PythonInterpreter; import org.python.core.*; public class SimpleEmbedded { public static void main(String args) throws PyException {
1
1636
by: darrel | last post by:
We're using URL rewriting (Isapi Rewrite). Is there any way to grab the pre-rewritten URL or can you only grab the rewritten one? I'm assuming you can't (as that's sort of the point of URL rewriting), but thought I'd ask... -Darrel
188
7171
by: christopher diggins | last post by:
I have posted a C# critique at http://www.heron-language.com/c-sharp-critique.html. To summarize I bring up the following issues : - unsafe code - attributes - garbage collection - non-deterministic destructors - Objects can't exist on the stack - Type / Reference Types
7
1234
by: Stan Canepa | last post by:
I am looking for good documentation to help support rewriting a VB 6 app in Dot Net. I looking for things like VB 6 being unsupported in March 2008, general performance improvements, at what point will VB 6 just won't work on the newest version of Windows. How good is the ajax functionality in 2005? Can you make a rich UI web base without losing performance? Really anything you can think of that can be used as a bullet point for moving...
14
1812
by: Stan Canepa | last post by:
This post is mostly for discussion. Why rewrite in .NET? Just a general discussion not related to any specific details. I was just looking to see what reasons developers are looking to, to help decide whether they should rewrite their app in .NET. What are the trends being observed of Microsoft when it comes to .Net? How much longer will COM objects live on? How stable is the Framework?
5
3606
by: Lupus | last post by:
Hello everybody In apache I used a feature called a "Rewrite rule" inside a .htaccess file to process the URL : i.e. http://www/mypage.html =http://www/page.php?page=mypage Now I'd like to do a similar action on a IIS server with ASP (not ..net)... Can anyone tell me how you can do this ?
18
10078
chunk1978
by: chunk1978 | last post by:
hi everyone. i just started learning how to dynamically show/hide elements with a checkbox toggle. i would like to know if it's possible to delete/rewrite elements instead of simply show/hide them. the reason is because in the following code, i show/hide a file field by checkbox toggle... however, if a file field selects a file before it's hidden, the file selected for the file field will still remain, as you can see when you uncheck the...
3
1203
by: aag | last post by:
Hey there! I've got an URL rewrite issue that I'm wondering if the masters out there can help with :) I have a site that resides at (for example) foo.com - it's a full site with tons of pages that users would need to get access to. However, I'd like to have a special feature of that same ASP.NET application such that if a users goes to: bla.foo.com/name
1
3492
by: mazdotnet | last post by:
Hi all, I've installed the new Microsoft URL Rewrite Module for IIS 7.0 http://www.iis.net/downloads/default.aspx?tabid=34&i=1691&g=6 on both my laptop (Vista Home Premium) and my desktop (Vista Ultimate). I'm running my sites on IIS instead of the ASP.NET server. If I call my site using http://localhost in the browser, it works fine. However, as soon as I run it from within Visual Studio 2008 in
0
8435
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8857
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8547
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7368
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5655
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4181
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1754
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.