PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Feb 23, 2020 2:27 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed Nov 30, 2011 8:09 pm 
Offline
Forum Newbie

Joined: Wed Nov 23, 2011 12:17 pm
Posts: 4
Hello everyone,

I have a question with the use of the functon in_array... I have a list of categories in my table and I want to know if a specific category exists so I am doing this:

$categoriasexistentes= mysql_query("SELECT * FROM LugaresTuristicos WHERE DestinoPeg='$LinkDestino' GROUP BY Clasificacion ")
or die(mysql_error());

$array = mysql_fetch_array($categoriasexistentes);

print_r($array);

WHAT IS DISPLAYED BY print_r (there should be much more categories) IS THIS:

Array ( [0] => Bar [Clasificacion] => Bar )


If I ad this all categories are displayed:

while($categoria = mysql_fetch_array($categoriasexistentes))

{
$todas=$categoria['Clasificacion'];

?>
<?php echo"{$todas} - "; ?>

<?php

}; ?>


Top
 Profile  
 
PostPosted: Wed Nov 30, 2011 8:37 pm 
Offline
Forum Regular
User avatar

Joined: Tue Sep 28, 2010 11:41 am
Posts: 984
Location: Columbus, Ohio
Try the following. Since you only listed one field from the results that your query would give that is what I told it to select, no need to retrieve more data than you are going to use.
Syntax: [ Download ] [ Hide ]
$aryCategories = array();
$SQL = 'SELECT DISTINCT `Clasification` FROM `LugaresTuristicos` WHERE `DestinoPeg`="'.mysql_real_escape_string($LinkDestino).'"';
$rsCategories = mysql_query($SQL);
if ($rsCategories && mysql_num_rows($rsCategories)>0) {
    while ($aryTemp = mysql_fetch_assoc($rsCategories)) {
        $aryCategories[] = $aryTemp['Clasificacion'];
    }
    mysql_free_result($rsCategories);
}
unset($rsCategories,$SQL);

print_r($aryCategories); //  Should be an array of items


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group