Jump to content

to readout with varying categorys


Guest SwordKing

Recommended Posts

Guest SwordKing

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

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> 

Guest SwordKing

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

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

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))

{

Guest SwordKing

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.