Jump to content

Jenk

Members
  • Posts

    778
  • Joined

  • Last visited

    Never

Posts posted by Jenk

  1. He might be using it for use in a query builder.. such as this method:
    [code]<?php

    public function parseQuery()
    {
        $num = func_num_args();
        if ($num == 1)
        {
            $this->_query = func_get_arg(0);
        }
        elseif ($num > 1)
        {
            $query = func_get_arg(0);
            for ($i = 1; $i < $num; $i++)
            {
                $arg = $arg = mysql_real_escape_string(func_get_arg($i), $this->_link);
                if (!is_numeric($arg))
                {
                    $arg = "'" . mysql_real_escape_string($arg, $this->_link) . "'";
                }
                $query = str_replace(':' . $i, $arg, $query);
            }
            $this->_query = $query;
        }
        else
        {
            throw new InvalidArgumentException('Must provide a query to be parsed!');
        }
    }

    ?>[/code]

    usage..

    [code]<?php

    $db->parseQuery('SELECT * FROM `table` WHERE `col` = :1 AND `col2` = :2', $colVal, $col2Val);

    ?>[/code]
  2. Just a note.. this method of storage (delimeted list) is looked upon as 'sloppy' because, well, it is sloppy.

    Use a table to store all the users entries with a foreign key for the user id and a foreign key for the book details. Essentiall 3 columns: index, userid, bookid.

    Then select the rows from that table, with joins on users and books if necessary. It will be MUCH more efficient.
  3. [quote author=recset link=topic=107280.msg430332#msg430332 date=1157688533]
    The database record just shows 'Array', but doesn't display what is in the array.


    [/quote]you need to convert the array to a string before inserting to a database. A sloppy way is to implode() the array with a delimeter, then explode() it when you retrieve from the site, a better way is to create a new table for NOTES and use the foreign key of user ID or post ID or whatever it is that is the 'parent' entity of NOTES.

    For example; the NOTES are child members of a form for a book review..

    so;

    [code]<?php

    $link = mysql_connect('host', 'user', 'pass');
    mysql_select_db('db', $link);

    function magic_escape($value, $link)
    {
        if (get_magic_quotes_gpc()) $value = stripslashes($value);

        return mysql_real_escape_string($value, $link);
    }

    if (!empty($_POST['NOTES']))
    {
        foreach ($_POST['NOTES'] as $note)
        {
            if (!mysql_query(
                     "INSERT INTO `book_reviews` (`notes`) VALUES ('"
                     . magic_escape($note, $link) . "') WHERE `bookid` = '"
                     . magic_escape($_POST['bookid']) . "'"
            ))
            {
                die('Error inserting note: ' . htmlentities($note));
            }
        }
    }

    ?>[/code]

    Then when selecting..

    [code]<?php

    $link = mysql_connect('host', 'user', 'pass');
    mysql_select_db('db', $link);

    function magic_escape($value, $link)
    {
        if (get_magic_quotes_gpc()) $value = stripslashes($value);

        return mysql_real_escape_string($value, $link);
    }

    if (!empty($_POST['bookid']))
    {
        $result = mysql_query(
            "SELECT `notes` FROM `book_reviews` WHERE `bookid` = '"
            . magic_escape($_POST['bookid'], $link) . "'"
        );
        if (!$result) die('Error selecting notes for bookid: ' . htmlentities($_POST['bookid']));

        while ($row = mysql_fetch_assoc($result))
        {
            echo '<div class="note">' . htmlentities($row['note']) . "</div>\n";
        }
    }
    else
    {
        echo 'No notes';
    }

    ?>[/code]
    untested
  4. [code=php:0]if ($do == Login)[/code]

    should be:

    [code=php:0]if ($do == 'Login')[/code]


    and

    [code=php:0]$do = stripslashes($_REQUEST['do']);[/code]

    should be:

    [code=php:0]function magic_strip($value)
    {
        if (get_magic_quotes_gpc())
        {
            $value = stripslashes($value);
        {
        return $value;
    }

    $do = magic_strip($value);
    [/code]
×
×
  • 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.