[thelist] MySQL insert fails

Lachlan Cannon luminosity at members.evolt.org
Mon Jul 8 00:27:01 CDT 2002


Joel, I see you've already got it working. Personally, if I were you, I'd
take the sql out of the query statement and put it on a seperate line..
it's much easier to see what's going on. Also, don't even bother passing a
value for id. If you've specified it as non-null and auto-incrementing,
it'll be added whether you specify it or not.

eg

$sql = "SELECT date FROM reservations WHERE custid = $id";
$result = mysql_query($sql, $db);

It looks a lot cleaner to me.

Regarding your earlier query about the fetch_array function, I don't
bother specifying both, or numeric or associative.. the PHP documentation
says itself that the overhead for retrieving both is very small. If all
you want is the associative, you mayaswell use the other function. I onl
use fetch_array because of force of habit. I can't see myself ever using
numeic indexes.. too unreliable if you chasnge the order later on, and
it's harder to read what you're doing, when you look over the code later.

-----------------
    while ($line = mysql_fetch_array($result, MYSQL_BOTH))
    {
        print "\t<tr>\n";
        foreach ($line as $col_value)
        {
            print "\t\t<td>$col_value</td>\n";
        }
        print "\t</tr>\n";
    }

returns each field twice. Is there a mechanism to choose the numeric or
associative index on the fly?
-----------------

you  could change it to

    while ($line = mysql_fetch_array($result))
    {
        print "\t<tr>\n";
        foreach ($line as $key => $col_value)
        {
            if (!is_numeric($key))
            {
                print "\t\t<td>$col_value</td>\n";
            }
        }
        print "\t</tr>\n";
    }

But personally, I don't see the point... (and I hate your bracket syntax,
btw :P)

HTH,
Lach
_____________________________________
http://members.evolt.org/luminosity/
MSN: luminosity @ members.evolt.org
_____________________________________





More information about the thelist mailing list