Hi have confussed myself,

can you see why i cant get a new pic to be displayed in the box on click please ?

<HTML><HEAD><TITLE></TITLE><META content="text/html; charset=utf-8" http-equiv=Content-Type><META name=GENERATOR content="MSHTML 10.00.8400.0"><STYLE type=text/css>BODY {
    FONT-FAMILY: verdana, arial, sans-serif
}</STYLE>
</HEAD><BODY>
<FORM style="BORDER-TOP-COLOR: ; BORDER-BOTTOM-COLOR: ; BORDER-RIGHT-COLOR: ; BORDER-LEFT-COLOR: " method=post action=refresh>
<TABLE cellSpacing=2 cellPadding=1 width="100%" border=1>
<TBODY>
<TR>
<TD><INPUT style="HEIGHT: 22px; WIDTH: 43px" size=1 value=0000 name="clickcount"></TD></TR>
<TR><php$con = mysql_connect("localhost", "bubber", "xyz");
 if (!$con){ die('Could not connect: ' . mysql_error()); }mysql_select_db("base1", $con);

   //----------------------------------------------//----------------------------------------------
    $result = mysql_query("SELECT * FROM `xpic` ORDER BY RAND() LIMIT 0,1;");echo "<TABLE border=9><TBODY><TR>
<P></P><TH>xxxx</TH></TR>";
<TD>
while($row = mysql_fetch_array($result))

  {
  echo "<TR>";

    echo '<TD><IMG border=0 name=abc hspace=0 alt=abc123 src="',$row['pic'],'" width=300 height=343></A></TD>';

 echo "</TR>";
  }
echo "</TBODY></TABLE>";


mysql_close($con);
?>;
</TD></TR>
<TR>
<TD><INPUT type=submit value="change pic" name=click onclick= picchange()></TD></TR></TBODY></TABLE></FORM>

   <SCRIPT language=javascript type=text/javascript>
function pcchange() 
{
A = document.frmOne.clickcount.value;
A = Number(A);
C = A+1;
document.frmOne.clickcount.value =  C;

return colourchange();
  <SCRIPT language=javascript type=text/javascript>
function colourchange()
 {
    var red=Math.floor(Math.random()*256)
     var green=Math.floor(Math.random()*256)
        var blue=Math.floor(Math.random()*256)

    document.frmOne.clckcount.style.backgroundColor = "rgb("+red+","+green+","+blue+")";

    return newpic();
    <SCRIPT language=javascript type=text/javascript>
function newpic()
 {      
   document.frmOne.cabc.value = <php$con = mysql_connect("localhost", "bubber", "xyz"); if (!$con){ die('Could not connect: ' . mysql_error()); }mysql_select_db("base1", $con);

   //----------------------------------------------//----------------------------------------------
    $result = mysql_query("SELECT * FROM `xpic` ORDER BY RAND() LIMIT 0,1;");echo "<TABLE border=9><TBODY><TR>
<P></P><TH>xxxx</TH></TR>";

while($row = mysql_fetch_array($result))

  {
  echo "<TR>";

    echo '<TD><IMG border=0 name=abc hspace=0 alt=abc123 src="',$row['pic'],'" width=300 height=343></A></TD>';

 echo "</TR>";
  }
echo "</TBODY></TABLE>";


mysql_close($con); 
?>


              }

      </SCRIPT>
         }

      </SCRIPT>
}</SCRIPT>



</BODY></HTML>

You are mixing in PHP in a Javascript function. That is not possible.

Hi priteas, how do i turn the mysql querry $result into a varilable to be able to be used and chaged in the java on-click fuction ?

You can use Ajax.
Once page is loaded at user side and then you want any php operation without page load you can use ajax.
Below is sample code. You need to include jQuery file to run it.

By default show only one pic. When user click on button call this ajax function.
in ajax.php file you need to write php code to fetch any random image src and just echo it.

$.ajax({
  url: 'ajax.php',
  success: function(data) {
   alert('random image src:'+data);
    // data will be src of image
    // using javascript you can change image's src from data
  }
});

Have tried to strip it down even more to the basics , to try and understand,
so now have 2 pages 1.php & 2.php

1 =

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="2.php" method="post" name="form1" target="_self">
  <p><img alt="pic1" name="pic1" width="320" height="320" id="pic1" />
    <label for="click">total clicks</label>
    <input name="click" type="text" id="click" value="00000" />
  </p>
  <p>button1
    <input type="submit" name="button1" id="button1" value="Submit" onClick = calculate() />
  </p>
</form>
<script language="javascript" type="text/javascript">
function calculate() 
{
A = document.formOne.pic1.value;
A = Number(A);
C = A+1;
document.frmOne.w.value =  C;
document.frmOne.z.value = C+1;
return 2.php()
}
</script></body>
</html>
and 2.php
<?php

 $con = mysql_connect("host", "myuser", "psxx");
 if (!$con)
{
 die('Could not connect: ' . mysql_error());
  }
mysql_select_db("mytable", $con);
//----------------------------------------------

//----------------------------------------------


$result = mysql_query("SELECT * FROM `xpic` ORDER BY RAND() LIMIT 0,1;");

while($row = mysql_fetch_array($result))

  {


   pic1='<td><img width="300" src="',$row['pic'],'"/></a></td>';


  }



mysql_close($con);
?>

and I cant get it to load a pic when I first land on the page now :(

am now down to

1.php =

</head>

<body>
<div id="frm"><img  src="<?php echo "$pic"; ?>"></></div>

<button id="Next pic" onclick="show_next(); return false;">

function show_next()
{
  $('#frm').load('2.php');
}


</body>
</html>

and
2.php

<?php

 $con = mysql_connect("localhost", "memyselfi", "psxx");
 if (!$con)
{
 die('Could not connect: ' . mysql_error());
  }
mysql_select_db("table1base", $con);

$sql = ("SELECT pic FROM xpic ORDER BY RAND() LIMIT 1");

       while($row = mysql_fetch_array($sql)){

             $pic = $row["pic"];

    }


mysql_close($con);
?>

1 random pic 1 button , on click = new random pic,

Be a part of the DaniWeb community

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