Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7976217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:51:50+00:00 2026-06-04T08:51:50+00:00

I’m currently working on a project which is nearly done, but there’s one more

  • 0

I’m currently working on a project which is nearly done, but there’s one more problem to fix, and it is pretty crucial.

What i am trying to do is change a value (activeID) in my database when i click a certain image.

I know i’m gonna need php as well as javascript, but my javascript-skills aren’t really good, if anyone could help me out, that would be amazing!

To help you guys understand, here the structure of the table in database:

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

CREATE TABLE IF NOT EXISTS `artikel` (
  `Titel` varchar(100) CHARACTER SET utf8 NOT NULL,
  `ArtikelID` int(255) NOT NULL,
  `content` text CHARACTER SET utf8 NOT NULL,
  `imagepath` varchar(255) CHARACTER SET utf8 NOT NULL,
  `activeID` int(11) NOT NULL,
  `thumbpath` varchar(255) CHARACTER SET utf8 NOT NULL,
  `shortcontent` text CHARACTER SET utf8 NOT NULL,
  `categorie` varchar(10) CHARACTER SET utf8 NOT NULL,
  PRIMARY KEY (`ArtikelID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `artikel` (`Titel`, `ArtikelID`, `content`, `imagepath`, `activeID`, `thumbpath`, `shortcontent`, `categorie`) VALUES
('Zware hinder op E313 door dodelijk ongeval in Geel', 1, 'Het ongeval gebeurde rond 12 uur. Er had zich een file gevormd doordat de afrit Geel-West is afgesloten wegens werken.', 'images/bin1.jpg', 0, 'images/bin1thumb.jpg', 'Op de E313 richting Antwerpen is vandaag ter hoogte van de afrit Geel-West.', 'bin'),
('België geeft 12 miljoen voor heropbouw Afghanistan na 2014', 2, 'Eind 2014 trekt de NAVO zich terug uit Afghanistan. De militairen dragen dan de verantwoordelijkheid voor de veiligheid definitief over aan de Afghaanse veiligheidstroepen.', 'images/bin2.jpg', 0, 'images/bin2thumb.jpg', 'Na de terugtrekking van de Belgische militairen uit Afghanistan eind 2014 zal België voor maximaal 12 miljoen euro bijdragen aan de heropbouw van het land.', 'bin'),
('Oppositie hekelt gebrek aan visie en groei in debat begrotingscontrole', 3, 'De controle was nodig omdat de regering bij de initiële begroting 2012 uitgegaan was van een economische groei van 0,8% van het bbp, terwijl dat cijfer in de economische begroting van februari teruggebracht werd 0,1%.', 'images/bin3.jpg', 0, 'images/bin3thumb.jpg', 'De plenaire Kamer buigt zich vandaag over de begrotingscontrole die het begrotingstekort voor 2012 moet beperken tot 2,8 procent van het bbp, overeenkomstig het stabiliteitsprogramma. Daarvoor was een inspanning van 1,8 miljard euro nodig.', 'bin')

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Here is the connection i use for the database:

<?php 

        session_start();
        
        $sHost = "localhost";
        $sUser = "root";
        $sPassword = "";
        $sDatabase = "project";
        
        $link = mysqli_connect($sHost, $sUser, $sPassword, $sDatabase) or die("MySQL Error: " . mysqli_error());  
        
?>

Here is the php and html code i have to get the content out of the database, notice that there is an image being called through a path for each record (only the first select statement you see is relevant to this topic because i have cut the rest of the HTMLcode out to keep the topic short):

        <?php
                
                //session_start();
                
                //include("classes/connection.php");
                include_once("classes/connection.php");
                
                $getBinnenland = mysqli_query($link,"SELECT * FROM artikel WHERE categorie = 'bin';");
                //$getBuitenland = mysqli_query($link,"SELECT * FROM artikel WHERE categorie = 'bui';");
                //$getSport = mysqli_query($link,"SELECT * FROM artikel WHERE categorie = 'spo';");
                //$getPolitiek = mysqli_query($link,"SELECT * FROM artikel WHERE categorie = 'pol';");
                //$getMilieu= mysqli_query($link,"SELECT * FROM artikel WHERE categorie = 'mil';");
                //$getBizar = mysqli_query($link,"SELECT * FROM artikel WHERE categorie = 'biz';");
                
                ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
                <html xmlns="http://www.w3.org/1999/xhtml">
                <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <title>Digital Press overview</title>
                <link rel="stylesheet" href="style.css" type="text/css" />
            </head>
            
            <body>
                
                <div id="wrapper">
        <ul id="Binnenland">            
                    <?php
                    if(mysqli_num_rows($getBinnenland) > 0)
                    {       
                        while($Binnenland = mysqli_fetch_assoc($getBinnenland))
                        {
                            echo "<li><a href='#'><h3>".$Binnenland['Titel']."</h3><img src='". $Binnenland['thumbpath'] ."' alt='thumbnail'/></a><p>".$Binnenland['shortcontent']. "</p>";
                            
                        }
                    }
                    else
                    {
                        echo "<li>Nog geen designs</li>";   
                    }
                    
                    ?>
        </ul>
</div>
</body>

SO NOW FOR THE QUESTION: If i click a certain image, i want it to change the activeID of that record into 1 instead of 0, and if i click it again i want it to change back to 0

I don’t have a clue on how to start this, so any help would be most welcome,
Thank you in advance to all who will help me with this!
Greetings

EDIT

i have implemented the code from the answer below, get no errors, but database does not change activeID either. anyone know what i can do to fix this?

The onclick event:

echo "<li><a href='#'><h3>".$Binnenland['Titel']."</h3><img onClick = 'javascript: setActive();' src='". $Binnenland['thumbpath'] ."' alt='thumbnail'/></a><p>".$Binnenland['shortcontent']. "</p>";

the javascript:

 <script type="text/javascript">
function setActive()
{
if (window.XMLHttpRequest)
   {
   xmlhttp=new XMLHttpRequest();
   }
 else
   {
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   } 
 xmlhttp.onreadystatechange=function()
   {
   if (xmlhttp.readyState==4 && xmlhttp.status==200)
     {
         //Return Value. Handle as you wish. Display or ignore.
         var x = xmlhttp.responseText;
     }
   }
 xmlhttp.open("POST","setActive.php",true);
 xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
 xmlhttp.send(p_str);
  }
</script>

The setActive.php file:

<?php            

    session_start();           

    $sHost = "localhost";           
    $sUser = "root";           
    $sPassword = "";           
    $sDatabase = "project";           

    $link = mysqli_connect($sHost, $sUser, $sPassword, $sDatabase) or die("MySQL Error: " . mysqli_error());             

     $res = mysqli_fetch_row(mysqli_query($link,"select activeID from artikel"));
     $active = $res[activeID];
     $activeID = ($active == 0) ? 1 : 0; 
     $res = mysqli_query($link,"update artikel set activeID = $activeID");
     if ($res) echo "Success, ActiveID = $activeID";
          else echo "Failure, unable to update ActiveID to $activeID";
?>           
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:51:52+00:00Added an answer on June 4, 2026 at 8:51 am

    HERE IS Artikel.php . LATEST POST 12:40 PST

    <?
    mysql_connect("xxxxxxxxxxx", "xxxxxxxxxx", "xxxxxxxxx");  
    mysql_select_db("xxxxxxxx");  
    
    $res = mysql_query("select * from artikel");  
    $fcount = mysql_fetch_assoc(mysql_query("select count(*) as count from artikel"));  
    
    while ($Binnenland =  mysql_fetch_assoc($res)) { 
        $jS = '"'.$Binnenland[ArtikelID].'"'; 
        echo "<font size=2 face='Century Gothic'><center><li><b>ARTICLE ID: ".$Binnenland['ArtikelID']."</b><br><font size=2><a href='#'><h3>".$Binnenland['Titel']."</h3><a href='javascript:setActive(".$jS.")'> <img src='$Binnenland[thumbpath]' width=75 style='border: 0px; -moz-border-radius: 8px; border-radius: 8px' alt='thumbnail'></a><p>".$Binnenland['shortcontent']. "</p></center>"; 
        echo "<span style='color: black;' id='".$Binnenland[ArtikelID]."'><center><font face='Century Gothic'>ActiveID: ".$Binnenland[activeID]."</font></center><br><br><hr></span>";
    } 
    
    ?> 
    
    <script type="text/javascript">  
    
    function setActive(ObjID)  {  
    
    if (window.XMLHttpRequest)  {  
        xmlhttp=new XMLHttpRequest();  
    }  
    else  
    {  
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  
    }   
    
    xmlhttp.onreadystatechange=function()   {  
    
    if (xmlhttp.readyState==4 && xmlhttp.status==200)  
          {  
    
            //Return Value. Handle as you wish. Display or ignore.  
            var x = xmlhttp.responseText; 
    
            if (document.getElementById(ObjID).style.color == 'black') document.getElementById(ObjID).style.color='red';
                    else document.getElementById(ObjID).style.color='black';
    
            document.getElementById(ObjID).innerHTML = '<center><font face="Century Gothic">ActiveID: ' + x + '</font></center><br><br><hr>'; 
          }  
    }  
        var p_str = "a="+ObjID; 
        xmlhttp.open("POST","setActive.php",true);  
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");  
        xmlhttp.send(p_str);  
    }  
    
    </script> 
    

    AND HERE IS setActive.php

    <?php              
    
    mysql_connect("xxxxx", "xxxxx", "xxxxxx");  
    mysql_select_db("xxxxx"); 
    $ArtikelID = $_REQUEST[a]; 
    
    $res = mysql_query("select activeID from artikel where ArtikelID = ".$ArtikelID);  
    $row = mysql_fetch_assoc($res); 
    
    $active = $row[activeID];  
    $activeID = ($active == 0) ? 1 : 0;   
    $res = mysql_query("update artikel set activeID = $activeID  where ArtikelID = ".$ArtikelID);  
    
    if ($res) echo $activeID;  
           else echo "Failure, unable to update ActiveID to $activeID";  
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.