Closed Thread
Old 05-21-2009, 02:35 AM php/mysql help
Junior Talker

Posts: 3
Trades: 0
ok i got a code that display the mysql query file it all works good
but i only what it to output the row with the same catid number for a ex(if u click on
<code><a href='$pagename.php?act=view&id=$id&cat=$catid'>$n ame</a><br /></code>) i wants to only get the rows with the catid 5 or 6 or what ever name is that link when its click on. can some please please fix this for me

heres my code
categorie.php this show the links to the next page that will display subcategories
Code:
<?
  include("conn.php");
 $pagename ="subcategories"; $table = site_post; $tableid = catid;
 $max = 25;
/*$qset = "select * from $table";
$rset = mysql_query($qset) or die(mysql_error());
$r = mysql_fetch_array($rset);*/

$p = $_GET['p'];
if(empty($p))
{
$p = 1;
}
$limits = ($p - 1) * $max;
$sql = mysql_query("SELECT * FROM $table LIMIT ".$limits.",$max") or die(mysql_error());
//the total rows in the table
$totalres = mysql_result(mysql_query("SELECT COUNT($tableid) AS tot FROM $table"),0);
//the total number of pages (calculated result), math stuff...
$totalpages = ceil($totalres / $max);
//the table
while($r = mysql_fetch_array($sql))   {
$id = $r['catid'];
$catid = $r['catid'];
$name = $r['name'];
echo "<a href='$pagename.php?act=view&cat=$id'>$name</a><br />";
}
for($i = 1; $i <= $totalpages; $i++){
//this is the pagination link
echo "<a href='$pagename.php?p=$i'>$i</a>|";
}
 ?>
subcategorie.php this show the links to the next page that will display the items
Code:
<?
  include("conn.php");
 $pagename ="view"; $table = site_post; $tableid = id;
 $max = 25;
/*$qset = "select * from $table";
$rset = mysql_query($qset) or die(mysql_error());
$r = mysql_fetch_array($rset);*/

$p = $_GET['p'];
if(empty($p))
{
$p = 1;
}
$limits = ($p - 1) * $max;
$sql = mysql_query("SELECT * FROM $table LIMIT ".$limits.",$max") or die(mysql_error());
//the total rows in the table
$totalres = mysql_result(mysql_query("SELECT COUNT($tableid) AS tot FROM $table"),0);
//the total number of pages (calculated result), math stuff...
$totalpages = ceil($totalres / $max);
//the table
while($r = mysql_fetch_array($sql))   {
$id = $r['id'];
$catid = $r['catid'];
$name = $r['name'];
echo "<a href='$pagename.php?act=view&cat=$catid'>$name</a><br />";
}
for($i = 1; $i <= $totalpages; $i++){
//this is the pagination link
echo "<a href='$pagename.php?p=$i'>$i</a>|";
}
 ?>
view.php this will view the list from the id that was sent this work fine its the top im haveing a time with
Code:
include("conn.php");
$table= site_post; $tableid= id;
$max = 10; //amount of articles per page. change to what to want
$p = $_GET['p'];
if(empty($p))
{
$p = 1;
}
$limits = ($p - 1) * $max;
//view the news article!
if(isset($_GET['act']) && $_GET['act'] == "view")
{
$id = $_GET['id'];
$catid = $_GET['catid'];
$sql = mysql_query("SELECT * FROM $table WHERE $tableid = '$id'" );
while($r = mysql_fetch_array($sql))
{
echo "<div style=\"position: absolute; top:150px; left: 240px\">
<div>";
 if($r["images1"]==""){
        echo "<img src=\"images/noimage.jpg\" width=\"99\" height=\"99\">";
              }else{
        echo '<a target="_blank" href="images/'.$r["images1"].'"><img src="images/'.$r["images1"].'" border="0" width="120" height="100" hspace="1" vspace="1"></a>';
        }
 if($r["images2"]==""){
         }else{
echo '<a target="_blank" href="images/'.$r["images2"].'"><img src="images/'.$r["images2"].'" border="0" width="120" height="100" hspace="1" vspace="1"></a>';
 }
  if($r["images3"]==""){
}else{
echo '<a target="_blank" href="images/'.$r["images3"].'"><img src="images/'.$r["images3"].'" border="0" width="120" height="100" hspace="1" vspace="1"></a>';
}
if($r["images4"]==""){
          }else{
echo '<a target="_blank" href="images/'.$r["images4"].'"><img src="images/'.$r["images4"].'" border="0" width="120" height="100" hspace="1" vspace="1"></a></div>';
}
echo '<br>';

 if($r[resume]==""){
          echo '<br>No Info Text Found<br><a class="link1" href="javascript:history.back();">Back</a>';
          }else{
echo '<div style="width:658px; text-indent:8px;">'.$r["resume"].'</div>
<a class="link1" href="javascript:history.back();">Back</a>
</div>';
}
}
}
mysql
Code:
CREATE TABLE `site_post` (
  `id` int(11) NOT NULL auto_increment,
  `catid` int(11) default NULL,
  `subcatid` int(11) default NULL,
  `catname` text,
  `name` text,
  `resume` text,
  `images1` text,
  `images2` text,
  `images3` text,
  `images4` text,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;
INSERT INTO `site_post` (`id`, `catid`, `subcatid`,`catname`, `name`, `resume`, `images1`, `images2`, `images3`, `images4`) VALUES
(1, 1,5, 'movies','name1', 'des gos here', '1.jpg', '', '', '')
(2, 2,1, 'tv shows','name2', 'des gos here', '3.jpg', '4.jpg', '', ''),
(3, 3,3, 'cars','name3', 'des gos here', '1.jpg', '3.jpg', '4.jpg', ''),
(4, 4,3, 'bikes','name4', 'des gos here', '1.jpg', '4.jpg', '', ''),
(5, 5,4, 'atv','name5', 'des gos here', '1.jpg', '2.jpg', '3.jpg', '4.jpg'),
(6, 6,4, 'flashgames',''name6', 'des gos here',  '1.jpg', '3.jpg', '', '');
chase2005 is offline
View Public Profile
 
 
When You Register, These Ads Go Away!
Closed Thread     « Reply to php/mysql help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.08540 seconds with 13 queries