Get ready for BLACK FRIDAY shopping starting in

Forums

PHP

This topic is locked

I need some advice.

Posted 27 Apr 2008 23:35:19
1
has voted
27 Apr 2008 23:35:19 Ben Corey posted:
I am new to php and mysql and quite familiar with javascript, so I am currently testing some things to make a site for an art gallery. I seem to have made a very unhealthy mix of the three languages and now I'm stuck, unable to retrieve a user selection from a dropbox that I wish to use. Sorry if the script is a bit of a mess, can anyone figure this out?

<?
$hostname='';
$dbname='phptest';
$username='';
$password='';
$connex=mysql_connect($hostname,$username,$password);
$sql = 'SELECT * FROM `items`';
$test=@mysql_db_query($dbname,$sql,$connex);

echo '<table border=1>';
echo '<tr><td></td><td></td>';
echo '<tr>';
echo '<td></td>';
echo '<td>';
echo '<table border=0 style="position:relative;top:25;left:25;color:white">';
while ($row = mysql_fetch_array($test))
{
extract($row,extr_all);
echo '<tr>';
echo '<td>';
echo '<image src="';
echo $number;
echo '.bmp" height=50 width=50></img>';
echo '</td>';
echo '<td style="width:80">';
echo $artist;
echo '</td>';
echo '<td style="width:150">';
echo $description;
echo '</td>';
echo '<td>';
echo $price;
echo '</td>';
}
echo '</td></table>';
echo '</td>';
echo '</table>';
?>
<?
$sql = 'SELECT * FROM `artists`';
$artistselect=@mysql_db_query($dbname,$sql,$connex);
echo '<select name="artist">';
echo '<option value=$name selected></option>';
while ($names = mysql_fetch_array($artistselect)) {
$name=$names['name'];
echo '<option value="">';
echo $name;
echo '</option>';
}
echo '</select>';
?>
//all is well up to here, I manage to retrieve information from the database and display it into a table. The following piece of Javascript works well.

<?
echo '<script language=javascript>';
echo 'function ChangeMessage(content,spot)';
echo '{';
echo 'if(document.getElementById)';
echo 'document.getElementById(spot).innerHTML = content;';
echo '}';
echo 'document.write(\'<div id="box" style="z-index=1;position:absolute;top:200;left:200;height:100;width:100;background=#cccccc"></div>\')';
echo '</script>';

?>


//Here is where it gets messy when I try to retrieve the information the user selected in the dropbox and use the ChangeMessage function to display it in the above "box" DIV. I am unable to use the variable, I have tried a couple of ways, I'm hoping you guys can help me.

<?
$pick = 'document.artist.options.selectedIndex.value';
echo '<form>';
echo '<input type=button value=Change style="position:absolute;top:600;left:300" onClick=ChangeMessage(\'';
echo $pick; // this is where the variable should be, changing depending on the user selection.
echo '\',\'box\')>';
echo '</form>';
?>



<html>
<head>
<script language=javascript>
</script>
</head>
<body background="speck.JPG">






</body>
</html>

PHP | Javascript

Edited by - herrbenito on 27 Apr 2008 23:43:36

Reply to this topic