Jump to content

mySQL function help


shauna7084

Recommended Posts

I am not a professional - but like to try my hand at PHP and mySQL occasionally.  I'm stuck on something realatively easy.  This function calls for a listing of all categories to be displayed.  I'm wanting to change it to create a listing only of the current category (as defined by the ID in the URL).  Can you help?

 

function head() {

 

global $mysql;

 

$result = mysql_query("SELECT DISTINCT * FROM cats ORDER BY id", $mysql);

 

while ($i = mysql_fetch_array($result)) {

 

$cat = stripslashes($i[name]);

 

}

echo "<h1>Allegiance Answers</h1><h2>CURRENT CATEGORY HERE</h2><P><a href=search.php>Search for an Answer</a></p><br>";

 

}

Link to comment
Share on other sites

Do you mean

<?php
function head($id) {

    $result = mysql_query("SELECT name FROM cats WHERE id = '$id'");

    $i = mysql_fetch_array($result) ;

    $cat = stripslashes($i[name]);

    echo "<h1>Allegiance Answers</h1><h2>$cat</h2><P><a href='search.php'>Search for an Answer</a></p>";

}

$id = $_GET['id'];

head ($id);
?>

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.