Guest Posted July 29, 2013 Share Posted July 29, 2013 Hello, I have a code <?php require_once('../class.dbops.php'); $newsClass = new dbops() or die('error'); $singleNews = $newsClass->getNewsById(413); $allNews = $newsClass->getAllNews(); echo '<pre>'; print_r($allNews); echo '</pre>'; while($allNews > 1000) { $id = $allNews['id']; $head = $allNews['headline']; $text = $allNews['text']; $author = $allNews['author']; $date = $allNews['date']; echo "<table width='1500' border='3'> <td width='300'><h4>{$text}</h4></td> <td width='300'><h4>{$head}</h4></td> <td width='300'><h4>von {$author} am {$date}</h4></td> <td width=300'><a href='update2.php?id=".$row["id"]."' target='_blank'>edit</a></td> <form action=news2.php method=post> <input type='hidden' name='hidden' value='".$row['id']."'> <td width='300'><input type='submit' name='delete' value='delete'</td> <form action=news2.php method=post> </form> </table>"; } combined with this page function getAllNews() { $query = "SELECT * FROM news WHERE 1 "; $rs = mysql_query($query); $news = array(); while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) ) { $news[] = $row; } return $news; } Well, I am pretty sure my array is working. My problem is to give out the array in the table. Could you help me please? Link to comment https://forums.phpfreaks.com/topic/280618-while-for-array-oop/ Share on other sites More sharing options...
AbraCadaver Posted July 29, 2013 Share Posted July 29, 2013 What is this? while($allNews > 1000) ??? Just do something like this: foreach($allNews as $row) { $id = $row['id']; //etc //table stuff } Link to comment https://forums.phpfreaks.com/topic/280618-while-for-array-oop/#findComment-1442560 Share on other sites More sharing options...
Guest Posted July 29, 2013 Share Posted July 29, 2013 Then I just get 6 blank table fields Link to comment https://forums.phpfreaks.com/topic/280618-while-for-array-oop/#findComment-1442561 Share on other sites More sharing options...
Guest Posted July 29, 2013 Share Posted July 29, 2013 Thats how printed array looks like Array ( [0] => Array ( [id] => 413 [headline] => hi [author] => qwerty [text] => ytrewq [date] => 2013-07-25 ) [1] => Array ( [id] => 414 [headline] => lala [author] => alal [text] => ertzfdz [date] => 2013-07-25 ) [2] => Array ( [id] => 415 [headline] => zuiuzou [author] => ou [text] => iozuioui [date] => 2013-07-25 ) [3] => Array ( [id] => 416 [headline] => jhln [author] => m,nmg [text] => hjdfzrt [date] => 2013-07-25 ) [4] => Array ( [id] => 423 [headline] => adsf asdfasd f [author] => adf adsgdsfg f [text] => fghfgha sdfas fdsaas dfasdf asdf asdfdsaf sda [date] => 2013-07-26 ) [5] => Array ( [id] => 424 [headline] => erdfgsdf [author] => fsdgsdf [text] => regwer [date] => 2013-07-29 ) ) Link to comment https://forums.phpfreaks.com/topic/280618-while-for-array-oop/#findComment-1442563 Share on other sites More sharing options...
AbraCadaver Posted July 29, 2013 Share Posted July 29, 2013 I'm not going to modify all of your code. Did you change: $head = $allNews['headline']; //to $head = $row['headline']; And so on an so forth and so on and so on??? That's what //etc meant. Link to comment https://forums.phpfreaks.com/topic/280618-while-for-array-oop/#findComment-1442564 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.