Ahh.. this has been working a buch of times for me.. but now its being retarded!
Im trying to pull stuff from my Mysql database.. I can insert it and stuff..

$sql = "SELECT * FROM news";  
$result = mysql_query($sql); if(!($result = mysql_query($sql))) die(mysql_error());
if(mysql_num_rows($result) == 1) { $row = mysql_fetch_array($result); echo ".::" .$row[topic]. "::.<br> <i>Posted by: " .$row[author]. " on " .$row[date]. "</i><br>"; echo "$row[message]"; }

When I have 2 things in my Database it displays nothing.. but when I have one i get

Notice: Use of undefined constant topic - assumed 'topic' in C:\Program Files\Abyss Web Server\htdocs\jimmy\index.php on line 306

Notice: Use of undefined constant date - assumed 'date' in C:\Program Files\Abyss Web Server\htdocs\jimmy\index.php on line 306
.::This is a test::.
Posted by: Brandon on 0000-00-00
Hi.. this is brandon testing addnews. 😃

    You receive "undefined constant" errors as you used undefined constants, rather than strings, as the indices for the associative array fetched by mysql_fetch_array()

    Also, you evaluate mysql_query() twice, which is unnecessary.

    $sql = "SELECT * FROM news";
    $result =  mysql_query($sql)
    	OR die(mysql_error());
    if (mysql_num_rows($result) == 1) {
    	$row = mysql_fetch_array($result);
    	echo ".::" . $row['topic'] . "::.<br> <i>Posted by: "
    		. $row['author'] . " on " . $row['date'] . "</i><br>"
    		. $row['message'];
    }

      Ah.. I see..
      But still.. when I have two things in the database.. it wot display anything.. because I have no
      else
      ..maybe my table is setup wrong?
      It looks like this

      Field           Type       Attributes     Null     Default   Extra     Action 
      author         text                         No                  
      message longtext No
      topic text No
      date date No 0000-00-00

      Do I need to add a 'id' column?
      Also.. it displays the date as 0000-00-00 when I add it to the database.. i use the 'CURDATE( )' function.. but it isnt working.. but it works for regisration for members.. ahhhh
      im confused!

        Write a Reply...