Jump to content

President Obama

Members
  • Posts

    55
  • Joined

  • Last visited

    Never

Contact Methods

  • AIM
    NB_Sico_Music

Profile Information

  • Gender
    Male
  • Location
    In your attic watching you though the ceiling lights.

President Obama's Achievements

Member

Member (2/5)

0

Reputation

  1. Don't worry I got it working, was a couple of problems. A) I wasn't connecting to my database at all in the ajax.php B) I didn't use semicolons on the 4 javascript variables, which is strange because I thought javascript didn't need semicolens C) Apparently having the code in another document like I did also stuffs it up, probably because of the php I used in it.
  2. Sorry but your code confused me a bit. Though I will say to post ajax to self just use $.post("");
  3. Encrypt it then send it to the php file. Theres a good article on it somewhere that I used, you have to a crypt library.
  4. Fine. include 'config.php'; $result = mysql_query("SELECT * FROM adverts") or die(mysql_error()); // Get Ads $result2 = mysql_query("SELECT * FROM lil_urls WHERE id=$text") or die(mysql_error()); // Get User Link $link = mysql_fetch_array($result2); // Array Convert User Link $ads = array(); // array for ad id $bds = array(); // array for ad url $cds = array(); // array for the two aboved combined to set the index as the id // Fill first 2 arrays while($row = mysql_fetch_array($result)){ $ads[] = $row['id']; $bds[] = $row['url']; } // Combine the 2 arrays to set the index as the id $cds = array_combine($ads, $bds); // Start Generating 4 random numbers to choose 4 random adds $result3 = array(); $numberCount = 4; $thisCount = 0; while($thisCount<$numberCount) { $thisNumber = array_rand($cds); if(!in_array($thisNumber, $result3)) { $result3[$thisCount] = $thisNumber; $thisCount++; } } // End generating. ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <script type="text/javascript" src="jquery/jquery.js"></script> <script type="text/javascript" src="jquery/javascript.js"></script> </head> <body> <pre> <?php print_r($result3); print_r($cds); ?> </pre> <a id="advert1" href="<?php echo $link['url']; ?>" onclick="window.open('<?php echo $cds[$result3[0]]; ?>')">Banner #1</a> <a id="advert2" href="<?php echo $link['url']; ?>" onclick="window.open('<?php echo $cds[$result3[1]]; ?>')">Banner #2</a> <a id="advert3" href="<?php echo $link['url']; ?>" onclick="window.open('<?php echo $cds[$result3[2]]; ?>')">Banner #3</a> <a id="advert4" href="<?php echo $link['url']; ?>" onclick="window.open('<?php echo $cds[$result3[3]]; ?>')">Banner #4</a> </body> </html>
  5. lol Sorry thought I had included that, what its meant to do is, person clicks ad link, ajax posts ad id to php document which then increases the column view by 1.
  6. Yeah I redesigned the code, this works kinda. Well it did in a test but in practical it won't, do you see the problem in this? ajax.php <?php if(isset($_POST['functionid'])){ switch ($_POST['functionid']){ case 1: ad1(); break; case 2: ad2(); break; case 3: ad3(); break; case 4: ad4(); break; } } function ad1(){ if(isset($_POST['result'])){ $advert = $_POST['result']; mysql_query("UPDATE adverts SET views = views+1 WHERE id = $advert"); } } ?> Javascript.js: $(document).ready(function() { // Get advert numbers var advert1 = <?php echo $cds[$result3[0]]; ?> var advert2 = <?php echo $cds[$result3[1]]; ?> var advert3 = <?php echo $cds[$result3[2]]; ?> var advert4 = <?php echo $cds[$result3[3]]; ?> $("#advert1").click(function(){ alert("Success") $.post("ajax.php?", {result: advert1, functionid: 1}, function(data){alert("Success")}) }); $("#advert2").click(function(){ $.post("ajax.php?", {result: advert2, functionid: 2}) }); $("#advert3").click(function(){ $.post("ajax.php?", {result: advert3, functionid: 3}) }); $("#advert4").click(function(){ $.post("ajax.php?", {result: advert4, functionid: 4}) }); }); HTML: <a id="advert1" href="<?php echo $link['url']; ?>" onclick="window.open('<?php echo $cds[$result3[0]]; ?>')">Banner #1</a> <a id="advert2" href="<?php echo $link['url']; ?>" onclick="window.open('<?php echo $cds[$result3[1]]; ?>')">Banner #2</a> <a id="advert3" href="<?php echo $link['url']; ?>" onclick="window.open('<?php echo $cds[$result3[2]]; ?>')">Banner #3</a> <a id="advert4" href="<?php echo $link['url']; ?>" onclick="window.open('<?php echo $cds[$result3[3]]; ?>')">Banner #4</a>
  7. What I want to do is when someone clicks on a link, call a php function in another file which updates the database. This is what I've kinda come up with, doesn't work though. (Uses Jquery) <?php $result3 = array(); $result3[0] = $_POST['result0']; $result3[1] = $_POST['result1']; $result3[2] = $_POST['result2']; $result3[3] = $_POST['result3']; mysql_query("UPDATE adverts SET views = views + 1 WHERE id = $result3[0]")or die(mysql_error()); mysql_query("UPDATE adverts SET views = views + 1 WHERE id = $result3[1]")or die(mysql_error()); mysql_query("UPDATE adverts SET views = views + 1 WHERE id = $result3[2]")or die(mysql_error()); mysql_query("UPDATE adverts SET views = views + 1 WHERE id = $result3[3]")or die(mysql_error()); ?> Jquery: $(document).ready(function(){ var result0 = <?php echo $result3[0]; ?> var result1 = <?php echo $result3[1]; ?> var result2 = <?php echo $result3[2]; ?> var result3 = <?php echo $result3[3]; ?> $('.advert').click(function(){ $.post("functions.php", {result0: "result0", result1: "result1", result2: "result2", result3: "result3" }) }) }); HTML: <a class="advert" href="<?php echo $link['url']; ?>" onclick="window.open('<?php echo $cds[$result3[0]]; ?>')">Banner #1</a>
  8. $bl = array(); $link1 = array_rand($cds); $link2 = array_rand($cds); $link3 = array_rand($cds); $link4 = array_rand($cds); $A = 0; while (!in_array($link1, $bl)){ $link1 = array_rand($cds); $bl[$A] = $link1; $A++; } while (!in_array($link2, $bl)){ $link2 = array_rand($cds); $bl[$A] = $link2; $A++; } while (!in_array($link3, $bl)){ $link3 = array_rand($cds); $bl[$A] = $link3; $A++; } while (!in_array($link4, $cds)){ $link4 = array_rand($cds); $bl[$A] = $link4; $A++; } echo $link1; echo $link2; echo $link3; echo $link4; Pretty much I'm trying to generate 4 number's between the min and max of an array but I don't want any duplicates. So it checks if the number exists in a bl array if it does it generates another number, well thats the theory. Doesn't work like that though.
  9. Ok I found a way to totally ditch my multidimensional array. What I did is make 2 arrays one with the id's and one with the links then I used array_combine to combine them to a new array which has the indexes as the id's, now I can use shuffle on it and add views.
  10. eh should of explained my self better. What I'm doing is pulling 4 ads at random out of the db, but with each pull I want to add 1 to the views for that specific ad. As in the links I only want the URL but with the views I want the Id to compare to the database and find out which ad to add a view to. Also if I use rand 4 times it will pull duplicates which I also don't want. Hard to explain.
  11. Ok I'm really lost here, what I need to do is shuffle a 2D array. Now when I shuffle them I want to keep both columns aligned to say. Like I only want the index to change. Kinda like this: Index Id URL 0 [2 www.e] I want the bracketed stuff to stay aligned. 1 [6 www.b] 2 [12 www.c] 3 [60 www.h] But I want them in different positions on every page load. So when I echo array[1][0] it will always be different. Is this even possible?
  12. Don't worry, got it working. heres the code I used: <?php include 'config.php'; $result2 = mysql_query("SELECT * FROM adverts") or die(mysql_error()) ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> </head> <body> <?php $ads = array(); $A = 0; while($row = mysql_fetch_array($result2)){ $ads[] = $row['url']; } shuffle($ads); echo $ads['1']; ?> </body> </html>
  13. <?php echo $description; ?> ? That should work, shouldn't it?
×
×
  • 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.