Jump to content

[SOLVED] Links changing script?


suckerr70

Recommended Posts

Now I have this code to call and display my blog stuff. I was wondering if I could make it so if I click a link (<a>Pizza</ a>), it can change "WHERE categoryID='food'" to "WHERE subcategoryID='pizza'". Also, how would I make it cut off after 20, and have a "nest page" link to show the next 20? Thanks!

 

<?php
$con = mysql_connect($host,$name,"$pass);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("$db", $con);

$result = mysql_query("SELECT * FROM post2 WHERE categoryID='food'");

while($row = mysql_fetch_array($result))
  {
  echo "<h2>" . $row['name'] . "</h3>";
  echo "<p>" . $row['address'] . "<br />";
  echo $row['phone'] . "</p><br />";
  echo "<p>" . $row['description'] . "</p>";
  echo "<p>---</p>";
  echo "<br />";
  }
mysql_close($con);
?>

Link to comment
https://forums.phpfreaks.com/topic/84415-solved-links-changing-script/
Share on other sites

set your "categoryID" up as a variable and use/set-up a limit with a variable as well.

 

something like this:

 

<?php
$con = mysql_connect($host,$name,"$pass);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("$db", $con);

$cid = $_GET['cid'];

$stophere = $_GET['stop'];

if ($cid == NULL)
{
$cid="food";
}

if ($stophere == NULL)
{
$stophere="20";
}

$result = mysql_query("SELECT * FROM post2 WHERE categoryID='$cid' LIMIT $stophere");

while($row = mysql_fetch_array($result))
  {
  echo "<h2>" . $row['name'] . "</h3>";
  echo "<p>" . $row['address'] . "<br />";
  echo $row['phone'] . "</p><br />";
  echo "<p>" . $row['description'] . "</p>";
  echo "<p>---</p>";
  echo "<br />";
  }
mysql_close($con);
?>

 

 

then set your link up like this:

 

<a href="pagename.php?cid=pizza&stop=40">Next Page</a>

 

of course you will have to add in a little bit of math code for completely automated pagination; if that is what your wanting.

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.