Jump to content

Help Please!


LiamS94

Recommended Posts

Hey, all!

 

I posted the question below into Yahoo! Answers and got an answer, but it doesn't seem to work.

 

For my website each user has their own mini web site. With each page they can rearrange their blocks (holds page content). Once they have rearranged their blocks a string like this '3,1|1,1|1,1|1,1|1,1|1,1|1,1|1,1|1,1' goes to the DB .

 

Each section which is separated by '|' is the colspan and rowspan of a block for a table. So 3,1 is for block1, 3 is the colspan and 1 is the rowspan.

 

How do I spilt this all up, so it because variables, like;

$block1_colspan = 3;

$block1_rowspan = 1;

and so on for every block?

 

This is the answer I got:

Your best bet is to first break up the data retrieved from the DB using the explode() function, and I would recommend using arrays for your data. (Replace the $string variable with the name of your string that containst the data)

 

Code:

$dimensions=explode("|", $string);

// dimensions variable is an array that has values such as 3,1 in one field, 1,1 in the next...

$numinarray = count($dimensions);

for($i=0;$i<$numinarray;$i++){

list($colspan[], $rowspan[])=explode(",", $dimensions);

}

 

Your output would be like:

$colspan[0]=3

$rowspan[0]=1

$colspan[1]=1

$rowspan[1]=1

...

 

Be sure to remember that arrays begin at 0, not 1.

 

But when I tried it just echoed 'Array' nine times. Can anyone help me to get this code working?

Link to comment
https://forums.phpfreaks.com/topic/119053-help-please/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.