Jump to content

alexdemers

Members
  • Posts

    65
  • Joined

  • Last visited

    Never

Posts posted by alexdemers

  1. I think LOAD DATA INFILE is only to populate tables and not a database. According to MySQL :: MySQL 5.1 Reference Manual, it seems that "INTO TABLE tbl_name" is a requirement. So, change your file/query to that accordingly.

     

    So: mysql_query("LOAD DATA INFILE '$absolutePath/install/import/tables.sql' INTO TABLE tbl_name");

     

    If you want to import the whole SQL file, then I'd suggest to use the mysql cli:

     

    mysql -p -h DBserber DBname < tables.sql

  2. If it's 1 pixel large, stretching it is the best option. If, let's say you have hearts (like in Zelda), then you would need to repeat it using a simple for loop:

     

    <?php
    $lives = 4;
    
    for ( $i = 0; $i < $lives; $i++ ) {
        echo '<img src="/images/heart.png" alt="<3" /> ';
    }
    
    ?>

     

  3. Hey,

     

    unfortunately this cannot be possible. The only things returned from forms submition is the value of a named element (select, input, textarea). In this case, the only thing returned is, you're correct, the ID of the person.

     

    Now there's 2 options.

     

    First, once your form has been submitted, you can get the value of the select: $_GET['vVol_id'] (obviously) and query your database to get the person's name.

     

    The other option is to do it with JavaScript. Create a hidden input element in HTML: <input id="vVol_name" type="hidden" name="vVol_name" value="" /> and when you submit the form, fill in the value with the selected name of the <select> element. Now in PHP you can do: $_GET['vVol_name']

     

    For the second option, if you are using jQuery (I'm more fluid in that framework):

     

    <script type="text/javascript">
    $('form#myForm').submit(function(){
        var personName = $('select#vVol_id :selected').text();
        $('input#vVol_name').attr('value', personName);
        return true;
    });
    <script>
    

     

  4. Oh one final point, is there a way I can let a user upload any jpeg but it will be resized? Or is it best to just state the height and width the image should be in the html, and will just fit it in somehow?

     

    Having the full size image resize to a much smaller size is HIGHLY not recommended. This really adds up to the page loading. In that case, you should create thumbnails of images uploaded and store them in a separate folder (eg. /thumbs/). Creating thumbnails is a bit complex (not too much) because it's different function calls depending on the type of images. Luckily in your case it's only JPEG. So, take a look at: How to Create Thumbnail Images using PHP which covers what I'm too lazy to type in this post.

     

    Also note, in that link the author's script is to convert every image in one folder at once which is not what you want, but it's the same function calls. Only the logic changes.

  5. Well, you have a lot of errors in that script. First, it only get the rows 1 time since you don't have any sort of loops. Second, there's a parse error: "case"$add; which should be concatenated with a dot:  "case".$add; Third, you try to select the table with its name surrounded in quotes. Remove the quotes after FROM.

     

    Here's a much better code. But, right now, every loops overwrites the variable $newcase which you should handle to your likings.

     

    <?php
    $mysqli = new mysqli("localhost", "username", "pasword", "cases");
        if ($mysqli === false) {
          die("ERROR: Could not connect to database. " . mysqli_connect_error());
    }
    
    $sql = "SELECT * FROM cases";
    $count = 0;
    $result = $mysqli->query($sql);
    
    while ($row = mysqli_fetch_array($result)) {
        $count++;
        echo $count;
        $newcase = 'case'.$count;
    }
    
    // die("ERROR: Could not execute query: $sql. " . $mysqli->error);
    ?>

  6. Hey,

     

    if they are stored as BLOB (Binary), my best bet is to do a separate script (let's say get_image.php?id=xxx) and pass in the ID of the item:

     

    <?php echo '<img src="get_image.php?id='.$row['item_id'].'" />'; ?>

     

    And get_image.php will go get the image in the database according to the item ID passed in.

     

    This works pretty good in all browsers (maybe won't will very old one).

     

    Make sure to set the header accordingly:

    <?php header('Content-type: image/jpeg'); ?>

  7. I can't provide you the code to do all of that but here are some of the basics:

     

    This is a good read to handle file uploads: PHP: POST method uploads - Manual

     

    While handling your file, you can check it it's a JPEG with:

     

    <?php
    $file = explode('.', $_FILES['user_picture']);
    $ext = end($file);
    
    if ($ext === 'jpg' || $ext === 'jpeg')
    {
    echo 'Your file is a JPEG format';
    }
    else
    {
    // Do what you wanna do here
    }
    ?>

     

    Getting the image size once it's in a folder/uploaded: PHP: getimagesize - Manual

     

    And for checking the file if it exists, I would recommend to check it before invoking the move_uploaded_file() function when handling file uploads. Use PHP: file_exists - Manual to check if your file already exists, if it does, delete the old one (PHP: unlink - Manual) and then invoke move_uploaded_file() to that directory.

     

    A resumé:

    [*]Create the HTML for file upload

    [*]Retrieve files in PHP

    [*]Error handling (not covered in my post)

    [*]Check if it's a JPEG

    [*]Check if the file exists; if not, move_uploaded_file; if it exists, delete old one, then move_uploaded_file

    [*]Get the image size

     

    Hope that clarifies your mind.

     

     

    Of course, I HIGHLY recommend error handling and other things to consider like thumbnails creation and others.

  8. I'll specify that I need the content of everything inside every different div tag with the id name like I specified.

     

    Example:

     

    Array
    (
        [0] => "content of <div id="id1"></div>"
        [1] => "content of <div id="id2"></div>"
        [2] => "content of <div id="id3"></div>"
        [3] => "content of <div id="id4"></div>"
    )
    

     

    Thanks again

  9. Hi,

     

    I just want to extract ALL the content from a specific tag with a specific ID. Here's the sample of the HTML:

     

    There are alot of id+integer on the page.

    <div id="id1">all the tags and text in here</div>
    <div id="id2">all the tags and text in here</div>
    <div id="id3">all the tags and text in here</div>
    

     

    Here's my preg_match_all function:

    preg_match_all ('<div id=\"id(?:[\d]+)\">(.*)<\/div>/ism', $str, $r);
    echo '<pre>';
    print_r ($r);
    

     

    The first sub pattern is to catch all the id with an integer (ie: id1, id2, id3 ... ) ... no trouble there

    Then I want to get ALL the text and HTML between the "div" tags. For some reason, it doesn't stop and match at the first </div>. It continues to get all the content before reaching THE LAST "</div>".

     

    This has been an issue for the past 2 hours. I can't get it to work. Maybe anyone can help me? 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.