Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: PHP: Displaying From a DB  (Read 1107 times)

0 Members and 1 Guest are viewing this topic.

PoeFacedKilla

Prussian Killer Bee
PHP: Displaying From a DB
« on: March 15, 2007, 07:55:18 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
I am working on a private messaging system for my new site, but for some reason, i get an error when i try to make an inbox:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/zelda38/public_html/mw383/Private/index.php on line 6

here's my pm SQL query:

CREATE TABLE `private_m` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` TEXT NOT NULL ,
`from` TEXT NOT NULL ,
`title` TEXT NOT NULL ,
`message` TEXT NOT NULL
) ENGINE = MYISAM ;


here's the inbox script:
Code: [Select]
<? include $_SERVER['DOCUMENT_ROOT']."/includes/layout.top.php"; ?>
<ol>
<?
$query = sprintf("SELECT id, name, from, title, message FROM private_m ORDER BY `id` DESC WHERE name='$memusername'" );
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
?>
<li><a href="pmView.php?id=<? print $row['id']; ?>"><? print $row['title']; ?></a> from: <? print $row['from']; ?></li>
<?
}
?>
<? include $_SERVER['DOCUMENT_ROOT']."/includes/layout.bottom.php"; ?>
« Last Edit: March 15, 2007, 08:01:22 pm by linkthemaster »
Logged
the Indyboard - User Generated Social Forum | Now With Even More Discussion!
Poe, The Independent Programmer
  • Zelda Shrine
Re: PHP: Displaying From a DB
« Reply #1 on: March 15, 2007, 10:09:29 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 563
You could try changing line 9:
Code: [Select]
while ($row = mysql_fetch_assoc($result)) {to
Code: [Select]
while ($row = mysql_fetch_array($result)) {
It doesn't look like your using an associative array so assoc shouldn't be used. Although I may be wrong its worth a try.
Logged

I ♥ Open Girlfriend (What!? I didn't add this.. must have been Solly!)
  • My DevArt Account

PoeFacedKilla

Prussian Killer Bee
Re: PHP: Displaying From a DB
« Reply #2 on: March 16, 2007, 02:38:32 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
i have already fixed it, it was because 'from' is a taken SQL variable.
Logged
the Indyboard - User Generated Social Forum | Now With Even More Discussion!
Poe, The Independent Programmer
  • Zelda Shrine
Re: PHP: Displaying From a DB
« Reply #3 on: March 16, 2007, 02:43:56 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2245
just so your aware its better to do something like
Code: [Select]
$result = mysql_query($query) or die(mysql_error());so if there's a problem with your sql it'll pick up on it and tell you what the actually problem is
Logged

PoeFacedKilla

Prussian Killer Bee
Re: PHP: Displaying From a DB
« Reply #4 on: March 16, 2007, 02:55:31 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
just so your aware its better to do something like
Code: [Select]
$result = mysql_query($query) or die(mysql_error());so if there's a problem with your sql it'll pick up on it and tell you what the actually problem is

yeh i know that, i wrote that at like 5 in the morning, so i am going back through all of it and fixing the errors.
Logged
the Indyboard - User Generated Social Forum | Now With Even More Discussion!
Poe, The Independent Programmer
  • Zelda Shrine
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.219 seconds with 47 queries.