Jump to content

Help calling out headlines from my database


Mr Chris

Recommended Posts

Hello,

 

I was wondering if someone could help me with some code.  I want to simply call out a headline from my database.  The first, then the second etc...

 

 
<? 
// select all records ordered by date 
  $topStory = mysql_fetch_array(mysql_query("Select * FROM  tble ORDER BY id LIMIT 6"));
  $topHead = $topStory['headline'];
?> 
<body>
<? echo $topHead['0']; ?><br />
<? echo $topHead['1']; ?><br />
<? echo $topHead['2']; ?><br />
<? echo $topHead['3']; ?><br />
<? echo $topHead['4']; ?><br />
<? echo $topHead['5']; ?><br />

 

Howeverm it pulls out the first headline letter, then the second first headline letter!  Can anyone help me.  I'd really like to do it like this and not in a while loop.

 

Thank you

<?php 
// select all records ordered by date 
$r = mysql_query("Select * FROM  tble ORDER BY id LIMIT 6");
while($topStory = mysql_fetch_array($r)) {
$topHead[] = $topStory['headline'];
}
?> 
<body>
<? echo $topHead[0]; ?><br />
<? echo $topHead[1]; ?><br />
<? echo $topHead[2]; ?><br />
<? echo $topHead[3]; ?><br />
<? echo $topHead[4]; ?><br />
<? echo $topHead[5]; ?><br />

Or put the html inside the WHILE

 

<body>
<?php 
// select all records ordered by date 
$r = mysql_query("Select * FROM  tble ORDER BY id LIMIT 6");
while($topStory = mysql_fetch_array($r)) {
    $topHead = $topStory['headline'];
    echo "$topHead<br />";
}
?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.