Guest SwordKing Posted May 3, 2007 Share Posted May 3, 2007 Hey all. I am creating a main document for my homepage. I was already able to create an add, edit and delete document which inserts my stuff in the database table: CREATE TABLE `artikel` ( `id` int(5) unsigned NOT NULL auto_increment, `category` varchar(20) NOT NULL default '', `headline` varchar(50) NOT NULL default '', `comment` text NOT NULL, `text` text NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`), KEY `id_2` (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=1 ; I have created about 5 categorys (musik, friends, lyrics, imprint, projects) which are inserted in the database which looks like this : INSERT INTO `artikel` VALUES (1, 'musik', 'Kataklysm', '', 'Pure Death Metal from Canada !\r\n\r\n<a href="http://kataklysm.net">Kataklysm online</a> !'); Finally I want to create a php document which figures out the categorys. So I have only to work with one document instead of 5. It should work with "index.php?show=artikel&category=$category" I wasn't able to realize it until now. My document looks like this : <?php include("system/replace.php"); ?> <form method="post" action="index.php?show=artikel"> <?php $sql="SELECT * FROM artikel ORDER BY id"; if(!empty($artikel)) { $sql="SELECT * FROM artikel WHERE category='$category' ORDER BY id LIMIT 1"; } $data2=mysql_query($sql, $db); while ($artikel = mysql_fetch_object ($data2)) {?> <table style="width:95%" cellspacing="1" cellpadding="0" class="forum"> <tr><td colspan="2" class="headb"> <?php replace("$artikel->headline"); ?> </td></tr><tr><td colspan="2" class="leftc"> <?php replace("$artikel->text"); ?> </td></tr><tr><td colspan="2" class="headb"> <b>Kommentar</b> </td></tr><tr><td colspan="2" class="leftc"> <?php replace("$artikel->comment"); ?> </td></tr></table><br> <?php } ?> The document shows all of the stuff from the table 'artikel'. What's wrong here? Link to comment https://forums.phpfreaks.com/topic/49823-to-readout-with-varying-categorys/ Share on other sites More sharing options...
suzzane2020 Posted May 3, 2007 Share Posted May 3, 2007 Not so clear about how you want to display it. Is it this way? Category1 Headline Comment Text Category2 Headline comment text etc... Link to comment https://forums.phpfreaks.com/topic/49823-to-readout-with-varying-categorys/#findComment-244390 Share on other sites More sharing options...
Guest SwordKing Posted May 3, 2007 Share Posted May 3, 2007 I want the document to show the stuff. For example : index.php?show=artikel&category=musik The document should only readout the content which has the category musik. Link to comment https://forums.phpfreaks.com/topic/49823-to-readout-with-varying-categorys/#findComment-244406 Share on other sites More sharing options...
suzzane2020 Posted May 3, 2007 Share Posted May 3, 2007 ok so all u wud need is this query <table style="width:95%" cellspacing="1" cellpadding="0" class="forum"> $res=mysql_query("SELECT * FROM artikel WHERE category='$category' " ) $num=mysql_num_rows($res); if($num!=0) { while($row=mysql_fetch_object($res)) { <tr><td colspan="2" class="headb"> <?php replace("$artikel->headline"); ?> </td></tr><tr><td colspan="2" class="leftc"> <?php replace("$artikel->text"); ?> </td></tr><tr><td colspan="2" class="headb"> <b>Kommentar</b> </td></tr><tr><td colspan="2" class="leftc"> <?php replace("$artikel->comment"); ?> </td></tr> <?php } }else{ echo "no records"}?> </table><br> Link to comment https://forums.phpfreaks.com/topic/49823-to-readout-with-varying-categorys/#findComment-244427 Share on other sites More sharing options...
Guest SwordKing Posted May 3, 2007 Share Posted May 3, 2007 If you mean it this way <?php include("system/replace.php"); ?> <form method="post" action="index.php?show=artikel"> <?php $sql="SELECT * FROM artikel ORDER BY id"; if(!empty($artikel)) { $sql="SELECT * FROM artikel WHERE category='$category' ORDER BY id LIMIT 1"; } $data2=mysql_query($sql, $db); while ($artikel = mysql_fetch_object ($data2)) $num=mysql_num_rows($res); if($num!=0) { while($row=mysql_fetch_object($res)) { ?> <tr><td colspan="2" class="headb"> <?php replace("$artikel->headline"); ?> </td></tr><tr><td colspan="2" class="leftc"> <?php replace("$artikel->text"); ?> </td></tr><tr><td colspan="2" class="headb"> <b>Kommentar</b> </td></tr><tr><td colspan="2" class="leftc"> <?php replace("$artikel->comment"); ?> </td></tr> <?php } } ?> </table><br> its wrong or I missunderstood you. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Programme\xampp\htdocs\nd\show\artikel.php on line 7 Link to comment https://forums.phpfreaks.com/topic/49823-to-readout-with-varying-categorys/#findComment-244449 Share on other sites More sharing options...
suzzane2020 Posted May 3, 2007 Share Posted May 3, 2007 First of all u have an extra query here which is nt required <?php include("system/replace.php"); ?> <form method="post" action="index.php?show=artikel"> <?php $sql="SELECT * FROM artikel ORDER BY id"; if(!empty($artikel)) { $sql="SELECT * FROM artikel WHERE category='$category' ORDER BY id LIMIT 1"; } $data2=mysql_query($sql, $db); while ($artikel = mysql_fetch_object ($data2)) $num=mysql_num_rows($res); if($num!=0) { while($row=mysql_fetch_object($res)) { and in the code above the number of rows shud be taken for the main query .ie the query that displays the records change it to the code i gave before it will work Link to comment https://forums.phpfreaks.com/topic/49823-to-readout-with-varying-categorys/#findComment-244460 Share on other sites More sharing options...
suzzane2020 Posted May 3, 2007 Share Posted May 3, 2007 this <?php include("system/replace.php"); ?> <form method="post" action="index.php?show=artikel"> <?php $sql="SELECT * FROM artikel ORDER BY id"; if(!empty($artikel)) { $sql="SELECT * FROM artikel WHERE category='$category' ORDER BY id LIMIT 1"; } $data2=mysql_query($sql, $db); while ($artikel = mysql_fetch_object ($data2)) $num=mysql_num_rows($res); if($num!=0) { while($row=mysql_fetch_object($res)) { wud be this <?php include("system/replace.php"); ?> <form method="post" action="index.php?show=artikel"> <?php $sql="SELECT * FROM artikel WHERE category='$category' ORDER BY id LIMIT 1"; } $data2=mysql_query($sql, $db); $num=mysql_num_rows($artikel); if($num!=0) { while ($artikel = mysql_fetch_object ($data2)) { Link to comment https://forums.phpfreaks.com/topic/49823-to-readout-with-varying-categorys/#findComment-244467 Share on other sites More sharing options...
Guest SwordKing Posted May 3, 2007 Share Posted May 3, 2007 <?php include("system/replace.php"); ?> <form method="post" action="index.php?show=artikel"> <?php $sql="SELECT * FROM artikel WHERE category='$category' ORDER BY id LIMIT 1"; } $data2=mysql_query($sql, $db); $num=mysql_num_rows($artikel); if($num!=0) { while ($artikel = mysql_fetch_object ($data2)) { ?> <tr><td colspan="2" class="headb"> <?php replace("$artikel->headline"); ?> </td></tr><tr><td colspan="2" class="leftc"> <?php replace("$artikel->text"); ?> </td></tr><tr><td colspan="2" class="headb"> <b>Kommentar</b> </td></tr><tr><td colspan="2" class="leftc"> <?php replace("$artikel->comment"); ?> </td></tr> <?php } }else{ echo "no records"}?> </table><br> Parse error: syntax error, unexpected '}' in C:\Programme\xampp\htdocs\nd\show\artikel.php on line 3 If I delete it and fix the <?php } }else{ echo "no records"}?> which makes an error too, I get Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Programme\xampp\htdocs\nd\show\artikel.php on line 6 Link to comment https://forums.phpfreaks.com/topic/49823-to-readout-with-varying-categorys/#findComment-244472 Share on other sites More sharing options...
Guest SwordKing Posted May 4, 2007 Share Posted May 4, 2007 Can someone help me with that? Link to comment https://forums.phpfreaks.com/topic/49823-to-readout-with-varying-categorys/#findComment-245348 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.