Jump to content

[SOLVED] Ajax & PHP Script Carrying Variables


iceblox

Recommended Posts

Hi Guys,

 

I have a ajax/php script which currently carrys one variable set by the value"" field. I want to carry another variable if possible this is my script how would i achieve this?

 

GetUser.php:

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


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

mysql_select_db("mobile", $con);

include ("http://www.freemobilephonereviews.com/cron/deals_network.php?NetworkName=$q");

mysql_close($con);
?>

 

Display Page

 

<div align="center">
  <center>
  <table border="0" cellpadding="2" cellspacing="3" style="border-collapse: collapse" bordercolor="#111111" width="78%" id="AutoNumber1">
    <tr>
      <td width="14%">
      <p align="center"><a target="_blank">
<a href="#" onClick="showUser(this.value)" value="Orange"><img src="http://www.urmob.co.uk/i/networks/Orange.gif" border="0" width="26" height="27"></a></td>
      <td width="14%">
      <p align="center"><a target="_blank">
      <a href="#" onClick="showUser(this.value)" value="O2"><img src="http://www.urmob.co.uk/i/networks/O2.gif" border="0" width="28" height="27"></a></td>
      <td width="14%">
      <p align="center"><a target="_blank">
      <a href="#" onClick="showUser(this.value)" value="Vodafone"><img src="http://www.urmob.co.uk/i/networks/Vodafone.gif" border="0" width="29" height="27"></a></td>
      <td width="14%">
      <p align="center"><a target="_blank">
      <a href="#" onClick="showUser(this.value)" value="T-Mobile"><img src="http://www.urmob.co.uk/i/networks/T-Mobile.gif" border="0" width="22" height="27"></a></td>
      <td width="14%">
      <p align="center"><a target="_blank">
      <a href="#" onClick="showUser(this.value)" value="Virgin"><img src="http://www.urmob.co.uk/i/networks/Virgin.gif" border="0" width="47" height="27"></a></td>
      <td width="15%">
      <p align="center"><a target="_blank">
      <a href="#" onClick="showUser(this.value)" value="Three"><img src="http://www.urmob.co.uk/i/networks/Three.gif" border="0" width="22" height="27"></a></td>

</table>
  </center>
</div>
  <center><div id="txtHint">
<?php
include ('http://www.freemobilephonereviews.com/cron/deals.php?ModelID=' . $ModelID . '');


?>
</div></center>

 

.Js File

 

var xmlHttp

function showUser(str)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url="getuser1.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 || xmlHttp.readyState=="complete")
   { 
   document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
   } 
} 

function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

 

 

 

Any help would be apprecaited...

 

Link to comment
Share on other sites

You'll need to modify the .js file:

 

var url="getuser1.php"
url=url+"?q="+str
url=url+"&yourothervariable=somevalue"
url=url+"&sid="+Math.random()

 

And then the php file:

 

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

 

Obviously you'll need to change the js to reflect what you actually want to pass in the url.

Link to comment
Share on other sites

Sorry that probably did come out as well as it should have done. Currently the script allows me to change the network via the display page. Want i would like to be able to is change the network and get the ModelID through a variable set in the display page. If this makes sense?

 

 

Phil

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.