/    Sign up×
Community /Pin to ProfileBookmark

selecting data + wrong ID

Hello,

This is the script for retrieving a categorie names from my DB.
It works fine.

[code=php]
$query = “SELECT * from categories where parent_id = 0”;
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

echo “<ul><li><a href=”meni_sub.php?id_kat = {$row[‘id_cat’]}”> {$row[‘cat_name’]}</a></li></ul>”;

}

[/code]

Now, some of the categories have their own sub-categories and I want to link the categories to them. For that linking
i am using meni_sub.php:

[code=php]
$query = “SELECT cat_name, parent_id from categories where parent_id = ‘$id_kat'”;
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{

echo “<ul><li>{$row[‘cat_name’]}</li></ul>”;

}
[/code]

As a result i get the names of all the categories and subcategories in the table, but i need only the subcategorie that is linked to the specific categorie. The problem is in pasting
the ID from the first script to another so the second script knows witch subcategorie to retrieve.

So, what is wrong with this script?

tnx!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@SheldonJul 05.2006 — Lets try adding some debugging to your second script then.

[code=php]if(isset($id_kat)){ echo($id_kat); }else{ echo("$id_Kat is not set"); }

$query = "SELECT cat_name, parent_id FROM categories WHERE parent_id = '".$id_kat."' ";
echo("The query is:".$query."<br>");
$result = mysql_query($query) or die (mysql_error());


echo("<ul>");

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


echo "<li>".$row['cat_name']."</li>";

}

echo("</ul>");[/code]
Copy linkTweet thisAlerts:
@aluvianaauthorJul 05.2006 — hi,

now i get this error message:

is not setThe query is:SELECT cat_name, parent_id FROM categories WHERE parent_id = ''

tnx
×

Success!

Help @aluviana spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...