Mr Chris Posted April 16, 2008 Share Posted April 16, 2008 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 Link to comment https://forums.phpfreaks.com/topic/101381-help-calling-out-headlines-from-my-database/ Share on other sites More sharing options...
conker87 Posted April 16, 2008 Share Posted April 16, 2008 X Rubbish. Sorry, remind me to read the post before. And you're going to need to use whiles. Link to comment https://forums.phpfreaks.com/topic/101381-help-calling-out-headlines-from-my-database/#findComment-518588 Share on other sites More sharing options...
moon 111 Posted April 16, 2008 Share Posted April 16, 2008 <?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 /> Link to comment https://forums.phpfreaks.com/topic/101381-help-calling-out-headlines-from-my-database/#findComment-518591 Share on other sites More sharing options...
benphp Posted April 16, 2008 Share Posted April 16, 2008 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 />"; } ?> Link to comment https://forums.phpfreaks.com/topic/101381-help-calling-out-headlines-from-my-database/#findComment-518615 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.