LiamS94 Posted August 10, 2008 Share Posted August 10, 2008 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 More sharing options...
Barand Posted August 10, 2008 Share Posted August 10, 2008 use print_r() to print an array, not echo. Link to comment https://forums.phpfreaks.com/topic/119053-help-please/#findComment-613034 Share on other sites More sharing options...
LiamS94 Posted August 10, 2008 Author Share Posted August 10, 2008 I understand what you are meaning, but for example $colspan[0]=1; when echoed show show '1'; Link to comment https://forums.phpfreaks.com/topic/119053-help-please/#findComment-613035 Share on other sites More sharing options...
Barand Posted August 10, 2008 Share Posted August 10, 2008 echo '<pre>'; print_r ($colspan); echo '</pre>'; or echo '<pre>', print_r ($colspan), '</pre>'; Link to comment https://forums.phpfreaks.com/topic/119053-help-please/#findComment-613041 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.