Best way to create SVG from database? (Using PHP) I've got a SQL database that keeps track of which services a client has.  I need to create an image using SVG that only displays the services that the client has.  The database stores the services in the format 1,2,3,6,7,9.  Here's what I have:

 &lt;?php
    header("Content-type: image/svg+xml");
    $db = new PDO(**[redacted]**);
    $grabServices = $db-&gt;prepare("SELECT services FROM *** where name= :name");
    $grabServices-&gt;execute(array(":name" =&gt; "test" ));
    $services = $grabServices-&gt;fetchAll();
    $services = explode(",", $services[0][services]);
    var_dump($services);
?&gt;

//snip...

&lt;?php if(in_array(1, $services)){?&gt;
    &lt;line x1="820" y1="120" x2 ="790" y2="180" class="SaaS"/&gt;
&lt;?php }?&gt;
&lt;?php if(in_array(2, $services)){?&gt;
    &lt;line x1="905" y1="180" x2 ="700" y2="370" class="PM"/&gt;
&lt;?php }?&gt;
//etc, etc,


This seems incredibly tedious to me.  The only other way I can think to do this would have all the SVG elements created in a PHP array, but that seems even more wasteful.  Is there a better way to do this?
&lt;?php
$formats = array(
    '1' =&gt; array(
        'x1' =&gt; 820,
        'y1' =&gt; 120
    ),
    '2' =&gt; array(
        'x1' =&gt; 905,
        'y1' =&gt; 180
    )
);
?&gt;

&lt;?php foreach( $formats as $key =&gt; $format ) : ?&gt;
    &lt;?php if ( in_array( (int) $key, $services ) ) : ?&gt;
        &lt;line x1="&lt;?php print $format['x1']; ?&gt;" y1="&lt;?php print $format['y1']; ?&gt;" /&gt;
    &lt;?php endif; ?&gt;
&lt;?php endforeach; ?&gt;


I didn't do it for every field, but you get the idea.

This is tedious to write the array. But you have to write it somewhere. If there is no logic, the computer can't guess.

I think it's easier to read/write a simple array than all this XML though.