Jump to content

explode - arrays


bizzo

Recommended Posts

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
[code]
do {
$arrayselect = explode("|", $row_infowouldlikebeincluded['infowouldlikebeincluded']);
} while ($row_infowouldlikebeincluded = mysql_fetch_assoc($infowouldlikebeincluded));
[/code]

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
Link to comment
Share on other sites

[!--quoteo(post=361133:date=Apr 3 2006, 05:34 PM:name=Desdinova)--][div class=\'quotetop\']QUOTE(Desdinova @ Apr 3 2006, 05:34 PM) [snapback]361133[/snapback][/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
Link to comment
Share on other sites

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

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

use print_r($arrsel); to check the results.
Link to comment
Share on other sites

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

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

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.