Jump to content

Change Image After User has visited


thesaleboat

Recommended Posts

So, I am editting a website that was originally created in XHTML but we switched it to PHP but everything is divided very precisely (i hate HTML  >:() so I have code developed to see if the user has visited a page before and if he has it updates the database.  I need an image on the website to change if the user has been there already so here is my code, obviously it doesn't work but I've tried a few different things.  I want the layout of the page to remain the same.  Please HELP me ->  ???

 

...

<tr>

<td class="progressChartInset2"><a href="regulations.php" class="four">Regulations</a></td>

  <td>

  <div align="center">

    <?php

    require_once('dbconnect.php');

    mysql_connect("$host", "$username", "$password")or die("cannot connect");

    mysql_select_db("$db_name")or die("cannot select DB");

    $myusername = $_SESSION['myusername'];

    $rowalreadyexists = mysql_query("SELECT * FROM `users_subcategories` WHERE `users_subcategories`.`SubCategoryId` = 30 and `users_subcategories`.`username` = '$myusername'") or die(mysql_error());

    $rowcount = mysql_num_rows($rowalreadyexists);

 

    if (!empty($_SESSION['myusername']) && $subcategory >= 1){

        if ($rowcount == 0) {

        echo (<img src="images/Zerocompletion.gif" alt="0% completed" width="18" height="18" />);

        }

    }

    else

        echo (<img src="images/Fullcompletion.gif" alt="100% completed" width="18" height="18" />);

    ?>

                                           

  </div>

</td>

</tr>

...

Link to comment
https://forums.phpfreaks.com/topic/114183-change-image-after-user-has-visited/
Share on other sites

i am not sure but i think the problem is that if

        if ($rowcount == 0) {
        echo (<img src="images/Zerocompletion.gif" alt="0% completed" width="18" height="18" />);
        }

returns false nothing else happens you need to change it to

    if (!empty($_SESSION['myusername']) && $subcategory >= 1){
        if ($rowcount == 0) {
        echo (<img src="images/Zerocompletion.gif" alt="0% completed" width="18" height="18" />);
        }
        else
            echo (<img src="images/Fullcompletion.gif" alt="100% completed" width="18" height="18" />);
    }
    else
        echo (<img src="images/Fullcompletion.gif" alt="100% completed" width="18" height="18" />);

 

Scott.

<td><div align="center">

<?php

require_once('dbconnect.php');

mysql_connect("$host", "$username", "$password")or die("cannot connect");

$myusername = $_SESSION['myusername'];

$rowalreadyexists = mysql_query("SELECT * FROM `users_subcategories` WHERE `users_subcategories`.`SubCategoryId` = 33 and `users_subcategories`.`username` = '$myusername'") or die(mysql_error());

$rowcount = mysql_num_rows($rowalreadyexists);

                       

if (!empty($_SESSION['myusername'])){

    if ($rowcount == 1) {

        echo '<img src="images/Fullcompletion.gif" alt="100% completed" width="18" height="18" />';

    }

    else

        echo '<img src="images/0completion.gif" alt="0% completed" width="18" height="18" />';

}

else

    echo '<img src="images/0completion.gif" alt="0% completed" width="18" height="18" />';

?>                                       

</div></td>

 

Got it Sold Out

 

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.