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
https://forums.phpfreaks.com/topic/79446-solved-php-split-variable/
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);

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;

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.