Jump to content


Photo

explode - arrays


  • Please log in to reply
4 replies to this topic

#1 bizzo

bizzo
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 03 April 2006 - 06:30 AM

Hi,
I have a database field which is taking text which is delimited by a |

The data is going into the field from a multiple selection list. Now I need a way of reporting on the entered data.

I was trying to use a do while loop to append data to the array which was created by the explode function, but as I found out the array is getting written over each time the loop is ran. At the moment my code reads
do {
$arrayselect = explode("|", $row_infowouldlikebeincluded['infowouldlikebeincluded']);
} while ($row_infowouldlikebeincluded = mysql_fetch_assoc($infowouldlikebeincluded));

What I would like to happen is I need to count the number of times an individual row item occurs in the column. This item may be in a row with a delimited string e.g. Info|General Use or it may not be e.g. Info

I'm not sure how to go about this, any help is appreciated

Thanks
biz

#2 Desdinova

Desdinova
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 03 April 2006 - 07:34 AM

I'm not sure what it is you want exactly, and I haven't worked with do/while loops.

What you could try, is to change $arrayselect =, to $arrayselect[] =

this way you'd create an array inside an array, not overwriting the data you had.

#3 bizzo

bizzo
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 03 April 2006 - 11:45 PM

[!--quoteo(post=361133:date=Apr 3 2006, 05:34 PM:name=Desdinova)--][div class=\'quotetop\']QUOTE(Desdinova @ Apr 3 2006, 05:34 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I'm not sure what it is you want exactly, and I haven't worked with do/while loops.

What you could try, is to change $arrayselect =, to $arrayselect[] =

this way you'd create an array inside an array, not overwriting the data you had.
[/quote]

Hi Desdinova,
Thanks for your reply.
When I change the array to $arrayselect[] and echo $arrayselect[$i] i get an output of "Array"

What i would like to happen if each time the loop runs the value of the explode be appended onto the array.

Thanks for your assistance

biz

#4 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 04 April 2006 - 12:06 AM

If I understand what you are trying to achieve try teh following...
<?php
$arrsel = array();

while ($row_infowouldlikebeincluded = mysql_fetch_assoc($infowouldlikebeincluded)) {
 $temp = explode("|", $row_infowouldlikebeincluded['infowouldlikebeincluded']);
 foreach ($temp as $value) {
  arraypush($arrsel,$value);
 }
}
?>

use print_r($arrsel); to check the results.
follow me on twitter @PHPsycho

#5 bizzo

bizzo
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 04 April 2006 - 01:22 AM

[!--quoteo(post=361408:date=Apr 4 2006, 10:06 AM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ Apr 4 2006, 10:06 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
If I understand what you are trying to achieve try teh following...
<?php
$arrsel = array();

while ($row_infowouldlikebeincluded = mysql_fetch_assoc($infowouldlikebeincluded)) {
 $temp = explode("|", $row_infowouldlikebeincluded['infowouldlikebeincluded']);
 foreach ($temp as $value) {
  arraypush($arrsel,$value);
 }
}
?>

use print_r($arrsel); to check the results.
[/quote]

Thanks for your reply

This gets the values into an array which is what i needed...but...for some reason its leaving out all the records that are delimited by a | - is there a way I can include all records in the array even if they don't have a |

Thanks





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users