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
https://forums.phpfreaks.com/topic/44665-mysql-function-help/
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
https://forums.phpfreaks.com/topic/44665-mysql-function-help/#findComment-216964
Share on other sites

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.