PHP array information.

From: Date: Mon, 09 Jul 2001 16:39:04 +0000
Subject: PHP array information.
Groups: php.general 
Request: Send a blank email to php-general+get-56965@lists.php.net to get a copy of this message
Hello: My apologies if this has been covered before, or if i have missed it on the php manual web pages. I am looking for some information on how to do a perl like array with a *sql call in PHP. Here is what I want to do: table: problem_class _rid (tinyint) description (mediumtext) Sample data: _rid description 1 open 2 closed 3 testing 10 S 11 M 12 L 13 XL 20 Black 21 Red 22 Green 23 Blue In perl this might be accomplished by doing this: (Note some pseudo code is used here. Assume mysql as database but could be others like Oracle.) $query = "SELECT _rid,description FROM problem_class"; $q_pointer = sql_query($query); @problem_class = sql_associate_array_get($q_pointer); print "<select name=\"status\">\n"; for ($i = 0; $i < 10 ; ++$i) { if ( $problem_class[$i] ne "") { print " <option value=\"$i\"> $problem_class[$i]\n"; } } print "</select>\n"; print "<select name=\"size\">\n"; for ($i = 10; $i < 20 ; ++$i) { if ( $problem_class[$i] ne "") { print " <option value=\"$i\"> $problem_class[$i]\n"; } } print "</select>\n"; print "<select name=\"color\">\n"; for ($i = 20; $i < 30 ; ++$i) { if ( $problem_class[$i] ne "") { print " <option value=\"$i\"> $problem_class[$i]\n"; } } print "</select>\n"; This produces something very close to this: <select name="status"> <option value="1"> open <option value="2"> closed <option value="3"> testing </select> <select name="size"> <option value="10"> S <option value="11"> M <option value="12"> L <option value="13"> XL </select> <select name="color"> <option value="20"> Black <option value="21"> Red <option value="22"> Green <option value="23"> Blue </select> If I could use something like this, it would allow me to produce different 'for' statements for each select drop down I wanted to create. One table to maintain, and change encase politics force me to change some of definitions with out having to do a massive sql update. This works as long as the problem_class table is rather short (ie less than 1,000 records). I know I am missing something 'obvious' in this. Your help is appreciated. Thank you. -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Chris Oxenreider | oxenreid@state.net | http://www.state.net/~oxenreid | MicroSoft Windows 2000: The De facto sub standard. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

« previous php.general (#56965) next »