Hi there,

Can anyone help?

Why is the following code displaying "P1P2P3..." etc, instead of "P1 , P2, P3 ,.." etc. ?

Thanks

Paul

<!--Conect to database-->
    <?php include "connects/patientconn.php"; ?>

    <?php

    $query = "SELECT `Patient I.D.` FROM `patient`";

    $result = mysql_query($query);

    while($patient = mysql_fetch_assoc($result))
    {
    $pt = implode(" , ", $patient);
    echo $pt;
    }
    ?>

Recommended Answers

Change line 13 to:

echo "$pt, ";

mysql_fetch_assoc returns an array (with only one element in above case) and implode returns a string (P1, P2, P3 etc on each iterration).

Jump to Post

All 2 Replies

I'm guessing implode doesn't do anything since $patient is not an array.

Change line 13 to:

echo "$pt, ";

mysql_fetch_assoc returns an array (with only one element in above case) and implode returns a string (P1, P2, P3 etc on each iterration).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.