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? Quote Link to comment Share on other sites More sharing options...
Solution AbraCadaver Posted July 29, 2013 Solution Share Posted July 29, 2013 (edited) What is this? while($allNews > 1000) ??? Just do something like this: foreach($allNews as $row) { $id = $row['id']; //etc //table stuff } Edited July 29, 2013 by AbraCadaver Quote Link to comment 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 Quote Link to comment 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 ) ) Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.