Jump to content

[SOLVED] Simple 3 column JS


unistake

Recommended Posts

Hi all,

I am having massive problems over a small issue!

 

On my website I have 3 columns, the user clicks an image on column 1 which retrieves information from a mysql db using PHP also, then the information is displayed in column 2 instantly. - This part works fine.

Then in column 2, I have two images that also when clicked on should show different information from a mysql db, however I can not get this second part to work.... any suggestions?!

 

The code ive been using is here http://www.w3schools.com/PHP/php_ajax_database.asp .

 

Thanks

 

Tim

Link to comment
https://forums.phpfreaks.com/topic/165407-solved-simple-3-column-js/
Share on other sites

ok I get your point! Thought it would be easier for you just to see what code I was dealing with than put it in this thread..

In the getuser.php code, I have tried to include two buttons that when clicked I would like to show some more information in the 'right' div tag shown in index.html.

 

Any help will be appreciated thanks..

Tim

 

index.html

<head>
<link href="style.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="selectuser.js"></script>
</head>


<body>
<div id="container">
  <div id="left"> 
    <p>click on this bookmaker image.</p>
    <p><a href="http://www.bet365.com/" target="_blank"><img src="flower1.png" width="200" height="60" name="flower1" onClick="showUser(this.name)"/></a></p>
    <p><img src="bet1128.png" width="200" height="60" name="bet1128" onClick="showBookie(this.name)" /> </p>
  </div>
  <div id="right">this information will depend on the image clicked in the 2nd column (txtHint)</div>
  <p>Content for id "container" Goes Here </p>
  <p><div id="txtHint"><b>Person info will be listed here.</b></div></p>
</div>
</body>

 

selectuser.js

// JavaScript Document

var xmlhttp;

function showUser(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="getuser.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

 

getuser.php

<?php
$q=$_GET["q"];

$con = mysql_connect('localhost', 'admin', 'password');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("database123", $con);

$sql="SELECT * FROM database WHERE column = '".$q."'";

$result = mysql_query($sql);

while($row = mysql_fetch_array($result))
  extract($row);
  {
  echo "$col1, $col2, $col3, $col4";
  }

echo "
  <input type='submit' name='initial' id='button' value='initial' >
  </label>
  <label>
  <input type='submit' name='follow' id='button2' value='followup' >";


mysql_close($con);
?>

From the code you have supplied, all I can see is the two buttons that you have after clicking the first image.  You don't have any code about "doing something else when the second image is clicked".

(ie, function showBookie() isn't included in your code)

 

You need to ask a specific question, and supply relevant code.  You didn't really ask a question, and the code you have doesn't handle the problem you said you have.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.