13. januar 2006 - 00:03Der er
5 kommentarer og 1 løsning
Hvordan fjerne jeg resultater fra en løkke som ikke har en titel?
Som spørgsmålet lyder. Hvordan fjerne jeg resultater fra denne løkke hvis der ikke er nogen titel? foreach($results as $res) { ?> <div class="katalogdiv"> <b><?php echo $res['Title']; ?></b><br /> <?php echo $res['Description']; ?> <a href="<?php echo $res['Url']; ?>" style="color: #333333; text-decoration: none; font-size: 10px; font-weight: bold;" rel="nofollow"><?php echo $res['Title']; ?></a> </div> <?php // Did you see where we used the nbr variable above to write the // ranking position to the screen? We need to increase it by one // before the next loop. $nbr++; }
I dette særtema ser vi på, hvordan cloud og AI bliver fundamentet for virksomhedernes digitale forretning, og hvordan de nye muligheder for automatisering og forretningsværdi kan udnyttes uden at miste overblik, sikkerhed og menneskelig kontrol.
Så vidt jeg forstår på dit spørgsmål, er det blot at sige: if (empty($res['Title'])) continue; Det skal bare være lige under din foreach. På den måde springes denne over, hvis $res['Title'] er tom.
jeg vil prøve det af i morgen... er på vej i seng nu. Men det er hele indholdet af <div> til </div> der skal springes over og så vise næste resultat som har en titel
Disse data er fra msn via deres API - her er der noget kode:
<?php if($query != "") { if($_GET['offst'] == "") { $offset = 0; } else { $offset = $_GET['offst']; } // Now let's set up the parameters for our API query. $parameters = array( 'AppID' => MSN_API_KEY, 'Query' => $query, 'CultureInfo' => 'da-DK', 'SafeSearch' => 'Off', 'Requests' => array( 'SourceRequest' => array( 'Source' => $source, 'Offset' => $offset, 'Count' => $count, 'ResultFields' => 'All' ) ) ); // Set up our call to SOAP to send our request off. $soapClient =& new soapclient(MSN_API_ENDPOINT);
// Configure our call to MSN's API $result =& $soapClient->call('Search', array('Request'=>$parameters), MSN_API_NAMESPACE);
// In case we run into an error from SOAP if($soapClient->getError()) { $err = $soapClient->getError(); $result = false; } }
// If there are no SOAP errors we want it to do it's thing if($err == "") { // Get our results array $results = $result['Responses']['SourceResponse']['Results']['Result']; // Get an offset for our Next and Previous links $nbr = $offset;
if(count($results) > 0) { // The prev offset for our previous link $prevoffset = $nbr - $count; // The next offset for our Previous link $nextoffset = $nbr + $count; // Increase our number, since they'll begin at 0 and we want // to use it later to output some numbers to the screen // as we list the returned sites. $nbr++; } // If the Previous Offset is NOT a negative number it means we're no // longer on the first page. For the first page it'll always be a // negative number, so we won't display a Previous link until // prevoffset is at least zero. if($prevoffset > -1) {
} // If Next Offset is less than the total number of results returned we // should show a Next link. if($nextoffset < $result['Responses']['SourceResponse']['Total']) { // This is a bit of strange logic and is ONLY used to control whether // a div tag is written or not. It has nothing to do with the API // script really. Just formatting. Basically, if a Previous link is // showing, we do NOT want to write another div tag. However if we're // on the first page we need one to complete the display. // What the line below is really doing is taking care of that. if($prevoffset == $count - ($count * 2)) {
} ?> <?php } // Close out our navigation div and get ready to display the results. // Now let's loop through our results array one at a time // and write the data to the screen in list tags. foreach($results as $res) { ?> <div class="katalogdiv"><!-- google_ad_section_start --> <b><?php echo $res['Title']; ?></b><br /> <?php echo $res['Description']; ?> <a href="<?php echo $res['Url']; ?>" style="color: #333333; text-decoration: none; font-size: 10px; font-weight: bold;" rel="nofollow"><?php echo $res['Title']; ?></a> </div> <?php // Did you see where we used the nbr variable above to write the // ranking position to the screen? We need to increase it by one // before the next loop. $nbr++; }
// Almost done. This is an exact copy of the Previous - Next link // code from above, so I won't comment it again. if($prevoffset > -1) {
} if($nextoffset < $result['Responses']['SourceResponse']['Total']) { if($prevoffset == $count - ($count * 2)) { ?> <div class="nav"> <?php } ?> <?php } } else { // If we couldn't do anything because of a SOAP error we'll want to // say that instead of displaying nothing. echo $err; } ?>
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.