Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

PHP Help?

Name: PHP/Fail 2008-07-19 12:58

Could somebody please help me, I'm learning PHP at the moment and there seems to be a slight failure with MySQL:

<?php
(some code has been skipped, such as passwords and db names)
$csn = mysqli_connect($host,$user,$password,$dbname)
    or die("Could not connect to sever.");

/* This query finds the limits of the post list */
    $query = "SELECT MIN(postID) FROM first_post";
    $result = mysqli_query($csn,$query)
        or die("Couldn't retrieve post limit.");
    $postmin = mysqli_fetch_assoc($result);
/* Continueing */
    $query = "SELECT MAX(postID) FROM first_post";
    $result = mysqli_query($csn,$query)
        or die("Couldn't retrieve post limit.");
    $postmax = mysqli_fetch_assoc($result);

mysqli_close($csn);

echo "Max: ";
echo $postmax['postID'];
echo "Min:";
echo $postmin['postID'];
echo "\n";
?>

The output for this is Max: Min: and not showing the arrays :-\
HALP?

Name: Anonymous 2008-07-19 13:00

You're using the wrong array keys. Either use FUNC(foo) as foo or use $postfunc['FUNC(foo)'].

Name: Anonymous 2008-07-19 13:00

I'm learning PHP
Stop now.

There's nothing wrong with your SQL, by the way.

Name: Anonymous 2008-07-19 13:05

| Either use FUNC(foo) as foo or use $postfunc['FUNC(foo)'].

What is this? (OP Here)

Name: Anonymous 2008-07-19 13:07

>>4

Figure it out yourself, dumbass.

Name: Anonymous 2008-07-19 14:22

>>4
You suck at bbCODE as badly as you do at PHP.
Like >>2 said, you're using the wrong array keys. Use print_r() to see the key/value pairs contained in an array.

Name: Anonymous 2008-07-19 15:09

Seriously though. Ditch PHP and learn the SLOW AS FUCK LANGUAGE Ruby

Name: Anonymous 2008-07-19 15:24

>>4
SELECT MAX(habeeb) as habeeb FROM ....

now you can acces your array with $postmax['habeeb']

Name: Anonymous 2008-07-19 15:35

>>1

<?php

/* Snip... */

mysql_connect(SQL_HOST, SQL_USER, SQL_PASS)
    or die("Couldn't connect to database.");
mysql_select_db(SQL_DB);

$q = mysql_query("SELECT MIN(postid), MAX(postid) FROM firstpost");
$a = mysql_fetch_assoc($q);

echo "Max: ", $a['MAX(postid)'], "\nMin: ", $a['MIN(postid)'], "\n";

?>


OMGOPTIMIZED

mysqli_connect() doesn't take a database name argument, and it's always better to use constants (that is, using define()) than variables for values that are constant.
mysql_query() and mysqli_query() by default always use the connection that was last opened, so unless you have more than one connection open, there's no need to pass an identifier as well.

Name: Anonymous 2008-07-19 15:37

>>8
thank you friend

Name: Anonymous 2008-07-19 16:02

>>10
I'm not your friend, pal.

Name: Anonymous 2008-07-19 16:02

>>11
;_;

Name: Anonymous 2008-07-19 19:47

>>11
I'm not your pal buddy

Name: Anonymous 2008-07-19 20:03

>>13
I'm not your cliché, fuckface.

Name: Anonymous 2008-07-19 20:04

>>10-11,13
I'm not your Leah Culver, FIOCkers.

Name: Anonymous 2010-11-28 7:30

<

Name: Anonymous 2011-02-03 3:58

<

Name: Anonymous 2011-02-04 18:33


Don't change these.
Name: Email:
Entire Thread Thread List