godsent Posted December 15, 2008 Share Posted December 15, 2008 I'm started to learn mysql and trying to use my lessons on website. Here are only one entry in my mysql table.(id, type, info, additional, more, date). I'm sure I'm building page wrong way. <? include '_client/config.php'; include '_client/connect.php'; $query = "SELECT * FROM data_base WHERE id='1'"; $res = mysql_query($query); $arr = mysql_fetch_row($res); ?> <div id="primarycontent"> <!-- primary content start --> <div class="post"> <div class="header"> <h3>Home <? print " > ".$arr[2]; print " (id: ".$arr[0].")"; ?> </h3> <div class="date">Updated: <? echo $arr[6] ?></div> </div> <div class="content"> <img src="images/pic1.jpg" class="picA floatleft" alt="" /> <p><strong><? echo $arr[1] ?></strong></p> <? echo $arr[3] ?> <p> </p> <p> </p> <p><? echo $arr[4] ?></p> </div> <div class="footer"> <ul> <li class="printerfriendly"><a href="#">Printer Friendly</a></li> <li class="comments"><a href="#">Comments (18)</a></li> <li class="readmore"><a href="#">Read more</a></li> </ul> </div> </div> <div class="post"> </div> <!-- primary content end --> </div> I think I'm doing this wrong way. I'm retrieving all information in arrays (for example $arr[6] is date, $arr[3] is info etc...). What I'm trying to do is how to build this code for every ID in the table? I'm confused about this, please explain me how it works and if you can help me Link to comment https://forums.phpfreaks.com/topic/137081-phpmysqlnewstable-building-help-please/ Share on other sites More sharing options...
Mchl Posted December 15, 2008 Share Posted December 15, 2008 $query = "SELECT * FROM data_base"; //select all IDs $res = mysql_query($query); while($arr = mysql_fetch_row($res)) { //code in here will be repeated for each row returned by your query, for example: echo "{$arr['id']}: {$arr['type']}<br/>\n"; } Link to comment https://forums.phpfreaks.com/topic/137081-phpmysqlnewstable-building-help-please/#findComment-715935 Share on other sites More sharing options...
godsent Posted December 15, 2008 Author Share Posted December 15, 2008 i get it, but how should i echo all this code <div class="post"> <div class="header"> <h3>Home <? print " > ".$arr[2]; print " (id: ".$arr[0].")"; ?> </h3> <div class="date">Updated: <? echo $arr[6] ?></div> </div> <div class="content"> <img src="images/pic1.jpg" class="picA floatleft" alt="" /> <p><strong><? echo $arr[1] ?></strong></p> <? echo $arr[3] ?> <p> </p> <p> </p> <p><? echo $arr[4] ?></p> </div> <div class="footer"> <ul> <li class="printerfriendly"><a href="#">Printer Friendly</a></li> <li class="comments"><a href="#">Comments (18)</a></li> <li class="readmore"><a href="#">Read more</a></li> </ul> </div> </div> even if i echo 'all'; php side wont work Link to comment https://forums.phpfreaks.com/topic/137081-phpmysqlnewstable-building-help-please/#findComment-715948 Share on other sites More sharing options...
Mchl Posted December 15, 2008 Share Posted December 15, 2008 $query = "SELECT * FROM data_base"; //select all IDs $res = mysql_query($query); while($arr = mysql_fetch_row($res)) { //code in here will be repeated for each row returned by your query, for example: echo "{$arr['id']}: {$arr['type']}<br/>\n"; ?> <p><?php echo $arr['id'];?>: This HTML will also be repeated for each row in query</p> <?php } Link to comment https://forums.phpfreaks.com/topic/137081-phpmysqlnewstable-building-help-please/#findComment-715956 Share on other sites More sharing options...
godsent Posted December 15, 2008 Author Share Posted December 15, 2008 Oh my! I Got it working, your the best! Really helped me allot, huge thanks! Link to comment https://forums.phpfreaks.com/topic/137081-phpmysqlnewstable-building-help-please/#findComment-715962 Share on other sites More sharing options...
Mchl Posted December 15, 2008 Share Posted December 15, 2008 Nice to hear that. Just one more thing: Dont use short tags ( <? ?> ). Always use full php tags (<?php ?>). Short tags are deprecated, are disabled by default in PHP5 and will not be available in PHP6. And what's most important they cause all sorts of problems, when mixing PHP and XML. Link to comment https://forums.phpfreaks.com/topic/137081-phpmysqlnewstable-building-help-please/#findComment-715967 Share on other sites More sharing options...
godsent Posted December 15, 2008 Author Share Posted December 15, 2008 ok i keep that in mind, thanks! Link to comment https://forums.phpfreaks.com/topic/137081-phpmysqlnewstable-building-help-please/#findComment-715972 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.