0

I am adding all names in to single variable but it is showing only one value last one.

my code is:

include 'dbconnect.php';
$result = mysql_query("SELECT * FROM bookedtates WHERE SID='$ServiceHosterIdv' AND BOOKEDDATE='$q'");
//$result = mysql_query("SELECT * FROM bookedtates WHERE SID='$ServiceHosterIdv' AND BOOKEDDATE='$q'");
while ($row = mysql_fetch_assoc($query)) {
$csk = "'".$row['NAME']."',";
}
echo $csk; 
1
  • What is your question? Commented Oct 4, 2013 at 7:21

3 Answers 3

1

No u just assign variable use it to plus add a "." before equtaion

  $csk .= "'".$row['NAME']."',";

But I would suggest to use array so u can use for JS(if ajax) or php for more flexible things

$csk = array();
while ($row = mysql_fetch_assoc($query)) {
$csk[] = array($row['NAME']);
}
echo $csk; //for ajax use echo json_encode($csk);
Sign up to request clarification or add additional context in comments.

2 Comments

i have used this but it is displaying only "array"
try print_r($csk); You shold get it but to output the array you need loop
0

just test with

include 'dbconnect.php';
$result = mysql_query("SELECT * FROM bookedtates WHERE SID='$ServiceHosterIdv' AND BOOKEDDATE='$q'");
//$result = mysql_query("SELECT * FROM bookedtates WHERE SID='$ServiceHosterIdv' AND BOOKEDDATE='$q'");
$csk = '';
while ($row = mysql_fetch_assoc($query)) {
    $csk .= "'".$row['NAME']."',";
}
echo $csk; 

Comments

0

You are resetting the variable to the value of $row['NAME'] on each iteration of the loop.

What you need to do is append the variable to the end of $csk:

$csk .= "'".$row['NAME']."',";
     ^---- notice the extra . here

The extra . indicates that you want to append the value to $csk.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.