Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 2nd, 2003, 02:39 PM
Authorized User
 
Join Date: Dec 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default PHP and ASP 'Dictionary Object'

Hello,

I'd like to know if there is a PHP equivalent of the ASP 'Dictionary Object'

Could someone help me with that?

Regards

HammR
 
Old December 2nd, 2003, 02:48 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dictionaries in ASP are (iirc) just regular PHP arrays -- that is, a container which provides a mapping between a key and a value. In PHP, arrays can have any number of keys of either string or numeric types.

What exactly are you trying to do? If you post a small ASP code example, I can probably give you the PHP equivalent. That should be good enough for you to start playing with.


Take care,

Nik
http://www.bigaction.org/
 
Old December 6th, 2003, 10:06 AM
Authorized User
 
Join Date: Dec 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I've used the dictionary object to get data from the database and use this in the pages. this example is used when i want to be able to change a color of a menu.

In ASP:

<% Set objRS = Ccart.Execute("SELECT * FROM Colors")
dim dictColor
set dictColor = CreateObject("Scripting.Dictionary")
While not objRS.EOF
dictColor.Add ""&objRS("ColorID")&"", ""&objRS("Color")&""
objRS.Movenext
Wend
End if
%>

In PHP:

$query_Colorset = "SELECT * FROM colors order by ColorID";
$Colorset = mysql_query($query_Colorset, $ccart) or die(mysql_error());
$row_Colorset = mysql_fetch_assoc($Colorset);
$totalRows_Colorset = mysql_num_rows($Colorset);

do {

$DictColor[$row_Colorset['ColorID'];] = $row_Colorset['Color'];
}
while ($row_Colorset = mysql_fetch_assoc($Colorset));

---

somethings wrong with the line
$DictColor[$row_Colorset['ColorID'];] = $row_Colorset['Color'];

can't figure out what

Regards

HammR
 
Old December 6th, 2003, 10:18 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

It might be the first semicolon?
-just a thought...

 
Old December 6th, 2003, 10:37 AM
Authorized User
 
Join Date: Dec 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

YES! that did the job.

Thanks

 
Old December 6th, 2003, 11:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes. In PHP, statements are separated by semicolons, so that stray ; in the middle of your statement terminated it abruptly, when the PHP parser was expecting a closing square bracket (]) or perhaps a concatenation operation (.)

I'll bet that you got a parse error saying something to that effect.

Still, I'm glad to hear it's working!


Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use context object in PHP zerone01 PHP How-To 0 February 26th, 2007 09:45 AM
using dictionary object rajiv_software Classic ASP Basics 4 June 21st, 2005 02:53 PM
dictionary object with session scope lcsgeek Classic ASP Basics 1 May 3rd, 2005 09:48 AM
Exception Error using Dictionary Object andersoni Classic ASP Basics 2 July 24th, 2004 12:58 PM
sessions and the dictionary object lcsgeek Classic ASP Professional 1 January 27th, 2004 06:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.