How to get only the first path from Mysql?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fynd
    New Member
    • Mar 2010
    • 13

    How to get only the first path from Mysql?

    Ok, let see if I can explain.
    I have a query from my db which inserts id of the inputted objects. The result is in a string which I use to show the content. In one of the sql tables, there are path names to images. One id can have up to 3 images assigned which gives 3 path names. But here is the catch, I only want to display the first path name. My query looks like this:
    Code:
    $data = "
                    SELECT
                      a.annonsid,
                      a.datum,
                      a.datumtid,
                      a.lan,
                      a.radio1,
                      a.rubrik,
                      a.stad,
                      a.pris,
                      a.typ,
                      a.kategori,
    				  b.annonsid,
                      b.bildpath
    				  
                    FROM
                      annonser AS a
                    LEFT JOIN
                      annonser_bilder AS b
                    ON
                      a.annonsid=b.annonsid
    				  
                    WHERE
                      a.kontrollerad = 'ja'
    			      $sokord
    				  
                    LIMIT
    				
                      $offset, $antal_bilder";
    				  
                    $query = mysql_query($data);
    			    $no=1;
                    while ($templista = mysql_fetch_array($query))
                    {
    My code for the output looks like this:
    Code:
     if($templista[bildpath])
                     {
                   echo "</td>";
                   echo "<td width=\"60\" height=\"30\">";
                   echo "<a href=\"?annonsID=".$templista[annonsid]."\">";
    			   $size = getimagesize($templista[bildpath]);
    bildpath is the path name for the image.

    I'm not a programmer by all means and I have been struggling to learn. Hopefully someone can help me with this?

    Best regards,
    Morgan
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Can you please do the following, after you have queried your database so we can see what data is being stored:

    Code:
    var_dump($templista['bildpath']);
    Also, when accessing elements of an array, surround the array key (if it's a string) with quotation marks.

    Comment

    • Fynd
      New Member
      • Mar 2010
      • 13

      #3
      Thanks for your suggestions and reply. The VAR DUMP outputs this:
      Code:
      string(46) "annonsbilder/201003300702531217.210.81.146.jpg"  string(46) "annonsbilder/201003300658152217.210.81.146.jpg"  string(46) "annonsbilder/201003300829383217.210.81.146.jpg"
      I have 3 images in that id and I just wanna display the first. It should be OK with GROUP BY a.annonsid but doesn't work as I have a string in the WHERE statement because this string handles the search function. If there was a way to delimit or reduce or extract the "bildpath" so only the first image was shown but I can not see it right now. Hoping for your help.
      I'm really grateful that you took your time to answer.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Well, in your SQL query, you could LIMIT 1, or you could access the first element of your array: $templista['bildpath'][0];

        Mark.

        Comment

        • Fynd
          New Member
          • Mar 2010
          • 13

          #5
          Thanks Markus, if I LIMIT 1, I could not list the other records in my db as I now LIMIT with $offset,$number _of_records.
          I tried the [0] in my array but the VAR_DUMP came up with this:
          string(1) "a" string(1) "a" string(1) "a"
          It seams like the path to the image is lost. Any more ideas? Sorry to bother you with questions, but now I'm lost. I know and understand why it happens but to be able to make it..........

          Best regards,
          Morgan

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Please post your revised code.

            P.S. Remember to use [code][/code] tags around the code.

            Comment

            • Fynd
              New Member
              • Mar 2010
              • 13

              #7
              Ok, here is the full query down to the img src. It will then continue showing the other arrays but I thought there was no meaning with that as the problem is located in the bildpath.
              The code is a mess right now and I haven't cleaned it up due to development so here it is:
              Code:
              $antal_bilder = ANTAL_SENAST_INLAGGDA_ANNONSER;
              
                            $sql = "
              
                              SELECT
              
                                a.annonsid,
              
                                a.datum,
              
                                a.datumtid,
              
                                a.lan,
              
                                a.typ,
              
                                a.rubrik,
              
                                a.stad,
              
                                a.pris,
              
                                a.marke,
              
                                a.kategori,
              				  b.id,
              				  b.bildnamn,
              
                                b.bildpath
              
                              FROM
              
                                annonser AS a
              
                              LEFT JOIN
              
                                annonser_bilder AS b
              
                              ON
              
                                a.annonsid=b.annonsid
              
                              WHERE
              
                                a.kontrollerad = 'ja' 
              				   
              
                              $sokord
                              
              
                              LIMIT
              
                                $offset, $antal_bilder
              
                              ";
              $rs = mysql_query($sql);
              
                              while ($visa = mysql_fetch_array($rs))
              
                             
              				{
                              
              //$result = mysql_query("SELECT bildpath FROM annonser_bilder LIMIT 0");
              //if (!$result) {
                  //echo 'Could not run query: ' . mysql_error();
                  //exit;
              //}
              //$row = mysql_fetch_row($result);
              
              //$path = $row[0]; // 42
              //echo $row[1]; // the email value
              				
              	
              //-------------------Slut gamla frågan----------------------------------------------------//  
                    echo "\t<tr onmouseover=\"javascript:style.background='".$varannan."'\" onmouseout=\"javascript:style.background=''\">\n";
              	  
              //--------------------Nya visa---------------------------------------------------------//
                               echo "</td>";
                               echo "<td width=\"60\" height=\"30\">";
                               echo "<a href=\"?annonsID=".$visa[annonsid]."\">";
                               echo "<span class=\"small\">";
                               echo "$visa[datum]";
                               echo "</td></span>";
              				  echo '</a>';
              		
              		var_dump($visa['bildpath'][1]);			
              				 //test=$visa[bildpath];
              				 
              
              //echo $test;
              
              
                             if($visa[bildpath])
                               {
                             echo "</td>";
                             echo "<td width=\"60\" height=\"30\">";
                             echo "<a href=\"?annonsID=".$visa[annonsid]."\">";
              			   $size = getimagesize($visa[bildpath]);
                     $height = $size[1];
                     $width = $size[0];
                   if ($height > 199)
                        {
                             $height = 60;
                             $percent = ($size[1] / $height);
                             $width = ($size[0] / $percent);
                        }
                   else if ($width > 199)
                        {
                             $width = 60;
                             $percent = ($size[0] / $width);
                             $height = ($size[1] / $percent);
                        }
                             //echo "<img src=\"thumbnails.php?src=$row1[bildpath]\" style=\"border: 0;\" />";
              			   echo "\t\t<img src=\"{$visa[bildpath]}\" width=\"$width\" height=\"$height\" border=\"1\"><br>";

              Comment

              • Fynd
                New Member
                • Mar 2010
                • 13

                #8
                Hi Markus,
                It seems like that the string I am searching, shows up as string46 when the var_dump($visa['bildpath']); is used but when using var_dump($visa['bildpath']['0']); I only get the single letters from the image path. In this case var_dump($visa['bildpath']['0']); will output string 1 "a" var_dump($visa['bildpath']['1']); will output string 1 "n" and so on.
                Well if we could find a way to output string46 one time we have it.

                The string 46 is the container for the array bildpath, now I have to find the method to show the row of string 46.

                Cheers,

                //Morgan

                Comment

                • Atli
                  Recognized Expert Expert
                  • Nov 2006
                  • 5062

                  #9
                  Hey.

                  Originally posted by Fynd
                  I have 3 images in that id and I just wanna display the first. It should be OK with GROUP BY a.annonsid but doesn't work as I have a string in the WHERE statement because this string handles the search function.
                  Could you show us the query after the string has been constructed?
                  You could just do echo $sql; exit; before the mysql_query($sq l); and print the results.


                  You really should limit the query, rather than do this in the PHP code, but if all else fails you can always just record which ID's you have already printed and skip each subsequent row that has that ID.
                  For example:
                  [code=php]
                  $used_ids = array();
                  while($row = mysql_fetch_ass oc($result)) {
                  if(in_array($ro w['id'], $user_ids)) {
                  continue; // Skip this row.
                  }
                  $used_ids[] = $row['id'];

                  // etc...
                  }
                  [/code]

                  Comment

                  • Fynd
                    New Member
                    • Mar 2010
                    • 13

                    #10
                    God dag Atli,
                    Well the application itself is a advertising script which contains a number of adverts. The info from the adverts are stored into 2 db's of the mysql database, 1 for the information about the advertiser etc, and 1 for the id, path and path name of the images stored with the adverts. This complicates things as I had to join 2 db's hence the code.
                    The id of the advert, which is stored in the first db, can have multiple images attached to the same id. This works well with 1 image, but when there are more than 1, there will be problem as that the search function is also a parameter of the query. You can search the db for whatever you want. But when there are 2 images you also get 2 image paths from the db and the script is doing the right thing when listing all adverts in the search function. It treats every extra image path as an extra advert and I just want to extract the first image path from the adverts id.

                    Id1 lot of information 3 images makes the output repeating 3 times
                    Id2 lot of information 2 images makes the output repeating 2 times
                    Id3 lot of information 1 images makes the output 1 times

                    The code before the query is quite complex but I think I post the whole lot. Pls. bare in mind I'm not a programmer and the code is really messy right now.
                    Thanks for helping out!
                    Some strings are in swedish but I think you understand them :-)
                    Code:
                    <?php
                    //----- Kollar vilken annons som visats mest sista veckan- //
                    $hetAnnons =  date("Y-m-d", mktime (0,0,0,date("m"),date("d")-7,date("Y")));
                    $antal[2] = mysql_fetch_array(mysql_query("SELECT annonsid,datum,visad FROM annonser WHERE datum > '$hetAnnons' ORDER BY visad DESC LIMIT 0, 1"));
                    
                    //----- Kollar antal personer som är online -------------- //
                    $antal[0] = mysql_num_rows(mysql_query ("SELECT DISTINCT ip FROM online")) + 11;
                    
                    //----- Fyller arrayen med alla veckodagar ----------------//
                    $dagar = array("Söndag", "Måndag", "Tisdag", "Onsdag", "Torsdag", "Fredag", "Lördag");
                    
                    //----- Fyller arrayen med alla månader -------------------//
                    $manader = array(1 => "Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September", "Oktober", "November", "December");
                    ?>
                    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
                    </script>
                    <script type="text/javascript" src="jquery.magnifier.js">
                    
                    /***********************************************
                    * jQuery Image Magnify- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
                    * This notice MUST stay intact for legal use
                    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for this script and 100s more
                    ***********************************************/
                    
                    </script>
                    <?php
                    //----- Om sökknappen blivigt intryckt gör vi en söksträng //
                    $ord = trim($ord);
                    if($sok)
                      {
                      $sortera ="datumtid DESC";
                      $sokvag = "";
                      $sokord = null;
                      $offset = 0;
                      $prev = $offset - $antalpersida;
                      $next = $offset + $antalpersida;
                      if($typ)
                        {
                        $sokvag = $typ;
                        $sokord = $sokord . " AND typ = '".$typ."'";
                        }
                      else
                        {
                        $sokvag = $typover;
                        }
                      if($kategori)
                        {
                        $sokvag = $sokvag." : ".$kategori;
                        $sokord = $sokord." AND kategori = '".$kategori."'";
                        }
                      else
                        {
                        $sokvag = $sokvag." : ".$kategoriover;
                        }
                      if($ord)
                        {
                    //----- Nu söker vi i både rubrik och text [OR text sist]--//
                        $sokord = $sokord." AND (rubrik like '%".$ord."%' OR info like '%".$ord."%')";
                        $sokvag = $sokvag." : ".$ord;
                        }
                      if($lan)
                        {
                        $sokvag = $sokvag." : ".$lan;
                        $sokord = $sokord." AND lan = '".$lan."'";
                        }
                      else
                        {
                        $sokvag = $sokvag." : ".$lanover;
                        }
                      if($pris)
                        {
                        $sokvag = $sokvag." : 0-".$pris."kr";
                        $sokord = $sokord." AND pris BETWEEN 0 AND ".$pris;
                        }
                      else
                        {
                        $sokvag = $sokvag." : ".$prisover;
                        }
                      $sokord = $sokord." ORDER BY ".$sortera;
                      }
                    //----- Om next / prev blivigt intryckt sätt rätt värden --//
                    elseif($nextprev)
                      {
                      $offset += 0;
                      $prev = $offset-$antalpersida;
                      $next = $offset+$antalpersida;
                      }
                    //----- Om Om någon har tryckt på kat. på startsidan ------//
                    elseif($visatyper)
                      {
                      $sortera ="datumtid DESC";
                      $sokvag = "";
                      $sokord = " AND typ = '".$visatyper."'";
                      $sokord = $sokord." ORDER BY ".$sortera;
                      $offset = 0;
                      $prev = $offset - $antalpersida;
                      $next = $offset + $antalpersida;
                      }
                    //----- Tar bort dom satans bakslasarna ------------------ //
                    $sokord = stripslashes($sokord);
                    
                    
                    echo "<table width=\"680\" height=\"800\" class=\"tabellram\" bgcolor=\"".$bgtabell."\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">\n";
                        echo "\t\t<form method=post action=".$PHP_SELF.">\n";
                      echo "\t<tr>\n";
                      echo "\t<td width=\"680\" height=\"15\" colspan=\"4\">\n";
                      echo "\t</td></tr>\n";
                    //-- listar upp sökformuläret ------------------------------//
                      echo "\t<tr>\n";
                      echo "\t<td width=\"10\" height=\"20\">\n";
                      echo "\t</td>\n";
                    //-- listar alla typer -------------------------------------//
                      echo "\t<td width=\"190\" height=\"20\">\n";
                        echo "\t\t<select name=\"typ\" size=\"1\">\n";
                        echo "\t\t<option value=\"\">".$typover."</option>\n";
                        echo "\t\t<option value=\"\">".$typstreck."</option>\n";
                        foreach($cmbtyp as $namn)
                          {
                          echo "\t\t<option value=\"".$namn."\"";
                          if (isset($typ) and $typ == $namn)
                            {
                            echo " selected=\"true\"";
                            }
                          echo ">".$namn."</option>\n";
                          }
                        echo "\t\t</select>\n";
                      echo "\t</td>\n";
                    //-- listar köp sälj eller bytes ---------------------------//
                      echo "\t<td width=\"190\" height=\"20\">\n";
                        echo "\t\t<select name=\"kategori\" size=\"1\">\n";
                    
                        echo "\t\t<option value=\"\">".$kategoriover."</option>\n";
                        echo "\t\t<option value=\"\">".$kategoristreck."</option>\n";
                    
                        foreach($cmbkategori as $namn)
                          {
                          echo "\t\t<option value=\"".$namn."\"";
                          if (isset($kategori) and $kategori == $namn)
                            {
                            echo " selected=\"true\"";
                            }
                          echo ">".$namn."</option>\n";
                          }
                        echo "\t\t</select>\n";
                      echo "\t</td>\n";
                    //-- textbox att skriva in sökord i ------------------------//
                      echo "\t<td width=\"190\" height=\"31\">\n";
                        echo "\t\t<input type=\"text\" size=\"20\" name=\"ord\" maxlength=\"30\" value=\"";
                        if(isset($ord))
                          {
                          echo $ord;
                          }
                        echo "\">\n";
                      echo "\t</td></tr>\n";
                    //-- tom cell ----------------------------------------------//
                      echo "\t<tr>\n";
                      echo "\t<td width=\"10\" height=\"20\">\n";
                      echo "\t</td>\n";
                    //-- listar alla län ---------------------------------------//
                      echo "\t<td width=\"190\" height=\"20\">\n";
                        echo "\t\t<select name=\"lan\" size=\"1\">\n";
                        echo "\t\t<option value=\"\">".$lanover."</option>\n";
                        echo "\t\t<option value=\"\">".$lanstreck."</option>\n";
                        foreach($cmblan as $namn)
                          {
                          echo "\t\t<option value=\"".$namn."\"";
                          if (isset($lan) and $lan == $namn)
                            {
                            echo " selected=\"true\"";
                            }
                          echo ">".$namn."</option>\n";
                          }
                        echo "\t\t</select>\n";
                      echo "\t</td>\n";
                    //-- listar alla prisklasser -------------------------------//
                      echo "\t<td width=\"190\" height=\"20\">\n";
                        echo "\t\t<select name=\"pris\" size=\"1\">\n";
                        echo "\t\t<option value=\"\">".$prisover."</option>\n";
                        echo "\t\t<option value=\"\">".$prisstreck."</option>\n";
                        foreach($cmbpris as $namn)
                          {
                          echo "\t\t<option value=\"".$namn."\"";
                          if (isset($pris) and $pris == $namn)
                            {
                            echo " selected=\"true\"";
                            }
                          echo ">Max ".$namn." kr</option>\n";
                          }
                        echo "\t\t</select>\n";
                      echo "\t</td>\n";
                    //-- sök knapp ---------------------------------------------//
                      echo "\t<td width=\"190\" height=\"20\">\n";
                      echo "\t\t<input type=\"submit\" name=\"sok\" class=\"knapp\" value=\" Sök annons  \">\n";
                      echo "\t<tr>\n";
                      echo "\t</td></tr>\n";
                        echo "\t\t</form>\n";
                    	
                    	/*
                    	?>
                       
                         <td colspan="4" align="right"<script type="text/javascript"> var uri = 'http://impse.tradedoubler.com/imp?type(js)pool(384489)a(1793211)' + new String (Math.random()).substring (2, 11);
                    document.write('<sc'+'ript type="text/javascript" src="'+uri+'" charset="ISO-8859-1"></sc'+'ript>');</script></tr></td>
                    <?
                    */
                    //-- Slut på sökformulär -----------------------------------//
                      //echo "\t<tr>\n";
                      echo "\t<td width=\"680\" height=\"10\" colspan=\"4\">\n";
                      echo "\t</td></tr>\n";
                    
                    if(!($sok or $nextprev or $visatyper))
                      {
                    
                    ?>
                      <tr>
                      <td width="680" colspan="4"><table width="650" height="12" border="0" cellspacing="0" cellpadding="0" align="center">
                        <tr align="top">
                          <td class="grabold12" align="left" width="400"><strong>Välkommen till Fyndklippet.se!</strong><br />
                              <span class="graboldsmall">Här annonserar privatpersoner <br />
                                och företag helt GRATIS!<br />
                                Mycket enklare kan det inte bli!<br />
                                 </td>
                          <td><script type="text/javascript"> var uri = 'http://impse.tradedoubler.com/imp?type(js)pool(384489)a(1793211)' + new String (Math.random()).substring (2, 11);
                    document.write('<sc'+'ript type="text/javascript" src="'+uri+'" charset="ISO-8859-1"></sc'+'ript>');</script></td>
                        </tr>
                      </table>
                        <?
                      echo "\t</td></tr>\n";
                      }
                      echo "\t<tr>\n";
                      echo "\t<td width=\"651\" colspan=\"10\" valign=\"top\">\n";
                    
                    if($sok or $nextprev or $visatyper)
                      {
                    //----- Checkar hur många poster det finns --------------- //
                      $total = mysql_num_rows(mysql_query("SELECT * FROM annonser WHERE kontrollerad='ja' $sokord"));
                    echo "<table width=\"680\" class=\"grabold\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" align=\"center\">\n";
                      echo "\t<tr>\n";
                      echo "\t<td width=\"600\" height=\"25\" class=\"litenrubrik\" colspan=\"6\" background=\"".$bgrubrikbild."\" bgcolor=\"".$bgrubrik."\" align=\"center\">\n";
                        if($total > 0)
                          {
                          echo "\t\tVisar ";
                          echo $offset+1;
                          echo " till ";
                          if(($offset+$antalpersida) < $total)
                            {
                            echo $offset+$antalpersida;
                            }
                          else
                            {
                            echo $total;
                            }
                          echo " av ";
                          echo $total;
                          echo " träffar.\n";
                          }
                        else
                          {
                          echo "\t\tTyvärr fick du ".$total." träffar, försök med att göra en ny sökning.\n";
                          }
                        echo "\t</td></tr>\n";
                        
                    	
                     //---------------Här---------------------------------//             
                                    
                    //$antal_bilder = ANTAL_SENAST_INLAGGDA_ANNONSER;
                    
                                  $sql = "
                    
                                    SELECT
                    
                                      a.annonsid,
                    
                                      a.datum,
                    
                                      a.datumtid,
                    
                                      a.lan,
                    
                                      a.typ,
                    
                                      a.rubrik,
                    
                                      a.stad,
                    
                                      a.pris,
                    
                                      a.marke,
                    
                                      a.kategori,
                    				  b.id,
                    				  b.bildnamn,
                    
                                      b.bildpath
                    
                                    FROM
                    
                                      annonser AS a
                    
                                    LEFT JOIN
                    
                                      annonser_bilder AS b
                    
                                    ON
                    
                                      a.annonsid=b.annonsid
                    
                                    WHERE
                    					
                                      a.kontrollerad = 'ja' 
                    				   $sokord
                    				   
                    				LIMIT
                    				$offset, $antal_bilder
                    				 
                                    ";
                    $rs = mysql_query($sql);
                    
                                    while ($visa = mysql_fetch_array($rs))
                    
                                   
                    				{
                                    
                    //$result = mysql_query("SELECT bildpath FROM annonser_bilder LIMIT 0");
                    //if (!$result) {
                        //echo 'Could not run query: ' . mysql_error();
                        //exit;
                    //}
                    //$row = mysql_fetch_row($result);
                    
                    //$path = $row[0]; // 42
                    //echo $row[1]; // the email value
                    				
                    	
                    //-------------------Slut gamla frågan----------------------------------------------------//  
                          echo "\t<tr onmouseover=\"javascript:style.background='".$varannan."'\" onmouseout=\"javascript:style.background=''\">\n";
                    	  
                    //--------------------Nya visa---------------------------------------------------------//
                                     echo "</td>";
                                     echo "<td width=\"60\" height=\"30\">";
                                     echo "<a href=\"?annonsID=".$visa[annonsid]."\">";
                                     echo "<span class=\"small\">";
                                     echo "$visa[datum]";
                                     echo "</td></span>";
                    				  echo '</a>';
                    		
                    		//var_dump($visa['bildpath'],$sokord);			
                    				 //test=$visa[bildpath];
                    				 
                    
                    //echo $test;
                    
                    
                                   if($visa[bildpath])
                                     {
                                   echo "</td>";
                                   echo "<td width=\"60\" height=\"30\">";
                                   echo "<a href=\"?annonsID=".$visa[annonsid]."\">";
                    			   $size = getimagesize($visa[bildpath]);
                           $height = $size[1];
                           $width = $size[0];
                         if ($height > 199)
                              {
                                   $height = 60;
                                   $percent = ($size[1] / $height);
                                   $width = ($size[0] / $percent);
                              }
                         else if ($width > 199)
                              {
                                   $width = 60;
                                   $percent = ($size[0] / $width);
                                   $height = ($size[1] / $percent);
                              }
                                   //echo "<img src=\"thumbnails.php?src=$row1[bildpath]\" style=\"border: 0;\" />";
                    			   echo "\t\t<img src=\"{$visa[bildpath]}\" width=\"$width\" height=\"$height\" border=\"1\"><br>";
                                   echo '</a>';
                                   echo "</td>";                 
                                     }
                                   else
                                    {
                                    echo "</td>";
                                    echo "<td width=\"30\" height=\"30\">";
                                    echo "<a href=\"?annonsID=".$visa[annonsid]."\">";
                                    //echo "<img src=\"grafik/ingenkamera.gif\" border=\"0\" width=\"50\" height=\"40\">";
                                    echo '</a>';
                                   echo "</td>";                 
                                     }
                                      
                                       
                                /*
                    
                                      echo "</td>";
                                      echo "<td width=\"90\" height=\"30\">";
                                      echo "<a href=\"?annonsID=".$visa[annonsid]."\">";
                                      echo "$visa[marke]";
                                      echo '</a>';
                                      echo "</td>";
                    */
                                      echo "</td>";
                                      echo "<td width=\"250\" height=\"50\">";
                                      echo "<a href=\"?annonsID=".$visa[annonsid]."\">";
                                      echo "$visa[rubrik]";
                    				  //echo "<a href=\"?annonsID=".$row1[annonsid]."\">";
                    				  echo "<span class=\"small\">";
                    				  echo "<br>";
                                      echo "$visa[pris]".":-";   
                                      echo '</a>';
                                      echo "</td></span>";
                                       
                    
                                      echo "</td>";
                                      echo "<td width=\"71\" height=\"30\">";
                                      echo "<a href=\"?annonsID=".$visa[annonsid]."\">";
                                      echo "$visa[typ]";
                    				  echo "<span class=\"small\">";
                    				  echo "<br>";
                    				  echo "$visa[lan]";
                                      echo '</a>';
                                      echo "</td><span/>";
                    
                    
                    
                                      
                    /*
                                      echo "</td>";
                                      echo "<td width=\"90\" height=\"40\">";
                                      echo "<a href=\"?annonsID=".$visa[annonsid]."\">";
                                      echo "$visa[radio1]";         
                                      echo '</a>';
                                      echo "</td>";
                    */
                    
                     //------------------------Slut på nya visa--------------------------------------//
                          echo "\t<tr>\n";
                          echo "\t<td width=\"400\" height=\"1\" colspan=\"6\" background=\"".$bgstreck570."\" align=\"center\">\n";
                          echo "\t</td></tr>\n";
                          }
                        echo "\t<tr><td width=\"600\" colspan=\"6\" valign=\"top\" align=\"center\">\n";
                        echo "<table width=\"600\" align=\"center\">\n";
                          echo "\t\t<form method=post action=".$PHP_SELF.">\n";
                          echo "\t<tr><td width=\"270\" align=\"left\" valign=\"top\">\n";
                          echo "\t\t<input class=\"knapp\" type=\"submit\" value=\"Ny sökning / Hem\">\n";
                          echo "\t\t</td>\n";
                          echo "\t\t</form>\n";
                    //----- Skapar knappar först bakåtknappen ------------------//
                          if(!($prev < 0))
                            {
                            echo "\t\t<form method=post action=".$PHP_SELF.">\n";
                            echo "\t<td width=\"150\" align=\"center\" valign=\"top\">\n";
                            echo "\t\t<input type=\"submit\" name=\"nextprev\" class=\"knapp\" value=\"<-- Förra ".$antalpersida."\">\n";
                            echo "\t\t<input type=\"hidden\" name=\"offset\" Value=".$prev.">\n";
                            echo "\t\t<input type=\"hidden\" name=\"sokord\" Value=\"".$sokord."\">\n";
                            echo "\t\t<input type=\"hidden\" name=\"sokvag\" Value=\"".$sokvag."\">\n";
                            echo "\t\t<input type=\"hidden\" name=\"typ\" Value=\"".$typ."\">\n";
                            echo "\t\t<input type=\"hidden\" name=\"kategori\" Value=\"".$kategori."\">\n";
                            echo "\t\t<input type=\"hidden\" name=\"ord\" Value=\"".$ord."\">\n";
                            echo "\t\t<input type=\"hidden\" name=\"lan\" Value=\"".$lan."\">\n";
                            echo "\t\t<input type=\"hidden\" name=\"pris\" Value=\"".$pris."\">\n";
                            echo "\t</td>\n";
                            echo "\t\t</form>\n";
                            }
                          else
                            {
                            echo "\t<td width=\"150\" align=\"center\" valign=\"top\">\n";
                            }
                    //----- Sedan framåtknappen --------------------------------//
                          if($total > $next)
                            {
                    //----- Sätter rätt antal på sista annonserna --------------//
                            if(($total - $next) > $antalpersida)
                              {
                              $sista = $antalpersida;
                              }
                            else
                              {
                              $sista = $total - $next;
                              }
                            echo "\t\t<form method=post action=".$PHP_SELF.">\n";
                            echo "\t<td width=\"150\" align=\"right\" valign=\"top\">\n";
                            echo "\t\t<input type=\"submit\" name=\"nextprev\" class=\"knapp\" value=\"Nästa ".$sista." -->\">\n";
                            echo "\t\t<input type=\"hidden\" name=\"offset\" Value=".$next.">\n";
                            echo "\t\t<input type=\"hidden\" name=\"sokord\" Value=\"".$sokord."\">\n";
                            echo "\t\t<input type=\"hidden\" name=\"sokvag\" Value=\"".$sokvag."\">\n";
                            echo "\t\t<input type=\"hidden\" name=\"typ\" Value=\"".$typ."\">\n";
                            echo "\t\t<input type=\"hidden\" name=\"kategori\" Value=\"".$kategori."\">\n";
                            echo "\t\t<input type=\"hidden\" name=\"ord\" Value=\"".$ord."\">\n";
                            echo "\t\t<input type=\"hidden\" name=\"lan\" Value=\"".$lan."\">\n";
                            echo "\t\t<input type=\"hidden\" name=\"pris\" Value=\"".$pris."\">\n";
                            echo "\t</td>\n";
                            echo "\t\t</form>\n";
                            }
                          else
                            {
                            echo "\t<td width=\"150\" align=\"center\" valign=\"top\">\n";
                            echo "\t</td>\n";
                            }
                          echo "\t</tr>\n";
                        echo "</table>\n";
                    
                        echo "\t</td></tr>\n";
                      echo "</table>\n";
                      }
                    else
                      {
                      
                    //-- Tabell med 4 billigaste/8 senaste/antal per kategori --//
                      echo "<table width=\"670\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n";
                      
                        echo "\t<tr valign=\"top\">\n";
                        echo "\t<td width=\"300\">\n";
                    
                    //-- Tabell med 4 billigaste sista månaden/8 senaste -------//
                    /*
                       $fraga = "SELECT annonsid,datum,datumtid,rubrik,pris FROM annonser ORDER BY datumtid DESC LIMIT 0, 13 ";
                       */ 
                       
                       $antal_bilder = ANTAL_SENAST_INLAGGDA_ANNONSER;
                                  $fraga = "
                                    SELECT
                                      a.annonsid,
                                      a.datum,
                                      a.datumtid,
                                      a.lan,
                                      a.radio1,
                                      a.rubrik,
                                      a.stad,
                                      a.pris,
                                      a.typ,
                                      b.bildpath,
                                      b.bildnamn
                                    FROM
                                      annonser AS a
                                    LEFT JOIN
                                      annonser_bilder AS b
                                    ON
                                      a.annonsid=b.annonsid
                                    WHERE
                                      a.kontrollerad = 'ja'  
                                    GROUP BY
                                      a.annonsid
                                    ORDER BY
                                      a.datumtid DESC
                                    LIMIT
                                      0, 15
                                    ";
                                    //$rs = mysql_query($sql);
                      $data = mysql_query($fraga);
                    
                    
                        echo "<table width=\"300\" class=\"tabellram\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" align=\"center\">\n";
                          echo "\t<tr>\n";
                          echo "\t<td width=\"300\" height=\"25\" align=\"center\" class=\"rubrik\" colspan=\"4\" background=\"".$bgrubrikbild."\" bgcolor=\"".$bgrubrik."\">".$rubriker [1]."\n";
                          echo "\t</td></tr>\n";
                          while ($billigaste = mysql_fetch_array($data))
                            {
                    		
                            echo "\t<tr onmouseover=\"javascript:style.background='".$varannan."'\" onmouseout=\"javascript:style.background=''\">\n";
                            echo "\t<td class=\"small\" width=\"70\">\n";
                            echo "\t\t<a href=\"index.php?annonsID=".$billigaste[annonsid]."\">";
                            echo $billigaste[datum];
                            echo "</a>\n";
                            echo "\t</td>\n";
                            echo "\t<td class=\"small\" width=\"130\">\n";
                    //-- Kapar av rubriken i rätt längd och lägger till punkter //
                            echo "\t\t<a href=\"index.php?annonsID=".$billigaste[annonsid]."\">";
                            if(strlen($billigaste[rubrik]) > 30)
                              {
                              echo substr($billigaste[rubrik],0,33)."....";
                              }
                            else
                              {
                              echo $billigaste[rubrik];
                              }
                            echo "</a>\n";
                            echo "\t</td>\n";
                            
                            echo "\t<td class=\"small\" width=\"80\">\n";
                            echo "\t\t<a href=\"index.php?annonsID=".$billigaste[annonsid]."\">";
                            echo $billigaste[pris]." kr";
                            echo "</a>\n";
                            echo "\t</td>\n";
                    
                            echo "\t<td class=\"small\" width=\"20\">\n";
                            echo "\t\t<a href=\"index.php?annonsID=".$billigaste[annonsid]."\">";
                    		
                    //-------------Visa thumbs på framsidan-------------------//
                     
                            if($billigaste[bildnamn])
                    		
                              {
                              echo "<img src=\"$billigaste[bildpath]\" border=\"1\" width=\"18\" height=\"18\">";
                              }
                            else
                              {
                              echo "&nbsp;\n";
                              }
                            echo "</a>\n";
                            echo "\t</td></tr>\n";
                            //echo "\t<tr>\n";
                            echo "\t<td width=\"340\" height=\"1\" colspan=\"4\" background=\"".$bgstreck570."\">\n";
                            echo "\t</td></tr>\n";
                            }
                    
                    
                    //-- Tom cell-----------------------------------------------//
                          echo "\t<tr>\n";
                          echo "\t<td width=\"268\" height=\"40\" colspan=\"3\"\n";
                    
                          echo "\t</td></tr>\n";
                    
                    
                    
                          echo "\t<tr>\n";
                    
                    
                    
                        echo "</table>\n";
                        ?>
                        <?
                        echo "\t</td>";
                        echo "\t<td width=\"370\">\n";
                    	
                    //-- skriver ner antalet annonser --------------------------//
                        echo "<table width=\"360\" class=\"tabellram\" style=\"padding-top:0px\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" align=\"center\">\n";
                          echo "\t<tr>\n";
                          echo "\t<td width=\"360\" height=\"25\" align=\"center\" class=\"rubrik\" colspan=\"4\" background=\"".$bgrubrikbild."\" bgcolor=\"".$bgrubrik."\">".$rubriker [2]."\n";
                          echo "\t</td></tr>\n";
                          echo "\t<tr>\n";
                          echo "\t<td class=\"grabold\" width=\"180\" valign=\"top\">\n";
                          $i = 0;
                          foreach($cmbtyp as $namn)
                            {
                            if($i == 30)
                              {
                              echo "\t</td><td class=\"grabold\" width=\"180\" valign=\"top\">\n";
                              }
                            echo "\t\t<a href=\"index.php?visatyper=".$namn."\">".$namn." (<span class=\"rodbold\">";
                            echo mysql_num_rows(mysql_query("SELECT * FROM annonser WHERE typ = '".$namn."'"));
                            echo "</span>)</a><br>\n";
                            $i++;
                            }
                          echo "\t</td></tr>\n";
                        echo "</table>\n";
                        
                        ?>
                      
                      <tr>
                        <td><!-- Start of StatCounter Code -->
                    
                    <!-- End of StatCounter Code -->
                    
                    
                    </a></td></tr>
                    <?
                        echo "\t</td></tr>\n";
                      echo "</table>\n";
                      }
                      echo "\t</td></tr>\n";
                    
                    echo "</table>\n";
                    
                    ?>

                    Comment

                    • Fynd
                      New Member
                      • Mar 2010
                      • 13

                      #11
                      Atli I have posted a long explanation but I think someone had to review it first, hadn't time to read the note when posting.
                      Hope that works.

                      Best regards,

                      Morgan

                      Comment

                      • Fynd
                        New Member
                        • Mar 2010
                        • 13

                        #12
                        Think my latest post vanished into cyberspace..... .........:-)
                        I tried the loop for used_id above but still the output is as usual from var_dump($visa['bildpath']);

                        bildpath is then string(45) and this string contains 3 items with different paths.
                        string(45) "annonsbild er/201003311008151 62.119.142.29.j pg"
                        string(45) "annonsbild er/201003311008152 62.119.142.29.j pg"
                        string(45) "annonsbild er/201003311008153 62.119.142.29.j pg"
                        So the trap for the id doesn't work as the id contains an image id that is unique in the same main id. If I could strip the string(45) into one? But I can not read only the first item from the string.
                        Thanks for helping out.

                        Best regards,
                        Morgan

                        Comment

                        • Fynd
                          New Member
                          • Mar 2010
                          • 13

                          #13
                          Anyone in for the issue? Or do you require more info?

                          Best regards,
                          Morgan

                          Comment

                          • Markus
                            Recognized Expert Expert
                            • Jun 2007
                            • 6092

                            #14
                            Is $visa['bildpath'] an array?

                            Comment

                            • Fynd
                              New Member
                              • Mar 2010
                              • 13

                              #15
                              Yes bildpath is an array caught from the sql query. If I follow the output from the query, it tells me that there's 3 images with the same id because there are 3 images on that id but I only want to display the first image of that id.
                              String(45) from above will be printed 3 times so the script actually is working as there are 3 writing in the same id. But the BIG question is how in *** do I print the first?

                              Explanation: in the query I connect the id with the db annonser with the id on the db annons_bilder but the images has got different names and path but yet connected to the same id.

                              Best regards,

                              Morgan

                              Comment

                              Working...