RE: [PHP] array help please
> $mysql query1 > result > array[cityid][cityname] > > mysql query2 > result > array[cityid][cityname] > > now what i want to do is kick out any doubles in my array > and resort them alphebetically by cityname ?! It's difficult to answer this question without knowing more about the context and the way you have your database laid out. In any event, sorting stuff and getting removing duplicates is probably better achieved in your mysql query than in php. Something like this would get you close (you'll have to figure it out for your database as you didn't give much to go on)... SELECT cityid, DISTINCE(cityname) FROM my_table WHERE some = 'condition' ORDER BY cityname Basically, use DISTINCT() to remove duplicates and use ORDER BY to set the display order. CYA, Dave -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array help please
John, et al -- ...and then John Fishworld said... % % can someone give me a bit of help / walthrough the following for me ! Let's see if I can help. % this first bits is okay % $mysql query1 % result % array[cityid][cityname] % % mysql query2 % result % array[cityid][cityname] Are CityIDs unique, like US-GA-ATL and CN-QC-MON or 214365 and 214387, or is duplication possible? If the IDs are unique then adding duplicates won't cause duplicate entries. % % now what i want to do is kick out any doubles in my array and resort them % alphebetically by cityname ?! Check out array_merge and array_multisort to put the two together and sort on the second key, respectively. % % % help ! HTH & HAND :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, "Science and Health" http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! msg91646/pgp0.pgp Description: PGP signature
[PHP] array help please
can someone give me a bit of help / walthrough the following for me ! this first bits is okay $mysql query1 result array[cityid][cityname] mysql query2 result array[cityid][cityname] now what i want to do is kick out any doubles in my array and resort them alphebetically by cityname ?! help ! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Array HELP PLEASE
try changing these lines: echo ""; for ($i = 6; $i <= 25; $i++) { echo "".stripslashes($models[$i]).""; } echo ""; to: echo ""; for ($i = 6; $i <= 25; $i++) { echo stripslashes($models[$i]).""; } echo ""; Martin T -Original Message- From: René Fournier [mailto:[EMAIL PROTECTED]] Sent: Friday, November 09, 2001 10:06 AM To: Php-General Subject: RE: [PHP] Array HELP PLEASE Or maybe not. :-) Although I got both rows displaying, they're actually two long to fit comfortably (w/o horizontally scrolling). So... I'd like to flip the axis of the table, so my header row runs vertically. But with the vagaries of html tables, I'm kinda stumped as to how to run the do/while+for loop. This is what I've got now (more or less): fld1fld2fld3 big red house little bluedog longyellow string With this code: === // MODELS A echo ""; echo ""; for ($i = 6; $i <= 25; $i++) { echo "".stripslashes($modelsheader[$i]).""; } echo ""; do { echo ""; for ($i = 6; $i <= 25; $i++) { echo "".stripslashes($models[$i]).""; } echo ""; } while ($models = mysql_fetch_array($result)); echo ""; = This is what I WOULD LIKE to have: fld1big little long fld2red blueyellow fld3house dog string == I can't figure how I would display element 1 of $modelsheader and every first element of $models, then increment and loop... That is, I would like to be able to refer to $models such that $models[0][0] referred to the first element of the first row and, say, $models[1][0] referred to the first element of the second row, and so on. > -Original Message- > From: René Fournier [mailto:[EMAIL PROTECTED]] > Sent: Thursday, November 08, 2001 3:39 PM > To: Php-General > Subject: RE: [PHP] Array HELP PLEASE > > > Oops, guess I posted too soon. Just figured out the problem myself (use a > do/while...). Thanks anyways. > > > -Original Message- > > From: René Fournier [mailto:[EMAIL PROTECTED]] > > Sent: Thursday, November 08, 2001 3:25 PM > > To: Php-General > > Subject: [PHP] Array HELP PLEASE > > > > > > (Before you write RTFM, please know that I have checked www.php.net, > > zend.com, phpbuilder.com, et all, and--in the eternal words of > > Bono--I still > > haven't found what I'm looking.) > > > > The situation: I extract an array from a MySQL table. Code: > > > > $models = mysql_fetch_array(mysql_query("SELECT * FROM models WHERE > > lang='$lang' AND key1='data' AND key2='$series'",$db)); > > > > Based on the above criteria, there should be two rows in > $modelsrow, with > > each row containing about twenty elements. (A two-dimensional array, > > right?) All I want to do is display the contents of $models. With the > > following... > > > > for ($i = 1; $i <= 20; $i++) { > > echo $models[$i].""; > > } > > > > ...I get just one row. How can I also display the other row? > I've tried > > variations of $models[1][2], but I just can't get right syntax. > (Help is > > much appreciated. Thanks.) > > > > If you know of a good tutorial on multidimension arrays + mySQL, > > that would > > be nice too. > > > > ...Rene > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Array HELP PLEASE
Or maybe not. :-) Although I got both rows displaying, they're actually two long to fit comfortably (w/o horizontally scrolling). So... I'd like to flip the axis of the table, so my header row runs vertically. But with the vagaries of html tables, I'm kinda stumped as to how to run the do/while+for loop. This is what I've got now (more or less): fld1fld2fld3 big red house little bluedog longyellow string With this code: === // MODELS A echo ""; echo ""; for ($i = 6; $i <= 25; $i++) { echo "".stripslashes($modelsheader[$i]).""; } echo ""; do { echo ""; for ($i = 6; $i <= 25; $i++) { echo "".stripslashes($models[$i]).""; } echo ""; } while ($models = mysql_fetch_array($result)); echo ""; = This is what I WOULD LIKE to have: fld1big little long fld2red blueyellow fld3house dog string == I can't figure how I would display element 1 of $modelsheader and every first element of $models, then increment and loop... That is, I would like to be able to refer to $models such that $models[0][0] referred to the first element of the first row and, say, $models[1][0] referred to the first element of the second row, and so on. > -Original Message----- > From: René Fournier [mailto:[EMAIL PROTECTED]] > Sent: Thursday, November 08, 2001 3:39 PM > To: Php-General > Subject: RE: [PHP] Array HELP PLEASE > > > Oops, guess I posted too soon. Just figured out the problem myself (use a > do/while...). Thanks anyways. > > > -----Original Message- > > From: René Fournier [mailto:[EMAIL PROTECTED]] > > Sent: Thursday, November 08, 2001 3:25 PM > > To: Php-General > > Subject: [PHP] Array HELP PLEASE > > > > > > (Before you write RTFM, please know that I have checked www.php.net, > > zend.com, phpbuilder.com, et all, and--in the eternal words of > > Bono--I still > > haven't found what I'm looking.) > > > > The situation: I extract an array from a MySQL table. Code: > > > > $models = mysql_fetch_array(mysql_query("SELECT * FROM models WHERE > > lang='$lang' AND key1='data' AND key2='$series'",$db)); > > > > Based on the above criteria, there should be two rows in > $modelsrow, with > > each row containing about twenty elements. (A two-dimensional array, > > right?) All I want to do is display the contents of $models. With the > > following... > > > > for ($i = 1; $i <= 20; $i++) { > > echo $models[$i].""; > > } > > > > ...I get just one row. How can I also display the other row? > I've tried > > variations of $models[1][2], but I just can't get right syntax. > (Help is > > much appreciated. Thanks.) > > > > If you know of a good tutorial on multidimension arrays + mySQL, > > that would > > be nice too. > > > > ...Rene > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Array HELP PLEASE
read this page a little closer! http://www.php.net/manual/en/function.mysql-fetch-array.php the mysql_fetch_array(); does not pull all the results in one big array. it IS only a single row of data. try this out, it should do what you are looking to do. $results = mysql_query("SELECT * FROM models WHERE lang='$lang' AND key1='data' AND key2='$series'",$db); while ($models = mysql_fetch_array($results)) { echo $models .""; } Jim - Original Message - From: "René Fournier" <[EMAIL PROTECTED]> To: "Php-General" <[EMAIL PROTECTED]> Sent: Thursday, November 08, 2001 2:25 PM Subject: [PHP] Array HELP PLEASE > (Before you write RTFM, please know that I have checked www.php.net, > zend.com, phpbuilder.com, et all, and--in the eternal words of Bono--I still > haven't found what I'm looking.) > > The situation: I extract an array from a MySQL table. Code: > > $models = mysql_fetch_array(mysql_query("SELECT * FROM models WHERE > lang='$lang' AND key1='data' AND key2='$series'",$db)); > > Based on the above criteria, there should be two rows in $modelsrow, with > each row containing about twenty elements. (A two-dimensional array, > right?) All I want to do is display the contents of $models. With the > following... > > for ($i = 1; $i <= 20; $i++) { > echo $models[$i].""; > } > > ...I get just one row. How can I also display the other row? I've tried > variations of $models[1][2], but I just can't get right syntax. (Help is > much appreciated. Thanks.) > > If you know of a good tutorial on multidimension arrays + mySQL, that would > be nice too. > > ...Rene > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Array HELP PLEASE
Oops, guess I posted too soon. Just figured out the problem myself (use a do/while...). Thanks anyways. > -Original Message- > From: René Fournier [mailto:[EMAIL PROTECTED]] > Sent: Thursday, November 08, 2001 3:25 PM > To: Php-General > Subject: [PHP] Array HELP PLEASE > > > (Before you write RTFM, please know that I have checked www.php.net, > zend.com, phpbuilder.com, et all, and--in the eternal words of > Bono--I still > haven't found what I'm looking.) > > The situation: I extract an array from a MySQL table. Code: > > $models = mysql_fetch_array(mysql_query("SELECT * FROM models WHERE > lang='$lang' AND key1='data' AND key2='$series'",$db)); > > Based on the above criteria, there should be two rows in $modelsrow, with > each row containing about twenty elements. (A two-dimensional array, > right?) All I want to do is display the contents of $models. With the > following... > > for ($i = 1; $i <= 20; $i++) { > echo $models[$i].""; > } > > ...I get just one row. How can I also display the other row? I've tried > variations of $models[1][2], but I just can't get right syntax. (Help is > much appreciated. Thanks.) > > If you know of a good tutorial on multidimension arrays + mySQL, > that would > be nice too. > > ...Rene > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Array HELP PLEASE
(Before you write RTFM, please know that I have checked www.php.net, zend.com, phpbuilder.com, et all, and--in the eternal words of Bono--I still haven't found what I'm looking.) The situation: I extract an array from a MySQL table. Code: $models = mysql_fetch_array(mysql_query("SELECT * FROM models WHERE lang='$lang' AND key1='data' AND key2='$series'",$db)); Based on the above criteria, there should be two rows in $modelsrow, with each row containing about twenty elements. (A two-dimensional array, right?) All I want to do is display the contents of $models. With the following... for ($i = 1; $i <= 20; $i++) { echo $models[$i].""; } ...I get just one row. How can I also display the other row? I've tried variations of $models[1][2], but I just can't get right syntax. (Help is much appreciated. Thanks.) If you know of a good tutorial on multidimension arrays + mySQL, that would be nice too. ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Array help please
Thanks Peter "Jason Stechschulte" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > On Fri, May 04, 2001 at 01:19:57PM +0100, peter.beal wrote: > > I'm trying to debug some software that I downloaded from the web. > > It seems to work fine most of the time however it occasionally crashed with > > database errors. > > When I look at the code it has a lot of array references that i don't > > understand > > e.g. $Session[clientID] > > most references at are of the form $arrayname["item"] or $arrayname[$item] > > as I would expect. > > is the example correct code? if so what does it mean? > > It either does the same thing as $Sessin["clientID"] The quotes are > optional but recommended, because clientID could be defined as a > constant and that could give unexpected results. > > -- > Jason Stechschulte > [EMAIL PROTECTED] > -- > : How would you disambiguate these situations? > > By shooting the person who did the latter. > -- Larry Wall in <[EMAIL PROTECTED]> > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Array help please
On Fri, May 04, 2001 at 01:19:57PM +0100, peter.beal wrote: > I'm trying to debug some software that I downloaded from the web. > It seems to work fine most of the time however it occasionally crashed with > database errors. > When I look at the code it has a lot of array references that i don't > understand > e.g. $Session[clientID] > most references at are of the form $arrayname["item"] or $arrayname[$item] > as I would expect. > is the example correct code? if so what does it mean? It either does the same thing as $Sessin["clientID"] The quotes are optional but recommended, because clientID could be defined as a constant and that could give unexpected results. -- Jason Stechschulte [EMAIL PROTECTED] -- : How would you disambiguate these situations? By shooting the person who did the latter. -- Larry Wall in <[EMAIL PROTECTED]> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Array help please
I'm trying to debug some software that I downloaded from the web. It seems to work fine most of the time however it occasionally crashed with database errors. When I look at the code it has a lot of array references that i don't understand e.g. $Session[clientID] most references at are of the form $arrayname["item"] or $arrayname[$item] as I would expect. is the example correct code? if so what does it mean? Thanks Peter -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]