Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sun Jan 25, 2004 3:25 pm
Code: Select all
<?php
// Display the text each row
while ( $row = mysql_fetch_array($result) ) {
$date = $row["newsDate"];
$title = $row["title"];
$message = $row["message"];
$newsid = $row["ID"];
echo "<tr>"
."<td>$title</td>"
."<td>$newsid</td>"
."<td><div align="center"><a href='$PHP_SELF?deletenews=$newsid'>Delete this News</a></div></td>"
."</tr>";
}
?>
I'm just curious why isn't $newsid = $row["ID"]; being picked up???
Everything else like $title is working fine
microthick
Forum Regular
Posts: 543 Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC
Post
by microthick » Sun Jan 25, 2004 3:38 pm
Show us your SQL statement that's getting $result.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sun Jan 25, 2004 3:47 pm
Code: Select all
<?php
$result = @mysql_query("SELECT * FROM news ORDER BY `id` DESC LIMIT 10");
?>
This?
microthick
Forum Regular
Posts: 543 Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC
Post
by microthick » Sun Jan 25, 2004 3:50 pm
PHP variables are case-sensitive.
If your field is called id then use $row['id'] instead of $row['ID'].
microthick
Forum Regular
Posts: 543 Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC
Post
by microthick » Sun Jan 25, 2004 4:08 pm
Phenom wrote: hehe how did I miss that one
Thanks man
lol, I do it all the time, too.
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Mon Jan 26, 2004 5:22 am
When doing SQL queries it is a good idea to 1) separate the SQL statement into it's own variable and 2) always specify the column names you would like to return. It will make debugging much easier in the long run, e.g.:
Code: Select all
$result = @mysql_query("SELECT * FROM news ORDER BY `id` DESC LIMIT 10");
becomes
Code: Select all
$sql = "SELECT id, newsDate, title, message FROM news ORDER BY `id` DESC LIMIT 10"
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
That way if you mispell a column name you'll get MySQL telling you about it before you get to the PHP processing bit.
Mac