Jump to content

PHP and JS talking issue - I am unsure how to solve this... please.


scotchegg78

Recommended Posts

Hi guys

 

Stupid girl here :(

 

I have a problem which I think should be easy for people to solve :)

 

I have a CMS system, pages load from a page class and if its a news page news items are loaded using a news class.

I need to add a news ratings system to this, so made a vote class which the news class owns an instance of.

 

So in the constructor for news class..

 

$this->vote = new vote($indb_link);

 

Then in the news class display function is the call to the vote class to display the 5 stars etc content i have

 

public function display() {
...
$vote= $this->vote->drawvote("news",$this->id,"");
...
}

 

Now this works fine no issues, however i need to to update my mysql database now, which i can do if i understand how to get the vote input to the php again!

 

For the vote output includes...

 

<a onclick=\"rateIt(this)\" id=\"_1\" title=\"One\" onmouseover=\"rating(this)\" onmouseout=\"off(this)\"></a>

 

which calls the JS functions, but it seems wrong to me to use the JS to update the mysql and not the php vote class itself i made ..

 

public function add($type,$itemid, $vote,$ip){

	$this->type = $type;
	$this->itemid = $itemid;
	$this->vote = $vote; //replace_harmful_content($inname);
	$this->ip = $ip;

	$lsql = "insert into vote (type,itemid,vote,ip) values ('".$this->type."','".$this->itemid."',".$this->vote.", ".$this->ip.");";
	//gshowdebug($lsql);
	mysqli_query($this->db_link, $lsql);
}

 

Now my problem is how do i get my a links to call my php add function?

I can not just add the php funciton to the onclick call can i ? eg..

 

 <a onclick=\". add(etc etc).\"  id=\"_1\" title=\"One\" onmouseover=\"rating(this)\" onmouseout=\"off(this)\"></a>

 

And If i reload the page i need to relad with a vote varible somewhere for the php to pick up, but something like..

 

<a href=\"".$_SERVER['PHP_SELF']."?voted=1\" 
<a href=\"".$_SERVER['PHP_SELF']."?voted=2\"

 

etc etc fails as the php_self loses the actual page the cms is on, a JS call like

 onclick=\"window.location.reload()\" 

re loads the cms page fine, but i have no varialbe to use !

 

Any advice or information to put me straight here very much appreciated.

 

lucy.

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.