Jump to content

BorysSokolov

Members
  • Posts

    78
  • Joined

  • Last visited

Posts posted by BorysSokolov

  1. I am attempting to assign a class to an element with a specific ID using jQuery. I've done this before without any problems, but for some reason, it's refusing to work now. 

     

    Here is a series of divs (the code is in a loop) from which I want to retrieve a single, unique div:

    <div id = "<?php echo $result.'_s'; ?>" >
    	<img src = "http://localhost/gallerySite/users/thumbnails/<?php echo $result; ?>" />
    </div>
    

    ...and here is the jQuery code I'm doing it with:

    $('#batman').addClass('myClass');
    

    When I run the program, the class simply isn't being applied to the div, and when I alert the length of the div, it returns 0, even though I can see it in the page source on Chrome. I've checked for spelling errors, and made sure the JS file is included in the correct place. What's odd though, is that when I assign a static value to the divs, let's say, "class = robin", and in jQuery, assign the 'batman' class to the divs with the 'robin', the program works fine. I suspect it may have something to do with the inline PHP in the HTML file, but I'm not sure why that would be an issue.

     

    Any ideas?

     

    Thanks.

  2. I'm building a basic photo gallery, and I'm having difficulties with the 'Categories' section. The plan is to display all the picture categories inside divs, and have them 'rotate' their background images through the pictures in the given category. For instance, the 'Nature' category div would change its background every few seconds to a random image in the Nature category.

     

    I've succeeded doing this, but the code wasn't very efficient. Basically, I've had a JavaScript file gather all the categories (through uniquely assigned IDs) and "$.post" them to a PHP file which polled images with the given category from a database, loaded them into an array and returned a random key. Then, using intervals it updated the background every couple of seconds.

     

    But I'm looking for a better way to do it. I'd prefer to poll the database only once, at the start of the page, and then just let the JS file reload the rand() function each time the interval is called; but I'm not sure how to pass the polled data to the file that call the random function. Any ideas how to do this?

     

    Obviously, I'm not expecting anybody to write the code for me, I just need some assistance. Also, sorry if all this is a little unclear, it's 4am here, and I'm falling asleep; if you need me to explain just let me know.

     

    Thanks.

  3. I'm building a basic photo gallery, and I'm having difficulties with the 'Categories' section. The plan is to display all the picture categories inside divs, and have them 'rotate' their background images through the pictures in the given category. For instance, the 'Nature' category div would change its background every few seconds to a random image in the Nature category.

     

    I've succeeded doing this, but the code wasn't very efficient. Basically, I've had a JavaScript file gather all the categories (through uniquely assigned IDs) and "$.post" them to a PHP file which polled images with the given category from a database, loaded them into an array and returned a random key. Then, using intervals it updated the background every couple of seconds.

     

    But I'm looking for a better way to do it. I'd prefer to poll the database only once, at the start of the page, and then just let the JS file reload the rand() function each time the interval is called; but I'm not sure how to pass the polled data to the file that call the random function. Any ideas how to do this?

     

    Obviously, I'm not expecting anybody to write the code for me, I just need some assistance. Also, sorry if all this is a little unclear, it's 4am here, and I'm falling asleep; if you need me to explain just let me know.

     

    Thanks.

  4. Hi all. I'm looking to gain some "real world" experience and put my skills to the test. While I don't have a lot of knowledge of web development, I do have a basic grasp of PHP, HTML and JavaScript. I can't guarantee of the quality of my work, but I'm willing to help out at any small tasks/projects, so if there is anything you need assistance with, just let me know, and I'll do my best.

     

    Thanks.

  5. Hello.

     

    For the last couple of months I've been learning web development; so far I've gotten the hang of the BASICS of PHP, and HTML, and other languages like JavaScript, SQL, JQuery, etc. and I've managed to produce some very simple websites/apps, but I have absolutely no "real world" experience. I realize I still have a long way to go, but my goal is to break into the industry, and ultimately work as a freelancer. So, I seek your advice. I'd be grateful if someone could just point me in the right direction, and show me where I could get some work experience. Do you perhaps know someone who needs assistance with a small project? I realize I wouldn't be of much use, but I'm willing to practically do anything. The purpose isn't to earn money, - not yet - I simply want to expose myself more to the field. Where could I start?

     

    Thanks.

  6. Also if you only want one result limit the query to 1.

     

    I've tightened up the code a little, like you suggested, and uploaded the program with free hosting, which seems to have eliminated the delay before the message is posted (I'm guessing their database is faster); but that still leaves me with one minor issue: how do I trigger the event to update the chat window whenever a new message is submitted? Currently I'm using intervals, but it seems really inefficient; is there a batter way?

     

    I've thought about fetching all the messages at the start, and then just posting each new message directly to the chat window, so whenever the scroll height of the window would change, I could post the new message into the database right after, but I still haven't attempted it. Would that be a good technique?

  7. I've made a simple jQuery program which retrieves information from a database based on the value of a textbox. The event is triggered on keyup:

     

    $('#textbox').on('keyup', function(){
    	var category = $(this).val();
    	
    	$.get('dbRun.php', {category: category}, function(data){
    		$('#output').html(data);
    	});
    });
    

     

    ...and here's the file that retrieves the data:

     

    <?php
    $linkDB = mysqli_connect('localhost', 'user', '', 'ajax_db');
    
    $queryCategory = mysqli_query($linkDB, "SELECT content FROM site_contents WHERE category = '".$_GET['category']."'");
    echo mysqli_fetch_row($queryCategory)[0];
    ?> 

     

    Unfortunately, it runs pretty slow; I'm guessing it's because every time the event is triggered the database has to re-connect, right? Then how could I run the database connect once, at the start of the program, and make the connection available to the ajax file?

     

    Thanks in advance.

  8. I like to use a templating system like Smarty, but for some reason you don't want to... So...

    You could use a HEREDOC to use one echo statement, and get the returned value of cutContent() before the echo's.

     

    I've just done some research, and changed my mind. I guess using a template engine really would be the best solution. So, this leads me to another question: which template should I use, as a beginner? Smarty seems to be the standard, I gather?

  9. I've always found the task difficult. I use includes and functions wherever I can, but sometimes it seems impossible. Take this code for example:

     

    <div>
    <?php
    	$gotContents = printContents($linkDB, 'home');
    	foreach($gotContents as $k){
    		echo "<div class = \"catContents\">";
    			echo "<div class = \"contentTitle\">".contentTitle($linkDB, $k)[0]."</div>";
    			echo cutContent($k);
    		echo "</div>";
    	}
    ?>
    </div>

    Here, there's no way (that I can see) to separate the HTML from the PHP; I can't divide the code into different files since I need parts of it to be encased in DIVs. So, is this type of code acceptable, or is there a better way to handle it? If so, how?

     

    Thanks in advance for any replies.

     

    EDIT: Also, I'm not interested in using any third-party software/add-on- just raw PHP and HTML please.

  10. So far, I came up with two main approaches -
     
    Option 1: Create an index with an included header and a footer, and require the relevant file/page based on a GET variable.
    Option 2: Create a footer and a header file, and include them on every page.
     
    The problem is, neither of those methods seem to work for me. With option 1, the specified page gets stored in the address, and makes the URLs look not as "clean" - mywebsite.com/index.php?page1. With option 2, the code quickly becomes disorganized.

     

    Advice?

  11. I thought it would be worth mentioning that I think the look of the site is pretty good.

     

    I'm no designer at all (I'm actually rubbish), but looks-wise on my 27" iMac it looks ok. The font isn't great, and I'll explain below, but I would say you have good potential. The guys above don't comment on the design, but I doubt they would say that it's as bad as the code.

     

    The fonts don't show up for me. You have used different fonts but haven't specified them in your CSS. To me the entire site uses the Times New Roman font because I don't have the ones you specified installed. Look at http://css-tricks.com/snippets/css/using-font-face/ for advice. Also, you would be better specifying a list of fallback fonts, so do this instead of just listing one:

     

     
    font-family:Arial, Helvetica, Verdana;
    
    ...that way your browser will use the first font in the list that it supports.

     

    Obviously as the above guys have mentioned it isn't coded great, but you'll definitely get there. You seem to have the right attitude too.

     

    I think time does matter in the long run and I would say something like this site should take about 8-15 hours for an expert. I started learning programming 4-5 years ago and I'm 50 times quicker (literally) now than when I started. Also, as you progress you'll keep snippets of code that you can re-use (e.g. a basic HTML layout which you'll use every time you start a new project).

     

    Personally I would start with a 3 page website, follow Ignace's advice (code structure) and if you ever find yourself cutting and pasting chunks of code then you're probably not doing it right.

     

    Keep at it though and good luck!

    Thanks, John, I'll keep that in mind.

  12. Oh no, it finally loaded after a couple of minutes.

     

    Anyway, I half agree with what ignace said about the time it takes. To start with I would just focus on quality. There are jobs though that will be time critical, or where you're being paid per-hour and they'll not want inexperience costing them more, unless you're upfront about it. Three weeks isn't a very good indication either; how many hours per day did you spend working on it?

     

    In answer to your questions:

     

    1) There's nothing uncommon or unique about that site's functionality, so most freelancers will have a lot of this code laying about for recycling, or they'll use a framework and that kind of thing takes no time at all. Your question has too many variables to give a direct answer.

     

    2) ignace answered this pretty well.

     

    3) HTML & CSS! The site you provided is awful. Not in terms of looks, but adapting to the user's browser. Viewing on my 1366 x 768 monitor, the login and news components on the right side aren't even visible, while there's a huge left margin wasting space. Plus you mentioned IE compatibility issues. How much longer would it take you to convert that website into something production-worthy? You might be surprised how time consuming that kind of thing can be when a client requires it.

     

    4) Beginner.

     

    Thanks for your response. I guess I made the mistake of jumping right in without thinking things through.

     

    Regarding the IE compatibility though, I just found the task too frustrating. I'll give it a shot once I get a better hang of CSS. 

  13. Hello.

     

    I've just finished building my first website, and I'd appreciate some critique. Specifically, I'd like to get some feedback on the code (you can find it on the site, under the Source tab). I do realize it's pretty messy, and of poor quality (and not supported by Explorer), and pretty broken too, but I'd like to hear your opinions nonetheless.

     

    Here it is:       http://www.nocommontheme.co.nf/

     

     

    I also have a couple question, if you don't mind:

     

    • On average, how long would it take a professional web developer/programmer to build a website similar to mine? It took me around 3 weeks; is that too long?
    • Generally, how should I structure my website? As in, what should go in the index, and how do I distribute/divide/link the files?
    • In what areas do I need to improve the most? Organization? :-\
    • Based solely on the code I've wrote, would you call me a beginner, or an intermediate? :sweat:

     

    Sorry if these questions sound a little childish, and thanks in advance for any feedback.

  14. Hello.

     

    I'm having a difficulty with my code and I'd appreciate some assistance.

     

    The below is a poll which is supposed to take user input in the form of radio-boxes and display the amount of users who have selected the given option. On the first run, it works fine, but whenever the page is refreshed, the form resubmits and the vote is entered again. I know this can be easily solved by posting the form information to another page and then redirecting back - and that's how I usually handled the problem in the past - but I'm wandering if there's a better way. Anybody got any ideas? Thanks in advance.

     

    <!--start of poll-->
    		<div id = "fullPoll"><!--POLL FORM-->
    			<?php
    			printRibbon('pollTag', 'Poll:' , 55, -30, 0, 20);
    				include 'sitePoll.php';
    				
    					if(isset($_POST['option'])){//RADIOBOX
    						if(!empty($_POST['option'])){
    							$chosenOption = $_POST['option'];
    						
    							$queryVotes = mysql_query("SELECT ".$chosenOption." FROM sitepoll");
    							$currentVotes = mysql_result($queryVotes, 0);
    							$updateVotes = $currentVotes + 1;
    						
    							mysql_query("UPDATE sitepoll SET ".$chosenOption." = '".$updateVotes."'");
    							header('Location: /No Common Theme/activeSourceTabLink.php');
    						}else{
    							?>
    						<div class = "errorsDiv">
    							Choose an option, Scrub.
    						</div>
    						<?php
    							
    						}
    					}
    					
    					
    			?>
    		</div>
    		<!--end of poll-->
    

     

     

  15. What is "correctly" supposed to be? How does it look now and how do you want it to look?

     

    At the moment the images are positioned in a single, straight, vertical column, with no spaces in between them. I'd like them, however, to run left to right, skipping to the next line once there's no more space, with some space separating them; like a typical grid layout.

  16. I have several images in a directory, which I would like to output(in an organized way) to the page. I've tried reading all the directory contents, and loading their names into an array to display the images using HTML, but I can't for the life of me figure out how to then position the pictures correctly in CSS.

     

    Here's the code:

     

    <?php
    $dirLoc = 'myWebsite/galleryPics';
    $handle = opendir($dirLoc);
    
    
    while($readDir = readdir($handle)){
    if($readDir != '.' && $readDir != '..'){
    $pic[] = $readDir;
    }
    }
    
    
    foreach($pic as $k){
    echo "<div class = \"picsDiv\">";
    echo "<img src = \"$dirLoc/$k\" height = \"100px\" width = \"100px\"/></div>";
    }
    ?>
    
    
    <html>
    <head>
    <style type = "text/css">
    
    .picsDiv {width:150px;
     height:150px;
     border:1px solid red;
     background-color:grey;}
    
    img {position:relative;
     top:50%;
     left:50%;
     margin-top:-50px;
     margin-left:-50px;}
    </style>
    </head>
    </html>
    

     

    Thank you in advance for any feedback.

  17.  

    Thanks for replying.

     

    Sorry, I'm still relatively new to programming. Would something like this be adequate?

     

    <?php
    $string = 'Hello!';
    $verifyString = array('checkLength' => NULL, 'checkMatch' => NULL);
    
    
    if(strlen($string) >= 10){
    $verifyString['checkLength'] = 'Input Too Long!';
    }
    if($string != 'Hello!'){
    $verifyString['checkMatch'] = 'Wrong Input!';
    }
    
    
    
    if($verifyString['checkLength'] == NULL && $verifyString['checkMatch'] == NULL){
    echo 'Logged In!';//continue on...
    }else{
    if($verifyString['checkLength'] != NULL){
     echo $verifyString['checkLength'];
    }
    if($verifyString['checkMatch'] != NULL){
     echo $veryString['checkMatch'];
    }
    }
    ?>
    

  18. Hello.

     

    Recently, I've been learning about registration forms in PHP, and I'm wandering how I could improve the one I've already written(this is only an excerpt, obviously):

     

    if(!empty($username) &&
    !empty($password) &&
    !empty($re_password) &&
    !empty($firstname) &&
    !empty($lastname)){
    
    
    if($password === $re_password){
    $query_run = mysql_query("SELECT username FROM users WHERE username = '$username'");
    if(mysql_num_rows($query_run)==1){
    echo 'User '."<strong>".$username."</strong>".' Already Exists!';
    }else{
    mysql_query("INSERT INTO users VALUES ('','".mysql_real_escape_string($username)."','".mysql_real_escape_string($hashed_password)."','".mysql_real_escape_string($firstname)."','".mysql_real_escape_string($lastname)."')");
    
    header('Location: my119file.php?pass_username='.$username);
    }
    }else{
    echo 'The Re-Entered Password Doesn\'t Match';
    }
    }else{
    echo 'Please Fill Out All The Fields';
    }
    }
    }else{
    echo 'You\'re already logged in';
    }
    

     

    I'm mainly concerned about the fact that, if the user inputs invalid information into the fields, he will only be notified of the first error encountered; if there happen to be multiple errors with the filled-out information, the user will not know until the first error is solved. For instance, if the user omits one of the required fields, AND the "confirm password" does't match, only the "Please Fill Out All The Fields" error will be displayed, and the "Password Don't Match" error will be ignored until the first issue is resolved. I would much rather prefer if the form recognized all errors in a single run, but I'm not sure how to do that...

     

    Any ideas?

     

    Thanks.

  19. Hello.

     

    I'm having trouble understanding the below code:

     

    <?php
    $dirName = 'secondDir';
    $handle = opendir($dirName);
    
    
    while($printFiles = readdir($handle)){
    if($printFiles != '.' && $printFiles != '..'){
     echo "<a href = '".$dirName.'/'.$printFiles."'>".$printFiles."</a></br>";
    }
    }
    closedir($handle);
    ?>
    

     

     

    Specifically, it's the if statement that's giving me a hard time. I know what it is, and I know what it does, but I don't understand the logic behind the condition; how does it work to remove the dots before the file list? Are the dots part of the readdir structure? If they are, then how come they can be removed by asking to print out a file list IF they aren't a part of it?

     

    I'm not sure if I am making any sense, but if anybody understands, could you please explain this to me?

     

    Thanks.

  20. Try again fopen

     

     

     

    Hint: If you want to read data from a file, you need to start somewhere before the end of all of the data in the file.

     

    And, since you are not writing to the file in that code, you don't need to open it "for writing", just "for reading"

     

    Right, that's a stupid mistake on my part. Works fine now, though. Thanks.

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