Jump to content

Recreational_Champ

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Posts posted by Recreational_Champ

  1. Thanks for moving the post:  I noticed I had posted in the wrong spot after submission.

     

    I have solved my problem!!!

     

    forget about symbolic links and just update .bash_login(or whatever your file name might be)

     

    #path is now set to MAMP mysql server and as a default I have added my other path as well
    export PATH="/Applications/MAMP/Library/bin:/usr/local/mysql/bin:$PATH"

     

    I understand that I can opt to run the two servers on different ports and just specify which mysql I want by that means instead, but I haven't tried that yet. ;D

     

     

     

  2. Hello~

     

    I have two mysql servers running on my computer, the one I installed by itself and the one that came packaged with MAMP.

     

    I have created a path in a file called .bash_login:

     

    export PATH="/usr/local/mysql/bin:$PATH"  and I am not quit sure why this path is set as such because mysql_sock is located in /tmp.

     

    I want to be able to run the MAMP mysql server from the cli and know that I can create a sym link to accomplish this task:

     

    sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

     

    If I create the sym link will I be able to run the mysql server packed with mamp from cli?

     

    What will be the effects on the current mysql server?

     

    What is mysql looking for to actually run?

     

    If I have supplied enough information, could you help me understand what is going on here.

     

    I would also be happy to keep everything as is and do something like:

     

    mysql -u 'user' -h '/path/to/mamp_mysql_file' -p, but still want to understand whats going on.

     

  3. What makes you think there is a efficient way?  Is your script slow?  Does it look bad?  What is the reason for you posting here?  Do you have any theoretical ideas that you think may be better?

     

    Sorry for not specifying exactly what I was trying to accomplish;  I really thought the code was short and strait forward enough to follow without explanation. 

     

    I don't just want to code for a solution, but code in the most efficient way as possible.  I feel as though my solutions are elementary in their structure and do think that it looks "bad" to have repetitive processes. 

     

    Yes.

     

    ...or were you really asking for someone to rewrite your code for you?

     

    I guess I kinda wanted for someone to post a solution :( not because I wanted it done for me, but to understand what I could do to improve my self in the future

     

    Those 9 queries (3 sets of 3) could be reduced to single query, if that's what you mean, by using a query similar to your first one, joining answers with log, querying by question_id and grouping counts by answer_id

     

    YES! YES! YES!  That is the solution I was looking for:

     

    select logs.answer_id, count(*) from logs,answers where answers.question_id=$_GET['variable'] and logs.answer_id=answers.answer_id group by answer_id 
    

     

    I had yet to discover grouping  ;D

     

    Thank you so very much for your time!

  4. I would like to know if there is a more efficient way than what I already have.

    <?php
    $ip = gethostbyaddr($_SERVER['REMOTE_ADDR']);
    require_once ('mysql_connect.inc.php');
    $query = "INSERT INTO logs VALUES(NULL,{$_GET['a_id']},'$ip',NULL)";
    mysql_query($query) or die("Not inserted". mysql_error()); 
    
    $query = "SELECT * FROM answers,logs where answers.question_id={$_GET['q_id']} and logs.answer_id=answers.answer_id"; 
    $result = mysql_query($query) or die('Error, query failed');
    $num_rows = mysql_num_rows($result);
    
    
    $sum_1;
    $sum_2;
    $sum_3;
    
    
    if($_GET['q_id'] == 1)
    {
    $query = "SELECT COUNT(answer_id) AS times_chosen FROM logs where answer_id=1";
    $result = mysql_query($query) or die('Error, query failed');
    $row = mysql_fetch_array($result);
    $sum_1 = $row['times_chosen'];
    
    $query = "SELECT COUNT(answer_id) AS times_chosen FROM logs where answer_id=2";
    $result = mysql_query($query) or die('Error, query failed');
    $row = mysql_fetch_array($result);
    $sum_2 = $row['times_chosen'];
    
    $query = "SELECT COUNT(answer_id) AS times_chosen FROM logs where answer_id=3";
    $result = mysql_query($query) or die('Error, query failed');
    $row = mysql_fetch_array($result);
    $sum_3 = $row['times_chosen'];
    }
    if($_GET['q_id'] == 2)
    {
    $query = "SELECT COUNT(answer_id) AS times_chosen FROM logs where answer_id=4";
    $result = mysql_query($query) or die('Error, query failed');
    $row = mysql_fetch_array($result);
    $sum_1 = $row['times_chosen'];
    
    $query = "SELECT COUNT(answer_id) AS times_chosen FROM logs where answer_id=5";
    $result = mysql_query($query) or die('Error, query failed');
    $row = mysql_fetch_array($result);
    $sum_2 = $row['times_chosen'];
    
    $query = "SELECT COUNT(answer_id) AS times_chosen FROM logs where answer_id=6";
    $result = mysql_query($query) or die('Error, query failed');
    $row = mysql_fetch_array($result);
    $sum_3 = $row['times_chosen'];
    }
    if($_GET['q_id'] == 3)
    {
    $query = "SELECT COUNT(answer_id) AS times_chosen FROM logs where answer_id=7";
    $result = mysql_query($query) or die('Error, query failed');
    $row = mysql_fetch_array($result);
    $sum_1 = $row['times_chosen'];
    
    $query = "SELECT COUNT(answer_id) AS times_chosen FROM logs where answer_id=8";
    $result = mysql_query($query) or die('Error, query failed');
    $row = mysql_fetch_array($result);
    $sum_2 = $row['times_chosen'];
    
    $query = "SELECT COUNT(answer_id) AS times_chosen FROM logs where answer_id=9";
    $result = mysql_query($query) or die('Error, query failed');
    $row = mysql_fetch_array($result);
    $sum_3 = $row['times_chosen'];
    }
    
    
    
    
    $percent_1 = ($sum_1 / $num_rows) * 100;
    $percent_2 = ($sum_2 / $num_rows) * 100;
    $percent_3 = ($sum_3 / $num_rows) * 100;
    
    mysql_free_result($result);
    mysql_close($connection);
    
    
    
    ?>
    

  5. Well, thats all that I have on that page --which works well alone. 

     

    It will be a graph based on poll results and I want to display other other php/html code next to that image.

     

    <?php
    header ("Content-type: image/png");
          
    $cavas = imagecreate(300,300);
    $gray = imagecolorallocate ($cavas,0xcc,0xcc,0xcc);
    $white = imagecolorallocate ($cavas,0x33,0x33,0x33);
    $light_purple = imagecolorallocate ($cavas,943,387,453);
    $color = imagecolorallocate ($cavas,'abc',123,956);
    
    imagefilledrectangle($cavas,0,0,40,70,$white);
    imagefilledrectangle($cavas,0,80,20,160,$light_purple);
    imagefilledrectangle($cavas,0,170,70,250,$color);
       
    imagepng($cavas);
    ?>
    <html>
    <h2>Poll results:</h2>
    </html>
    

     

     

    make sense?

  6. <?php
    header ("Content-type: image/png");
    
    $cavas = imagecreate(300,300);
    $gray = imagecolorallocate ($cavas,0xcc,0xcc,0xcc);
    $white = imagecolorallocate ($cavas,0x33,0x33,0x33);
    $light_purple = imagecolorallocate ($cavas,943,387,453);
    $color = imagecolorallocate ($cavas,'abc',123,956);
    
    imagefilledrectangle($cavas,0,0,40,70,$white);
    imagefilledrectangle($cavas,0,80,20,160,$light_purple);
    imagefilledrectangle($cavas,0,170,70,250,$color);
    
    imagepng($cavas);
    ?>

     

     

    How can I add that image that I created to an existing page without header errors?

  7. Hello all~  I have made a php game printing out images using a multidimensional array stored within a session variable named 'board.'  I am having quite some time trying to navigate the current state of my player. 

     

    <form action="this.php" method="get" accept-charset="utf-8">
    <input type="submit" name="right" value="→">
    <input type="submit" name="left" value="←">
    <input type="submit" name="up" value="↑">
    <input type="submit" name="down" value="↓">
    <input type="submit" name="reset" value="reset;">
    </form>
    

     

     

    if(isset($_GET['right']))
    {
    $dir = "right";
    move($dir);
    }
    if(isset($_GET['left']))
    {
    $dir = "left";
    move($dir);
    }
    if(isset($_GET['up']))
    {
    $dir = "up";
    move($dir);
    }
    if(isset($_GET['down']))
    {
    $dir = "down";
    echo "$dir";
    }
    if(isset($_GET['reset']))
    {
    session_destroy();
       setcookie(session_name(),"", time() - 3600);
       $_SESSION=array();
    echo "reset";
    

     

     

    Now, I can move the player in any direction I choose, but I have to hit the submit button "twice" to get the player to move only after I have moved in a different direction. 

     

    Example:

     

    New session started, player in a random position...

     

    Try to navigate player up/down/left/right and it will move in the direction I last clicked "once" before moving the current selection... even when cookies/sessions have been cleared.

     

    Somehow the submit GET status retains last moved state;  I am one click behind and cannot figure it out

     

     

    My move() is working just fine!  Problem occurs when I submit reset as well.

     

     

    A walk through would be very helpful :)

     

    Thanks

  8. I would like to traverse images in my array by using form buttons for navigation i.e. up, down, left, or right.

     

    I have:

     

     

    <form action="<?php $_SERVER['PHP_SELF'] ?>" method="get" accept-charset="utf-8">

     

    <p>

    <input type="submit" name="right" value="right">

    <input type="submit" name="left" value="left">

    <input type="submit" name="up" value="up">

    <input type="submit" name="down" value="down">

    <input type="submit" name="reset" value="reset">

    </p>

    </form>

     

     

     

    What code would be required so that if the submit button right is pressed I would be able to call a function that does things every time right is pressed ?

     

    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.