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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.