Jump to content

[SOLVED] PHP Split Variable?


amwd07

Recommended Posts

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

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

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