how do i print the string dynamically using implode and explode from the database?

Olly

New Member
i am using implode to store my image paths. with the special symbol '~' . and hence in my database i store a single string which holds the path and filename of the multiple pictures and then i retrieve it. the string which is stored in the database is similar to this.\[code\]uploads/adv/adfront_07October2010_13531.jpg~uploads/adv/adfront_07October2010_37472.jpg~uploads/adv/adfront_07October2010_43637.jpg~uploads/adv/adfront_07October2010_39959.jpg\[/code\]i store the above code using the implode function. and then i retrieve it using the following code.\[code\]$adbox_query = "SELECT advertisements.id , advertisements.pic_brief, advertisements.pos FROM advertisements WHERE pos BETWEEN 1 AND 8";$adbox_res = mysql_query($adbox_query) or trigger_error(mysql_error(). " in " .$query);$adbox = array_fill(1, 8, null);while ($row = mysql_fetch_array($adbox_res)) { $adbox[$row['pos']] = $row;}\[/code\]and using the foreach i fetch the result like this.\[code\]if( $adbox[1]) { $id_1 = $adbox[1]['id']; echo "<a href = 'http://stackoverflow.com/questions/3890586/advertisement.php?id=$id_1'>"; $ad1 = $adbox[1]['pic_brief']; $ad1 = explode('~', $ad1); foreach($ad1 as $adbox1){ echo "<img src = 'http://stackoverflow.com/questions/3890586/admin-login/$adbox1' alt = 'advertisement'/>"; } } else { echo "i do not exist"; }\[/code\]the above code works perfectly fine however i want to achieve something more with this.i want the first string which prints the html element according to the queries in the database to have a class defined as active. to be more precise.if my database holds the 4 image paths, it will print the following html code.\[code\]<img src = 'http://stackoverflow.com/questions/3890586/admin-login/uploads/adv/adfront_07October2010_13531.jpg' alt = 'advertisement'/><img src = 'http://stackoverflow.com/questions/3890586/admin-login/uploads/adv/adfront_07October2010_37472.jpg' alt = 'advertisement'/><img src = 'http://stackoverflow.com/questions/3890586/admin-login/uploads/adv/adfront_07October2010_43637.jpg' alt = 'advertisement'/><img src = 'http://stackoverflow.com/questions/3890586/admin-login/uploads/adv/adfront_07October2010_39959.jpg' alt = 'advertisement'/>\[/code\]now i want to add the class active to the first html image tag for example instead of the above code i want to achieve it like this.\[code\]<img class= 'active' src = 'http://stackoverflow.com/questions/3890586/admin-login/uploads/adv/adfront_07October2010_13531.jpg' alt = 'advertisement'/> <img src = 'http://stackoverflow.com/questions/3890586/admin-login/uploads/adv/adfront_07October2010_37472.jpg' alt = 'advertisement'/> <img src = 'http://stackoverflow.com/questions/3890586/admin-login/uploads/adv/adfront_07October2010_43637.jpg' alt = 'advertisement'/> <img src = 'http://stackoverflow.com/questions/3890586/admin-login/uploads/adv/adfront_07October2010_39959.jpg' alt = 'advertisement'/>\[/code\]i am confused on what i should be doing to achieve it. how do i twist my code to achieve the result.?thank you
 
Back
Top