7 Replies - 456 Views - Last Post: 17 February 2013 - 03:31 PM

#1 NixNuz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-February 13

Linking of an object inside a table doesn't work

Posted 17 February 2013 - 01:41 PM

Hi there,
I want to link an object from a MySQL-Query inside a php-table but my code doesn't seem to work and I think it is just a problem of punctuation.

When I want to change this:
echo '<img src="'.$row['small'].'" border="0" alt="'.$row['name']." height="150px" width="150px"></img>";
(which is working BTW) to this:
echo  "<a href="content/details.php?kategorie='.$kategorie.'&id='.$zeile['id'].'" target="_blank" onclick="return popup(this.href);"><img src=\"" . $row['small'] . "\" border=0 alt=\"" . $row['name'] . "\" height=150px width=150px></img></a>" ;
everything is vanished suddenly.
My inspiration for the code came from here: http://www.dreaminco...-results-colum/

This is the complete code:

<?php 
            $db_link = mysql_connect ( localhost,  
                                       *censored user*,  
                                       *censored PW* ); 
              
            $db_sel = mysql_select_db( *dbname* ) 
               or die("Auswahl der Datenbank fehlgeschlagen"); 
                
            $kategorie = $_GET['kategorie']; 
              
            $seite = $_GET['seite']; 
            $next_page = $seite + 1; 
            if ( $next_page == 22) 
            { 
              $next_page = 1; 
            } 
            $prev_page = $seite - 1; 
            if ( $prev_page == 0) 
            { 
              $prev_page = 21; 
            } 
             
            $sql = "SELECT id, seite, small, big, beschreibung, preis FROM $kategorie WHERE seite='$seite'"; 
              
            $db_erg = mysql_query( $sql ); 
            if ( ! $db_erg ) 
            { 
              die('Ungültige Abfrage: ' . mysql_error()); 
            } 
              
            ?> 
             
        <div id="gallerie"> 
              
            <?php 
             
            $query = "SELECT * FROM $kategorie WHERE seite = '$seite' ";  
            $result = mysql_query($query) or die(mysql_error());  
                $tableCount = 0; 
                $tableRowOpen = false; 
                while($row = mysql_fetch_assoc($result)) { 
                    if($tableCount == 0){ 
                        echo "<tr>"; 
                        $tableRowOpen = true; 
                    } 
                    echo "<td>"; 
                    echo '<img src="'.$row['small'].'" border="0" alt="'.$row['name']." height="150px" width="150px"></img>";   
                    echo "</td>"; 
                    if($tableCount + 1 == 3){ 
                        $tableCount = 0; 
                        echo "</tr>"; 
                        $tableRowOpen = false; 
                    } 
                    else{ 
                        $tableCount++; 
                    } 
                 
                } 
                if($tableRowOpen){ 
                    echo "</tr>"; 
                } 
                 
            ?>


Thank you so much for helping!

Is This A Good Question/Topic? 0
  • +

Replies To: Linking of an object inside a table doesn't work

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3361
  • View blog
  • Posts: 11,398
  • Joined: 12-December 12

Re: Linking of an object inside a table doesn't work

Posted 17 February 2013 - 02:18 PM

Yes, the expression is malformed. It is easier to stick with apostrophes within double-quotes and embed variables directly in the string, without the need for . $something .. Arrays need to be enclosed in curly brackets, and this is useful for variable as well - to separate them from the content that surrounds them.

Something like:
<?php
echo  "<a href='content/details.php?kategorie={$kategorie}&id={$zeile[id]}' target='_blank' " .
    "onclick='return popup(this.href);'><img src='{$row[small]}' border='0' alt='{$row[name]}' " .
    "height='150px' width='150px'></img></a>";

?>

though I haven't tested this expression.

It is best, also, to enclose all attributes in quotes, particularly when building an expression with PHP.

This post has been edited by andrewsw: 17 February 2013 - 02:20 PM

Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3361
  • View blog
  • Posts: 11,398
  • Joined: 12-December 12

Re: Linking of an object inside a table doesn't work

Posted 17 February 2013 - 02:25 PM

I find it much easier to use HEREDOCs for detailed output:

$output = <<< HEREDOC
<a href='content/details.php?kategorie={$kategorie}&id={$zeile[id]}' target='_blank' 
onclick='return popup(this.href);'>
<img src='{$row[small]}' border='0' alt='{$row[name]}' height='150px' width='150px'></img>
</a>
HEREDOC;

echo $output;

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3361
  • View blog
  • Posts: 11,398
  • Joined: 12-December 12

Re: Linking of an object inside a table doesn't work

Posted 17 February 2013 - 02:31 PM

Sorry, we need apostrophe around the array-elements:

echo  "<a href='content/details.php?kategorie={$kategorie}&id={$zeile['id']}' target='_blank' " .
    "onclick='return popup(this.href);'><img src='{$row['small']}' border='0' alt='{$row['name']}' " .
    "height='150px' width='150px'></img></a>";
echo '<br>';

$output = <<< HEREDOC
<a href='content/details.php?kategorie={$kategorie}&id={$zeile['id']}' target='_blank' 
onclick='return popup(this.href);'>
<img src='{$row['small']}' border='0' alt='{$row['name']}' height='150px' width='150px'></img>
</a>
HEREDOC;

echo $output;

Was This Post Helpful? 0
  • +
  • -

#5 NixNuz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-February 13

Re: Linking of an object inside a table doesn't work

Posted 17 February 2013 - 02:35 PM

Thanks man,
HEREDOCS doesn't really work, but your first solution fixed most of it. Now there is only the following error left:

Notice: Use of undefined constant id - assumed 'id' in /var/www/bxweb260/html/nixnuz.net/herzmann/content/gallerie.php on line 65 Notice: Use of undefined constant small - assumed 'small' in /var/www/bxweb260/html/nixnuz.net/herzmann/content/gallerie.php on line 65 Notice: Use of undefined constant name - assumed 'name' in /var/www/bxweb260/html/nixnuz.net/herzmann/content/gallerie.php on line 65


Although the links work and a window pops up when you click them, this huge error messes up all the formatting.

Oh, nevermind I just had to put quotation marks inside the ["boxes"].

Thank you very much :)
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3361
  • View blog
  • Posts: 11,398
  • Joined: 12-December 12

Re: Linking of an object inside a table doesn't work

Posted 17 February 2013 - 02:49 PM

Yes, I noticed and corrected this in my recent post (I hadn't had a chance to test it). I'm surprised that the HEREDOC didn't work but it requires the same apostrophes to be inserted - again, this is in my recent post.

I would encourage you to look into the HEREDOC notation. You can use tabs within them, and newlines, to make them easier to read.

BTW There is no closing IMG tag (</img>).
Was This Post Helpful? 0
  • +
  • -

#7 NixNuz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-February 13

Re: Linking of an object inside a table doesn't work

Posted 17 February 2013 - 03:01 PM

Yeah I also noticed the missing <img>-tag and already corrected it. I just didn't see all your posts at the right time so I guess there was only some confusion ^^ Anyways, thank you very much for help :) You really helped me out :D
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3361
  • View blog
  • Posts: 11,398
  • Joined: 12-December 12

Re: Linking of an object inside a table doesn't work

Posted 17 February 2013 - 03:31 PM

View PostNixNuz, on 17 February 2013 - 03:01 PM, said:

Yeah I also noticed the missing <img>-tag and already corrected it. I just didn't see all your posts at the right time so I guess there was only some confusion ^^/> Anyways, thank you very much for help :)/> You really helped me out :D

You don't have a missing img tag, you have more than you need(?). Anyway, glad I could help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1