Jump to content

phpuserlogin

Members
  • Posts

    41
  • Joined

  • Last visited

Posts posted by phpuserlogin

  1. <?php
    
    # Set page title and display header section.
    $page_title = 'database' ;
    include ( 'includes/header.html' ) ;
    
    # Open database connection.
    require ( 'connect_db.php' ) ;
    
    # Display body section, retrieving from 'forum' database table.
    $q = "SELECT * FROM forum" ;
    $r = mysqli_query( $dbc, $q ) ;
    if ( mysqli_num_rows( $r ) > 0 )
    {
      echo '<table>';
      while ( $row = mysqli_fetch_array( $r, MYSQLI_ASSOC ))
      {
        echo '
        <td>' . $row['subject'] . '</td> </tr>';
      }
      echo '</table>' ;
    }
    else { echo '<p>There are currently no messages.</p>' ; }
    
    # Close database connection.
    mysqli_close( $dbc ) ;
      
    # Display footer section.
    include ( 'includes/footer.html' ) ;
    
    ?>

    I've updated it, so it just displays the words in the subject row from the sql.

    So Playstation 2 model no would be selected from the actual subject row, via link, and a drop down menu would be the select method.

    I've solved the display of the data.

    How do I create a link to select subject row or what ever.

     

  2. <?php
    
    # Set page title and display header section.
    $page_title = 'database' ;
    include ( 'includes/header.html' ) ;
    
    # Open database connection.
    require ( 'connect_db.php' ) ;
    
    # Display body section, retrieving from 'forum' database table.
    $q = "SELECT * FROM forum" ;
    $r = mysqli_query( $dbc, $q ) ;
    if ( mysqli_num_rows( $r ) > 0 )
    {
      echo '<table><tr><th>Posted By</th><th>Subject</th>';
      while ( $row = mysqli_fetch_array( $r, MYSQLI_ASSOC ))
      {
        echo '<tr><td>
        <td>' . $row['subject'] . '</td><td>' . '</td> </tr>';
      }
      echo '</table>' ;
    }
    else { echo '<p>There are currently no messages.</p>' ; }
    
    # Close database connection.
    mysqli_close( $dbc ) ;
      
    # Display footer section.
    include ( 'includes/footer.html' ) ;
    
    ?>

     

    displayfromeditsql.jpg

  3. $q = "SELECT * FROM forum" ;
    $r = mysqli_query( $dbc, $q ) ;
    if ( mysqli_num_rows( $r ) > 0 )
    {
      echo '<table><tr><th>Posted By</th><th>Subject</th><th id="msg">Message</th></tr>';
      while ( $row = mysqli_fetch_array( $r, MYSQLI_ASSOC ))
      {
        echo '<tr><td>' . $row['first_name'] .' '. $row['last_name'] . '<br>'. $row['post_date'].'</td>
        <td>' . $row['subject'] . '</td><td>' . $row['message'] . '</td> </tr>';
      }
      echo '</table>' ;
    }

    So row Posted by, do I make a link in order to select that column, or use a drop down. to select a specific row for the data. Posted by is just an example. Record data 1, a very basic example is just what I'm trying to tinker with, with this code. Subject and so on.

  4. <?php
    
    # Set page title and display header section.
    $page_title = 'database' ;
    include ( 'includes/header.html' ) ;
    
    # Open database connection.
    require ( 'connect_db.php' ) ;
    
    
    $q = "SELECT * FROM forum" ;
    $r = mysqli_query( $dbc, $q ) ;
    if ( mysqli_num_rows( $r ) > 0 )
    {
      echo '<table><tr><th>Posted By</th><th>Subject</th><th id="msg">Message</th></tr>';
      while ( $row = mysqli_fetch_array( $r, MYSQLI_ASSOC ))
      {
        echo '<tr><td>' . $row['first_name'] .' '. $row['last_name'] . '<br>'. $row['post_date'].'</td>
        <td>' . $row['subject'] . '</td><td>' . $row['message'] . '</td> </tr>';
      }
      echo '</table>' ;
    }
    else { echo '<p>There are currently no messages.</p>' ; }
    
    # Close database connection.
    mysqli_close( $dbc ) ;
      
    # Display footer section.
    include ( 'includes/footer.html' ) ;
    
    ?>

    I would like to select one row list of the following. As this old example displays a bunch of rows, so a drop down menu would individual select one item from the sql. Can I do that with this example, is it complicated to do so?

     

     

    displayfromdatabase.jpg

  5. The tutorial starts out by displaying this code.

    <!DOCTYPE html>
    <html>
    <div style='background-color:gold; width:640px;'>
    <canvas id="gameCanvas" width="640" height="480"></canvas>
    </div>
    <div style='display:none;'>
    <img id='dog' src='smuffy.png'>
    <img id='donut' src='donut.png'>
    </div>
    <script>
    </script>
    </html>

    I forgot html at the top there, but that doesn't change the result.

    Then the next code part is this.

    var ctx=gameCanvas.getContext("2d");
       var x=[100,300,500];
       var y=[0,0,0];	 
       var speed=[2,1,3];
       var dogX=300, changeX=0, score=0;
    
       var gameTimer=setInterval(mainloop,20);
       function mainloop() {
         ctx.clearRect(0,0,640,480);
    	ctx.font="30px Arial";
    	ctx.fillText("Score: "+score,10,30);
            for(var n=0; n<3; n++){
    	ctx.drawImage(donut,x[n],y[n],50,50);
    	y[n]+=speed[n];
    	checkForHits();
    	if(y[n]>400){
    	y[n]=-80; x[n]=Math.random()*600;
     }
    
    }
    
    ctx.drawImage(dog,dogX,400,60,60);
    dogX+=changeX;
    }
    </script>
    </htm>

    Exactly as shown in the book, so you just remove or add the exact code and don't include the two tags below

     a section on arrays to do with the objects, essentially what the code does.

    Then it says to check F12 for any bugs. Gives an example of the word snuffy as smffy, but obviously there is no error of that sort.

    Then the next page,

    move the player code,

    document.onkeydown=keyPressed;
        function keyPressed(e){
        var k=e.keyCode;
        if(k==37){changeX=-4;}
        if(k==39){changeX=4;}
    }

    Then the next part below is check for Hits.

    function checkForHits(n) {
       if((Math.abs(400-y[n])<60)&&
       (Math.abs(dogX-x[n])<60)){
       score+=1;
       y[n]=-80; x[n]=Math.random()*600;
       }
    }

    I didn't include the sound file, I don't think that would matter. bleep.play above the first curly

     

    The the last is Gameover

     setTimeout(gameover,30000);
       function gameover(){
       clearInterval(gameTimer);
       ctx.font="80px Arial";
       ctx.fillText("Game Over!",100,250);
    
    }       

    You know better than I do, the game sort of works, but the check hits section doesn't register a touch with the object and player.

  6. If added with this code, what happens?

     

     setTimeout(gameover,30000);
       function gameover(){
       clearInterval(gameTimer);
       ctx.font="80px Arial";
       ctx.fillText("Game Over!",100,250);
    
    }       
    </script>
    </html>

     

  7. <!DOCTYPE html>
    <div style='background-color:gold; width:640px;'>
    <canvas id="gameCanvas" width="640" height="480"></canvas>
    </div>
    <div style='display:none;'>
    <img id='dog' src='smuffy.png'>
    <img id='donut' src='donut.png'>
    </div>
    <script>
       var ctx=gameCanvas.getContext("2d");
       var x=[100,300,500];
       var y=[0,0,0];	 
       var speed=[2,1,3];
       var dogX=300, changeX=0, score=0;
    
       var gameTimer=setInterval(mainloop,20);
       function mainloop() {
         ctx.clearRect(0,0,640,480);
    	ctx.font="30px Arial";
    	ctx.fillText("Score: "+score,10,30);
            for(var n=0; n<3; n++){
    	ctx.drawImage(donut,x[n],y[n],50,50);
    	y[n]+=speed[n];
    	checkForHits();
    	if(y[n]>400){
    	y[n]=-80; x[n]=Math.random()*600;
     }
    
    }
    ctx.drawImage(dog,dogX,400,60,60);
    dogX+=changeX;
    }
        document.onkeydown=keyPressed;
        function keyPressed(e){
        var k=e.keyCode;
        if(k==37){changeX=-4;}
        if(k==39){changeX=4;}
    }

    Does this code work?

    function checkForHits(n) {
       if((Math.abs(400-y[n])<60)&&
       (Math.abs(dogX-x[n])<60)){
       score+=1;
       y[n]=-80; x[n]=Math.random()*600;
       }
    }
    </script>
    </html>

     

    Thanks

    donut.png

    smuffy.png

  8. Hello,

    I tried this code in a game, but doesn't do anything.

    if(score>highScore){
    localStorage.setItem('highScore',score);
    var highScore=0, loc=localStorage.getItem('highScore');
    if(loc>0)highScore=loc;

    The bottom would be added after var variables.

    And the top is for the Game over part of the game.

    ctx.fillText("High Score: "+HighScore,400,20);
      }

    This would go in a Function Check for Hits, at the very end

  9. I have gone further, and still no change.

    <html>
    <audio id='endMp3' src='https://maxw.com/low.mp3'></audio>
    <audio id='endMp3' src='https://maxw.com/high.mp3'></audio>
    <div style='background-color:blue; height:480px; width:640px;'>
       <canvas id="gameCanvas" width="640" height="480"></canvas>
    </div>
    <script>
    var ctx=gameCanvas.getContext("2d");
    var x=240, y=180, dir=90, score=0;
    drawBackground();
    function drawBackground(){
       ctx.strokeStyle='orange';
       ctx.lineWidth=40;
       ctx.strokeRect(0, 0, 640, 480);
    }
    var gameTimer=setInterval(mainLoop, 50);
    function mainloop(){
       ctx.fillstyle='orange';
       ctx.fillRect(x,y,9,9);
       if(dir==90){x+=10;}
       if(dir==180){y+=10;}
       if(dir==-90){x-=10;}
       if(dir==0){y-=10;}
       //checkpixelcolor();
       score++;
       ctx.fillRect(0,0,100,20);
       ctx.fillStyle='black';
       ctx.font="20px Arial";
       ctx.fillText("Score: "+score,2,16);
    }
    function checkPixelcolor(){
       var col=ctx.getImagedata(x,y,1,1).data;
       if(col[3]!=0){
       endMp3.play();
       clearInterval(gameTimer);
       ctx.font="80px Arial";
       ctx.fillText("Game Over!",100,250);
      }
    }
    </script>
    <html>

    If I changed one of the Style from capital to low, the border changes black instead of orange. So I don't know what exactly is going on.

  10. <html>
    <div style='background-color:blue; height:480px; width:640px;'>
       <canvas id="gameCanvas" width="640" height="480"></canvas>
    </div>
    <script>
    var ctx=gameCanvas.getContext("2d");
    var x=240, y=180, dir=90, score=0;
    drawBackground();
    function drawBackground(){
    ctx.strokeStyle='orange';
    ctx.lineWidth=40;
    ctx.strokeRect(0, 0, 640, 480);
    }
    var gameTimer=setInterval(mainLoop, 50);
    function mainloop(){
    ctx.fillStyle='orange';
    ctx.fillrect(x,y,9,9)
    if(dir==90){x+=10;}
    if(dir==180){y+=10;}
    if(dir==-90){x-=10;}
    if(dir==0){y-=10;}
    //checkpixelcolor();
    score++;
    ctx.fillRect(0,0,100,20);
    ctx.fillStyle='black';
    ctx.font="20px Arial";
    ctx.fillText("Score: "+score,2,16);
    }
    </script>
    <html>

    Hi, I typed the following out, and it should load this or this is what is loads. It should load more graphics, but it doesn't.

    Where has it gone wrong?

    gamecanvas.jpg

  11. I bought this book as it was aimed at a beginner, the code has worked for you without any errors, you can obviously work out what is wrong with the above, I noticed I didn't put a space with the function moveMeteors

    It has errors from the beginning?

    Current errors are on

    document.onkeydown=keyPressed; this isn't defined.

    checkForHits(n);

    moveMeteors();

    if(math.abs(x[n]<50)&&

  12. There is no code to paste, I typed it out of the examples in the book.

    I even tried this game after the fish one.

    functionmoveMeteors(){

    This appears to be the error in the console.

    <!doctype html>
    <style>
    div{width:640px; height:480px;
        background:url('stars.png');}
    img{display:block;}
    </style>
    <div>
    <canvas id="gameCanvas" width="640" height="480"></canvas>
    </div>
    <Img id='rocket' src='rocket.png'>
    <img id='meteor'src='meteor.png'>
    <script>
    var ctx=gameCanvas.getContext("2d");
    var x=[600,600,600,600,600];
    var y=[0,100,200,300,400];
    var speed=[-1,-2,-0.5,-1.2,-1.8];
    var rocketY=200, changeY=0, score=0;
    
    var gameTimer=setInterval(mainLoop, 10);
    function mainLoop(){
    moveMeteors();
    MoveRocket();
    }
    functionmoveMeteors(){
    	ctx.clearRect(0,0,640,480);
    	for(var n=0; n<5; n++){
            ctx.drawImage(meteor,x[n],y[n],80,80);
    	x[n]+=speed[n];
    	checkForHits(n);
    	if(x[n]<-80){
    	    x[n]=640; y[n]=Math.random()*400;
    	}
        }
    }
    function moveRocket(){
    	ctx.drawImage(rocket,10,rocketY,80,80);
    	rocketY+=changeY;
    	score+=1;
    	ctx.fillstyle="yellow";
    	ctx.font="30px Arial";
    	ctx.fillText("score: "+score, 10, 30);
    	if((rocketY<0)||(rocketY>400)){changeY=0;}
    }
    document.onkeydown=keyPressed;
    function keypressed(e){
        var k=e.keyCode;
        if(k==38){changeY=-3;}
        if(k==40){changeY=-3;}
    }
    function checkForHits(n){
        if(math.abs(x[n]<50)&&
              (math.abs(rocketY-y[n]<50)){
    	  clearInterval(gameTimer);
    	  ctx.font="80px Arial";
    	  ctx.fillText("Game Over!",100,250);
    	}
        }
    </script>
    </html>

     

    rocket.png

    meteor.png

    stars.png

  13. I didn't know the above. The closest I have tried to programming was some blender bricks, and Visual basic, a very long time ago, and python. I'm not a programmer. I bought this book since it was aimed at a beginner audience, I thought why not. The book doesn't even state this as guide.

    So why doesn't the fish image not move with the mouse, I have changed the error, so it should work? I have typed it out with errors or is the book wrong on some of the code, could there be errors in it? I'm guessing I'm the one that has made them. Four games, and only the balloon one has worked so far. The other, tennis, catch and then donuts, and then fish dodging pipes have errors of some sort.

  14. var gameTimer=setInterval(mainLoop, 10);
    document.onKeydown=function(){
    ySpeed=-2;
    }

    Not sure.

    Quote

    Press any key on the keyboard to make the fish jump. How many pipes can the fish jump through?

    Step 15. Which is the last. The code is on the next page in total. The only other info is change some of the code to make it quicker or change the pipe positions.

×
×
  • Create New...