amwd07 Posted November 29, 2007 Share Posted November 29, 2007 Hello I need help to split a database field into 5 sperate strings I have already converted to a variable $ratings = $row_rs3['ratings'] example entry 5,4,5,3,4 I am trying to split into 5 seperate strings entering the following works $ratingsplit = "5,4,5,3,4"; my problem is when I try to split the variable, myabe i am missing something really simle here? <?php $ratingsplit = $ratings; list($service, $atmosphere, $cleanliness, $value, $experience) = split('[,]', $ratingsplit); echo "service: $service; atmosphere: $atmosphere; cleanliness: $cleanliness; value: $value; experience: $experience;<br />\n"; ?> Link to comment https://forums.phpfreaks.com/topic/79446-solved-php-split-variable/ Share on other sites More sharing options...
revraz Posted November 29, 2007 Share Posted November 29, 2007 Why not use explode ? Link to comment https://forums.phpfreaks.com/topic/79446-solved-php-split-variable/#findComment-402239 Share on other sites More sharing options...
amwd07 Posted November 29, 2007 Author Share Posted November 29, 2007 How do I do that with the variable? Link to comment https://forums.phpfreaks.com/topic/79446-solved-php-split-variable/#findComment-402241 Share on other sites More sharing options...
amwd07 Posted November 29, 2007 Author Share Posted November 29, 2007 OK I have now changed to explode and I must have it wrong again? $splitratings = explode(",", $ratings); echo $splitratings[0]; echo $splitratings[1]; echo $splitratings[2]; echo $splitratings[3]; echo $splitratings[4]; Link to comment https://forums.phpfreaks.com/topic/79446-solved-php-split-variable/#findComment-402262 Share on other sites More sharing options...
revraz Posted November 29, 2007 Share Posted November 29, 2007 What's in $ratings Link to comment https://forums.phpfreaks.com/topic/79446-solved-php-split-variable/#findComment-402275 Share on other sites More sharing options...
amwd07 Posted November 29, 2007 Author Share Posted November 29, 2007 $ratings = $row_rs3['core_jreviews_ratings.ratings']; $splitratings = explode(" ", $ratings); Link to comment https://forums.phpfreaks.com/topic/79446-solved-php-split-variable/#findComment-402278 Share on other sites More sharing options...
revraz Posted November 29, 2007 Share Posted November 29, 2007 First try $ratings="5,4,3,2,1"; to make sure it works how you expect Link to comment https://forums.phpfreaks.com/topic/79446-solved-php-split-variable/#findComment-402280 Share on other sites More sharing options...
kenrbnsn Posted November 29, 2007 Share Posted November 29, 2007 Where is "$row_rs3['core_jreviews_ratings.ratings'];" coming from? Are you sure the value is what you're expecting? Ken Link to comment https://forums.phpfreaks.com/topic/79446-solved-php-split-variable/#findComment-402281 Share on other sites More sharing options...
amwd07 Posted November 29, 2007 Author Share Posted November 29, 2007 mysql_select_db($database_connDW, $connDW); $query_rs3 = "SELECT core_jreviews_ratings.reviewid, core_jreviews_ratings.ratings, core_jreviews_ratings.ratings_qty, core_jreviews_comments.id, core_jreviews_comments.pid, core_jreviews_ratings.ratings_sum, (core_jreviews_ratings.ratings_sum / core_jreviews_ratings.ratings_qty) as avgrating FROM (core_jreviews_ratings INNER JOIN core_jreviews_comments ON core_jreviews_comments.id=core_jreviews_ratings.reviewid) WHERE core_jreviews_comments.pid = '$reviewid'"; $rs3 = mysql_query($query_rs3, $connDW) or die(mysql_error()); $row_rs3 = mysql_fetch_assoc($rs3); $totalRows_rs3 = mysql_num_rows($rs3); Link to comment https://forums.phpfreaks.com/topic/79446-solved-php-split-variable/#findComment-402285 Share on other sites More sharing options...
amwd07 Posted November 29, 2007 Author Share Posted November 29, 2007 All working with the following code $splitratings = explode(",", $ratings); $service = $splitratings[0]; $atmosphere = $splitratings[1]; $cleanliness = $splitratings[2]; $value = $splitratings[3]; $experience = $splitratings[4]; ////////////////////// echo $service; echo $atmosphere; echo $cleanliness; echo $value; echo $experience; Link to comment https://forums.phpfreaks.com/topic/79446-solved-php-split-variable/#findComment-402317 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.