Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Jan 2010
    Location
    Grästorp Sweden
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Applying hyperlinks to a mysql query result, help needed

    Hi, this i my first time asking anything on the Internet.
    I'm creating a website that's semi dynamic. The site have a form to post a "sort of" blog. The post's inserts in three tables in a mysql db. I then retrieve the post's and show them on a page, nyheter.php. So far no problems. I also show them on a sidebar, with the diffrence of only showing the first 20 words from the post_content row. This also works as a charm. Now to the problem. I need to apply a hyperlink on the Title and Content in the sidebar and point them to the equal post in the nyheter.php.

    On the sidebar page the code looks like this
    Code:
    <?php
    	@mysql_select_db("iw_test") or die( "Unable to select database");
    	$query="SELECT post_title, SUBSTRING_INDEX(post_content,' ',20) AS post_content, post_date FROM iw_posts ORDER BY post_date DESC LIMIT 5";
    	$result = mysql_query($query);
    	$num = mysql_numrows($result);
    mysql_close();
    ?>
    
    <?php
    
    
    $i=0;
    while ($i < $num) {
    
    $post_title = mysql_result($result,$i,"post_title");
    $post_content = mysql_result($result,$i,"post_content");
    $post_date = mysql_result($result,$i,"post_date");
    
    echo "<h3>$post_title</h3>";
    echo "<p>$post_content</p>";
    echo "<p>$post_date</p>";
    
    $i++;
    }
    ?>
    The code for nyheter.php is the same except i did a * FROM insted of seperating the query as seen in the code above. My goal is as follow, I need the sidebar teesers to be clickable to their twins on the nyheter.php page.
    I've tried to apply hyperlink to the echos above, with the result that the entire side goes blank except the header.

    P.s I,m sort of a newbee to both PHP and Mysql. D.s
    Regards Stefan
    Last edited by Stebbe; 01-07-2010 at 06:45 PM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Can we have a link to your page? Or please post your current html taken from your browser's view source option.

    PS: Use [CODE][/CODE] tags to wrap your codes while posting here.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Jan 2010
    Location
    Grästorp Sweden
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Hi abduraooft, Thanks for fast reply...

    Missed the / in the closing [CODE] sorry
    Sorry for a not so fast answer back, I've been having bit of a struggle with my server, on the dev machine things look good, Win7, iis, php and mysql ran out of the box. The php.ini on the server was a bit messed up, now solved...

    The url for the site is http://www.infinitumwellness.se

    and the source code for the page nyheter.php
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/master.dwt.php" codeOutsideHTMLIsLocked="false" --> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
    <meta name="google-site-verification" content="zNCGZwRB4J_fiPgTrUmF_pIgSEbpZcnzNQyYXUNAWrc" /> 
    <meta name="google-site-verification" content="zNCGZwRB4J_fiPgTrUmF_pIgSEbpZcnzNQyYXUNAWrc" /> 
    <meta name="robots" content="noarchive"> 
    <meta name="robots" content="all"> 
    <meta name="distribution" content="global"> 
    <meta http-equiv="content-language" content="sv"> 
    <meta name="keywords" content="livsstilscoaching,funktionell träning,mindfulness,mindfulness,infinitum wellness,infinitumwellness, LCHF, träning, hälsa, hälsoprofil, kroppsanalys, konditionstest,hälsocoach, hälsocoach på distans, Grästorp, Essunga, Nossebro, Vara"> 
    <meta name="description" content="Funktionell träning, Mindfulness. Friskvård, Stresshantering, LCHF, Kostrådgivning"> 
     
    <!-- InstanceBeginEditable name="doctitle" --> 
    <title>Nyheter</title> 
    <!-- InstanceEndEditable --> 
     
    <!--[if lte IE 6]>
    <script type="text/javascript">
    // apply min-width to the wrapper and footer elements for ie6 - set your ids here
    function setMinWidth() {
        var aElement1 = document.getElementById("wrapper");
        var aElement2 = document.getElementById("footer");
     
    	aElement1.runtimeStyle.width = ((d = document.compatMode == "CSS1Compat" ? document.documentElement : document.body) && (d.clientWidth > 1200 ? "1200px" : d.clientWidth < 700 ? "700px" : "auto") );
    	aElement2.runtimeStyle.width = ((d = document.compatMode == "CSS1Compat" ? document.documentElement : document.body) && (d.clientWidth > 1200 ? "1200px" : d.clientWidth < 700 ? "700px" : "auto") );
     
    }
    // Set the width of an element
    function setElemWidth(elem) {
     // Replace the CSS expression with a static value.
        elem.runtimeStyle.width = ((d = document.compatMode == "CSS1Compat" ? document.documentElement : document.body) &&
    (d.clientWidth > 1200 ? "1200px" : d.clientWidth < 700 ? "700px" : "auto"));
    }
     
    // This only sets the size AFTER a resize event.
    if ( -1 != navigator.userAgent.indexOf("MSIE") ) {
        window.onresize = setMinWidth;
    }
     
    </script>
    <![endif]--> 
    <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable --> 
    <link href="master.css" rel="stylesheet" type="text/css" /> 
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/> 
    </head> 
     
    <body id="nyheter"> 
    <div id="wrapper" class="clearfix" > 
    	<div id="inner"> 
    		<div id="header"> 
    		</div> 
    		<div id="topnav"> 
    	<ul id="mainnav"> 
        <li><a href="../index.php" title="Start">Start</a></li> 
        <li><a href="../nyheter.php" title="Om Mig"class="active">Nyheter</a></li> 
        <li><a href="../om_mig.php" title="Om Mig" >Om mig</a></li> 
        <li><a href="../tjanster.php" title="Om Mig">Tjänster</a></li> 
        <li><a href="../halsa.php" title="Om Mig">Hälsa</a></li> 
        <li><a href="../traning.php" title="Om Mig">Träning</a></li> 
        <li><a href="../mat.php" title="Om Mig">Mat</a></li> 
        <li><a href="../stress.php" title="Om Mig">Stress</a></li> 
        <li><a href="../foretag.php" title="Om Mig">Företag</a></li> 
        <li><a href="../kontakt.php" title="Om Mig">Kontakt</a></li> 
      </ul> 
      <!-- end #topnav --></div> 
    		
    <div id="left"> 
    <h1>Nyheter</h1> //This is edited after copy from source code, content from here on down to the <hr color="#6699FF" />  I'd like to have hyperlinked to the "not trimed" text in nyheter.php// 
    <h3>Same as above or below or what ever...</h3><p>This layout uses three floats for the columns even though the middle column is a fluid width we can achieve</p><p>2010-01-07 12:40:00</p><h3>The content in the left sidbar...</h3><p>Should be hyperlinked to the same article in the page Nyheter.php. In the left sidebar a SELECT FROM LEFT("d_b",20)AS d_b</p><p>2010-01-07 11:08:00</p> 
        <hr color="#6699FF" /> 
        <h2 align="center">Du är besökare<br />nr:  
          
            <script type="text/javascript" language="javascript" src="../iwraknare.php?page=index"></script> 
          </h2> 
        
    <!-- end #left --></div> 
    		<div id="middle"> 
    			<div id="content"><!-- InstanceBeginEditable name="content" --> 
    <h1>Nyheter</h1><h3>Same as above or below or what ever...</h3><p>This layout uses three floats for the columns even though the middle column is a fluid width we can achieve this by using a 100% width float for the middle column and then applying a right negative margin equal to the widths of the left and right columns.
     
    A negative margin on the opposite side of a float (opposite to the direction it is floated) doesn't change the width of a float but instead allows other content to approach from that side by the amount of the negative margin.
     
    This would result in overlap of course so we need one extra html element to nest inside the middle floated column that has a margin-right equal to the combined width of the left and right floats and this then keeps the content clear of the side floats.
     
    The benefit of floating all three columns is that we avoid the 3 pixel jog in IE6 and it also allows the html to remain in sensible source order in that left, middle and right columns follow each other logically in the html.
     
    The drawback of this technique is that you must control the minimum width of the center column before the ocntent overflows or the columns will drop in IE6.
     
    The min max routine for IE6 (as ie6 doesn't understand min/max width) is provided by javascript and a once only expression which avoids the speed issues with using expressions. (See Steve Souders for more information on this.)
     
    The sticky footer is a combination of my old techniques and the results of a brain storming session on Sitepoint where a quiz I set refined the details into an all purpose sticky footer. You can see the quiz and read how it all evolves here. A stripped down version of the footer technique is shown here in all it's glory.
     
    Lastly the full column colours are achieved with my absolute column overlay technique that I invented some years ago and uses two extra divs to supply just column colours. The full details are shown in my orignal article and as shown in this demo.</p><p>2010-01-07 12:40:00</p><h3>The content in the left sidbar...</h3><p>Should be hyperlinked to the same article in the page Nyheter.php. In the left sidebar a SELECT FROM LEFT("d_b",20)AS d_b is applied to ceep the content lenght down to be more of a teeser.</p><p>2010-01-07 11:08:00</p>			 <!-- InstanceEndEditable --></div> 
    		</div> 
    		<div id="right"> 
      <h3>Partners</h3> 
       <div align="center"><a href="http://www.halsoborgen.com/grastorp/" target="_blank"><img src="../siteimages/halsoborgen.png" alt="H&auml;lsoborgen" width="130" height="76" border="0" /></a>    </div> 
       <h3>Länkar</h3> 
       <div align="center"><a href="http://www.lchf.se" target="_blank"><img src="../siteimages/lchf.se.png" alt="LCHF.se" width="130" border="0" /></a></div> 
      <!-- end #sidebar2 --></div>	</div> 
    	<div id="l"></div> 
    	<div id="r"></div> 
    	<!-- l & r are the left and right column colours only - they hold no content --> 
    </div> 
    <div id="footer"> 
        
       <p><ul><li><strong>Kontakt:</strong>&nbsp;  Maria Baatz</li> 
       <li><strong>E-post:</strong>&nbsp;<a href="mailto:maria@infnitumwellness.se">maria@infnitumwellness.se</a></li> 
       <li><strong>Tel:</strong>&nbsp;  0702-688452</li></ul> 
       </p> 
      <!-- end #footer --></div> 
     
    </body> 
    <!-- InstanceEnd --></html>
    Last edited by Stebbe; 01-07-2010 at 01:16 PM.

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    It should be pretty simple to get right. Change this line on both codes
    PHP Code:
    echo "<h3>$post_title</h3>"
    for the sidebar, change it to
    PHP Code:
    echo '<h3><a href="#post-'.$i.'">$post_title</a></h3>'
    for the nyheter.php change it to
    PHP Code:
    echo '<h3 id="post-'.$i.'">$post_title</h3>'

  • #5
    New Coder
    Join Date
    Jan 2010
    Location
    Grästorp Sweden
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Did not work...

    Hi JAY6390, Thanks for your help, but it did not work.
    If i copy/paste the lines and insert them in my code, this is the result. http://www.infinitumwellness.se/nyheter.php I have tried with both the " ' " and " " " around the code to no good.
    Code:
    <div id="wrapper" class="clearfix" >
    	<div id="inner">
    		<div id="header">
    		</div>
    		<div id="topnav">
    	<ul id="mainnav">
        <li><a href="../index.php" title="Start">Start</a></li>
        <li><a href="../nyheter.php" title="Om Mig"class="active">Nyheter</a></li>
        <li><a href="../om_mig.php" title="Om Mig" >Om mig</a></li>
        <li><a href="../tjanster.php" title="Om Mig">Tjänster</a></li>
        <li><a href="../halsa.php" title="Om Mig">Hälsa</a></li>
        <li><a href="../traning.php" title="Om Mig">Träning</a></li>
        <li><a href="../mat.php" title="Om Mig">Mat</a></li>
        <li><a href="../stress.php" title="Om Mig">Stress</a></li>
        <li><a href="../foretag.php" title="Om Mig">Företag</a></li>
        <li><a href="../kontakt.php" title="Om Mig">Kontakt</a></li>
      </ul>
      <!-- end #topnav --></div>
    		
    <div id="left">
    <h1>Nyheter</h1>
     
    <h3><a href="#post-0">$post_title</a></h3><p>$post_content</p><p>$post_date</p><h3><a href="#post-1">$post_title</a></h3><p>$post_content</p><p>$post_date</p>
        <hr color="#6699FF" />
        <h2 align="center">Du är besökare<br />nr:  
          
            <script type="text/javascript" language="javascript" src="../iwraknare.php?page=index"></script>
          </h2>
        
    <!-- end #left --></div>
    		<div id="middle">
    			<div id="content"><!-- InstanceBeginEditable name="content" -->
    <h1>Nyheter</h1><h3 id="post-0">$post_title</h3><p>$post_content</p><p>$post_date</p><h3 id="post-1">$post_title</h3><p>$post_content</p><p>$post_date</p>			 <!-- InstanceEndEditable --></div>
    		</div>
    		<div id="right">
      <h3>Partners</h3>
       <div align="center"><a href="http://www.halsoborgen.com/grastorp/" target="_blank"><img src="../siteimages/halsoborgen.png" alt="H&auml;lsoborgen" width="130" height="76" border="0" /></a>    </div>
       <h3>Länkar</h3>
       <div align="center"><a href="http://www.lchf.se" target="_blank"><img src="../siteimages/lchf.se.png" alt="LCHF.se" width="130" border="0" /></a></div>
      <!-- end #sidebar2 --></div>	</div>
    	<div id="l"></div>
    	<div id="r"></div>
    	<!-- l & r are the left and right column colours only - they hold no content -->
    </div>
    <div id="footer">
        
       <p><ul><li><strong>Kontakt:</strong>&nbsp;  Maria Baatz</li>
       <li><strong>E-post:</strong>&nbsp;<a href="mailto:maria@infnitumwellness.se">maria@infnitumwellness.se</a></li>
       <li><strong>Tel:</strong>&nbsp;  0702-688452</li></ul>
       </p>
      <!-- end #footer --></div>
     
    </body>
    <!-- InstanceEnd --></html>
    I'm thankful for any help I can get, this is sort of the final thing before launch...

  • #6
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    When you say you want it to link to the post, do you mean that there is another page that displays the single post, or do you mean you want the page to jump to that part of the page with that post, because the code I provided works (even on your current page) you just need to add more postings

  • Users who have thanked JAY6390 for this post:

    Stebbe (01-07-2010)

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    PHP Code:
    echo "<h3><a href=\"whatever.php?".$i."\">".$post_title."</a></h3>"

  • Users who have thanked sir pannels for this post:

    Stebbe (01-07-2010)

  • #8
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    That will output the same as mine did sir_panels, the only difference being that you've used double quotes and escaped them in the string

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    Hi Jay,

    On the link he posted (http://www.infinitumwellness.se/nyheter.php) the title is not showing, it justs shows the var name... So I thought I would play around with escaping for him ..

    Cheers,
    P

  • #10
    New Coder
    Join Date
    Jan 2010
    Location
    Grästorp Sweden
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I've added some more posts, and the result I'm after, is like on WordPress, you get just a little bit of the blog and klick it in the leftsidebar to go to the actual post.
    At the moment the only thing displayed are the names of the database row names, and on the left sidebar the tiltles are hyperlinks but the don't go any where...
    I'm sure I'm missing something very simple here so bare with me please

    I will try sir pannels escaping dubble " on the dev machine and see what it gives me...

    I appriciate your efforts...
    BTW sorry if my english is not all the way correct I'm from Sweden...

  • #11
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Ah oops, so it does my apologies . The sidebar should be
    PHP Code:
    echo '<h3><a href="#post-'.$i.'">'.$post_title.'</a></h3>'
    and nyheter should be
    PHP Code:
    echo '<h3 id="post-'.$i.'">'.$post_title.'</h3>'

  • #12
    New Coder
    Join Date
    Jan 2010
    Location
    Grästorp Sweden
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts
    This might seem like a dumb question, but is there something I need to change in the code for nyheter.php? I changed in the code for sidebar and that now takes me to nyheter.php, but not the proper article.
    //Stefan

  • #13
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Do you have a page that displays the single post created yet? I thought you wanted to link the sidebar to the location on the page where that particular post is being shown just on nyheter

  • #14
    New Coder
    Join Date
    Jan 2010
    Location
    Grästorp Sweden
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts
    The second part of your question is correct. Or from the top, user post in to the db, the fields are Title and Content. I add time/date from a hidden field. Retrive the data from db at the same time but from two diffrent scripts, on nyheter.php I pick everything, on the sidebar I've shorten the array to only display the 20 first words in the Content. When live, the articles on nyheter.php would contain much more info than just a few words. So thats why I need the links on the sidebar to point to the specific artilce in nyheter.php. I hope this shows what I need get help with... In my dev env I get the links to point to the page nyheter.php but not to the specific article, just to the top of the page...

    //Stefan

  • #15
    New Coder
    Join Date
    Jan 2010
    Location
    Grästorp Sweden
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts
    The scripts you provided sits on my live env... Just copy/paste a lot of txt into the db, now you can see what i'm after. The links in sidebar takes me to top of nyheter.php and not the article clicked...
    The script provided for nyheter.php is untuched, is that right?
    //Stefan


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •