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"; ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted November 29, 2007 Share Posted November 29, 2007 Why not use explode ? Quote Link to comment 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? Quote Link to comment 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]; Quote Link to comment Share on other sites More sharing options...
revraz Posted November 29, 2007 Share Posted November 29, 2007 What's in $ratings Quote Link to comment 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); Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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); Quote Link to comment 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; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.