Be a Supporter!

mySQL select question

  • 332 Views
  • 2 Replies
New Topic Respond to this Topic
AntiTanner
AntiTanner
  • Member since: Nov. 26, 2000
  • Offline.
Forum Stats
Member
Level 32
Blank Slate
mySQL select question 2001-09-02 23:57:31 Reply

Ok im attempting to modify the blaze board script to show my "news" post on the frontpage. Right now i have it so every time a new topic is created in the News forum, it sets an identifier ($FP) equal to 1. Now im trying to call that post out of the db by saying "SELECT * FROM post WHERE FP=1 ORDER BY dateline." I think its just grabbing the data from the first row it sees with an FP of 1, and not getting all the ones. Anyways...i cant get this to work, myabe im going about it all wrong?

liljim
liljim
  • Member since: Dec. 16, 1999
  • Offline.
Forum Stats
Staff
Level 28
Blank Slate
Response to mySQL select question 2001-09-03 05:01:43 Reply

At 9/2/01 11:57 PM, TannerCenterwallEsq wrote: Ok im attempting to modify the blaze board script to show my "news" post on the frontpage. Right now i have it so every time a new topic is created in the News forum, it sets an identifier ($FP) equal to 1. Now im trying to call that post out of the db by saying "SELECT * FROM post WHERE FP=1 ORDER BY dateline." I think its just grabbing the data from the first row it sees with an FP of 1, and not getting all the ones. Anyways...i cant get this to work, myabe im going about it all wrong?

How are you calling the dataset back? You may also need to use the limit command.

Example:

// $connection = connection details (including db selection)
$get = @mysql_query("SELECT * FROM post WHERE FP=1 ORDER BY dateline DESC LIMIT 1", $connection);

if (mysql_num_rows($get) == 0) {
echo "No new for today";
} else {
$row = mysql_fetch_array($get);
$title = $row['title'];
$datetimeposted = $row['dateline'];

echo "$title - posted at $datetimeposted";

}

Obviously, you will need to do a lot more with it than just echoing the title and the time it was posted...

Umm, and you'd be better off specifying exactly which columns you want out of the table rather than selecting * (which is very bad practice). Dunno what else to suggest without seeing some code.

liljim
liljim
  • Member since: Dec. 16, 1999
  • Offline.
Forum Stats
Staff
Level 28
Blank Slate
Response to mySQL select question 2001-09-03 05:14:11 Reply

At 9/3/01 05:01 AM, liljim wrote:
At 9/2/01 11:57 PM, TannerCenterwallEsq wrote:

Oh, and to iterate more than one row at a time, put it in a while or for loop, like so:

while($row = mysql_fetch_array($get)) {
$rowwhatever = $row['column1'];
$rowwhatever2 = $row['column2'];

echo $rowwhatever . " " . $rowwhatever2;

}