Forum Moderators: coopster

Message Too Old, No Replies

An OOP question about split()

is this possible?

         

henry0

12:11 pm on Oct 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am trying to use a form:
$a="#cccccc";
$b="img src=img/curv_g.jpg";
echo "<select name=\"color\"><option value=\"$a^$b\">Grey #cccccc</option></select>";

that should feed (not tried yet the modif since I cannot figure the how to) my DB to be query by the template bellow (after using split()function )

$content_101 .= '';
include "includes/bg.inc.php";
$page->SetParameter("BG", $content_101);

$content_103 .= '';
include "includes/curv.inc.php";
$page->SetParameter("CURV", $content_103);

as you see this presently comes from two different values out of my DB
“BG” and “CURV”

if instead of having two values posted by the form I was to use the above form code
how then can I split the new dual value entered in the DB as “Grey” and still be able using for example an include such as “curv”
<?
$conn = db_connect();

$sql= "select curv from group_1 where id=$id";
$result = mysql_query($sql,$conn);
while ($new_content=mysql_fetch_array($result) ){
$content_103.= $new_content[curv];

}
?>
that in return should feed
content_101 and content_103 (I need to keep those two existing)
Hope I am clear enough ... although not really sure!

why am I splitting hairs:
I am adding a modif to my CMS that will allow for BG options, but since I have a curve as part of my design I then need to match the curve img to my BG
therefore I would like the user to click once instead of cliking twice to set both values

Regards

Henry

ergophobe

5:31 pm on Oct 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I can think of a couple of ways to do it that might work.

1. Use a lookup table.

$bg = '#cccccc';
$curve_img = getCurveImg($bg);

function getCurveImg($bg)
{
$q = "SELECT file_name FROM curves WHERE bg='$bg'";
$r = mysql_query($q);
$curve_info = mysql_fetch_assoc($r);
return $curve_info['file_name'];
}

echo '<img src="' . $curve_img . '">';

2. you could split the values as you suggest, though you don't need regex functions, just a unique delimiter

$color_info = explode('^', $_POST['name']);

$bg = $color_info[0];
$curve_file = $color_info[1];

Does that help?

henry0

6:13 pm on Oct 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks
It helps a great deal

I can try both but might use the lookup table

Henry